@shware/http 2.10.1 → 2.10.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.
@@ -26,7 +26,6 @@ __export(geolocation_exports, {
26
26
  getGeolocationFromVercel: () => getGeolocationFromVercel
27
27
  });
28
28
  module.exports = __toCommonJS(geolocation_exports);
29
- var import_ip = require("./ip.cjs");
30
29
  function toNumber(value) {
31
30
  return value ? Number(value) : void 0;
32
31
  }
@@ -56,9 +55,14 @@ function getGeolocationFromVercel(r) {
56
55
  postal_code: r.headers.get("x-vercel-ip-postal-code") ?? void 0
57
56
  };
58
57
  }
58
+ function stripPort(value) {
59
+ if (!value) return null;
60
+ const i = value.lastIndexOf(":");
61
+ return i !== -1 && /^\d+$/.test(value.slice(i + 1)) ? value.slice(0, i) : value;
62
+ }
59
63
  function getGeolocationFromCloudfront(r) {
60
64
  return {
61
- ip_address: (0, import_ip.extractIpAddress)(r.headers.get("CloudFront-Viewer-Address")) ?? void 0,
65
+ ip_address: stripPort(r.headers.get("CloudFront-Viewer-Address")) ?? void 0,
62
66
  city: r.headers.get("CloudFront-Viewer-City") ?? void 0,
63
67
  country: r.headers.get("CloudFront-Viewer-Country") ?? void 0,
64
68
  longitude: toNumber(r.headers.get("CloudFront-Viewer-Longitude")),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/geolocation.ts"],"sourcesContent":["import { extractIpAddress } from './ip';\n\nexport type Geolocation = {\n ip_address?: string;\n city?: string;\n country?: string; // ISO 3166-1 alpha-2\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string; // ISO 3166-2\n metro_code?: string;\n postal_code?: string;\n time_zone?: string;\n};\n\nfunction toNumber(value: string | null): number | undefined {\n return value ? Number(value) : undefined;\n}\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nexport function getGeolocationFromCloudflare(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('true-client-ip') ?? r.headers.get('cf-connecting-ip') ?? undefined,\n city: r.headers.get('cf-ipcity') ?? undefined,\n country: r.headers.get('cf-ipcountry') ?? undefined,\n continent: r.headers.get('cf-ipcontinent') ?? undefined,\n longitude: toNumber(r.headers.get('cf-iplongitude')),\n latitude: toNumber(r.headers.get('cf-iplatitude')),\n region: r.headers.get('cf-region-code') ?? undefined,\n metro_code: r.headers.get('cf-metro-code') ?? undefined,\n postal_code: r.headers.get('cf-postal-code') ?? undefined,\n time_zone: r.headers.get('cf-timezone') ?? undefined,\n };\n}\n\n/** reference: https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nexport function getGeolocationFromVercel(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('x-real-ip') ?? undefined,\n city: r.headers.get('x-vercel-ip-city') ?? undefined,\n country: r.headers.get('x-vercel-ip-country') ?? undefined,\n continent: r.headers.get('x-vercel-ip-continent') ?? undefined,\n longitude: toNumber(r.headers.get('x-vercel-ip-longitude')),\n latitude: toNumber(r.headers.get('x-vercel-ip-latitude')),\n region: r.headers.get('x-vercel-ip-country-region') ?? undefined,\n postal_code: r.headers.get('x-vercel-ip-postal-code') ?? undefined,\n };\n}\n\n/** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nexport function getGeolocationFromCloudfront(r: Request): Geolocation {\n return {\n ip_address: extractIpAddress(r.headers.get('CloudFront-Viewer-Address')) ?? undefined,\n city: r.headers.get('CloudFront-Viewer-City') ?? undefined,\n country: r.headers.get('CloudFront-Viewer-Country') ?? undefined,\n longitude: toNumber(r.headers.get('CloudFront-Viewer-Longitude')),\n latitude: toNumber(r.headers.get('CloudFront-Viewer-Latitude')),\n region: r.headers.get('CloudFront-Viewer-Country-Region') ?? undefined,\n metro_code: r.headers.get('CloudFront-Viewer-Metro-Code') ?? undefined,\n postal_code: r.headers.get('CloudFront-Viewer-Postal-Code') ?? undefined,\n time_zone: r.headers.get('CloudFront-Viewer-Time-Zone') ?? undefined,\n };\n}\n\nexport function getGeolocation(r: Request): Geolocation {\n if (r.headers.get('x-vercel-id')) return getGeolocationFromVercel(r);\n if (r.headers.get('cf-ray')) return getGeolocationFromCloudflare(r);\n return getGeolocationFromCloudfront(r);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAiC;AAejC,SAAS,SAAS,OAA0C;AAC1D,SAAO,QAAQ,OAAO,KAAK,IAAI;AACjC;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,IAAI,gBAAgB,KAAK,EAAE,QAAQ,IAAI,kBAAkB,KAAK;AAAA,IACpF,MAAM,EAAE,QAAQ,IAAI,WAAW,KAAK;AAAA,IACpC,SAAS,EAAE,QAAQ,IAAI,cAAc,KAAK;AAAA,IAC1C,WAAW,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAC9C,WAAW,SAAS,EAAE,QAAQ,IAAI,gBAAgB,CAAC;AAAA,IACnD,UAAU,SAAS,EAAE,QAAQ,IAAI,eAAe,CAAC;AAAA,IACjD,QAAQ,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAC3C,YAAY,EAAE,QAAQ,IAAI,eAAe,KAAK;AAAA,IAC9C,aAAa,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAChD,WAAW,EAAE,QAAQ,IAAI,aAAa,KAAK;AAAA,EAC7C;AACF;AAGO,SAAS,yBAAyB,GAAyB;AAChE,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,IAAI,WAAW,KAAK;AAAA,IAC1C,MAAM,EAAE,QAAQ,IAAI,kBAAkB,KAAK;AAAA,IAC3C,SAAS,EAAE,QAAQ,IAAI,qBAAqB,KAAK;AAAA,IACjD,WAAW,EAAE,QAAQ,IAAI,uBAAuB,KAAK;AAAA,IACrD,WAAW,SAAS,EAAE,QAAQ,IAAI,uBAAuB,CAAC;AAAA,IAC1D,UAAU,SAAS,EAAE,QAAQ,IAAI,sBAAsB,CAAC;AAAA,IACxD,QAAQ,EAAE,QAAQ,IAAI,4BAA4B,KAAK;AAAA,IACvD,aAAa,EAAE,QAAQ,IAAI,yBAAyB,KAAK;AAAA,EAC3D;AACF;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,gBAAY,4BAAiB,EAAE,QAAQ,IAAI,2BAA2B,CAAC,KAAK;AAAA,IAC5E,MAAM,EAAE,QAAQ,IAAI,wBAAwB,KAAK;AAAA,IACjD,SAAS,EAAE,QAAQ,IAAI,2BAA2B,KAAK;AAAA,IACvD,WAAW,SAAS,EAAE,QAAQ,IAAI,6BAA6B,CAAC;AAAA,IAChE,UAAU,SAAS,EAAE,QAAQ,IAAI,4BAA4B,CAAC;AAAA,IAC9D,QAAQ,EAAE,QAAQ,IAAI,kCAAkC,KAAK;AAAA,IAC7D,YAAY,EAAE,QAAQ,IAAI,8BAA8B,KAAK;AAAA,IAC7D,aAAa,EAAE,QAAQ,IAAI,+BAA+B,KAAK;AAAA,IAC/D,WAAW,EAAE,QAAQ,IAAI,6BAA6B,KAAK;AAAA,EAC7D;AACF;AAEO,SAAS,eAAe,GAAyB;AACtD,MAAI,EAAE,QAAQ,IAAI,aAAa,EAAG,QAAO,yBAAyB,CAAC;AACnE,MAAI,EAAE,QAAQ,IAAI,QAAQ,EAAG,QAAO,6BAA6B,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/geolocation.ts"],"sourcesContent":["export type Geolocation = {\n ip_address?: string;\n city?: string;\n country?: string; // ISO 3166-1 alpha-2\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string; // ISO 3166-2\n metro_code?: string;\n postal_code?: string;\n time_zone?: string;\n};\n\nfunction toNumber(value: string | null): number | undefined {\n return value ? Number(value) : undefined;\n}\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nexport function getGeolocationFromCloudflare(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('true-client-ip') ?? r.headers.get('cf-connecting-ip') ?? undefined,\n city: r.headers.get('cf-ipcity') ?? undefined,\n country: r.headers.get('cf-ipcountry') ?? undefined,\n continent: r.headers.get('cf-ipcontinent') ?? undefined,\n longitude: toNumber(r.headers.get('cf-iplongitude')),\n latitude: toNumber(r.headers.get('cf-iplatitude')),\n region: r.headers.get('cf-region-code') ?? undefined,\n metro_code: r.headers.get('cf-metro-code') ?? undefined,\n postal_code: r.headers.get('cf-postal-code') ?? undefined,\n time_zone: r.headers.get('cf-timezone') ?? undefined,\n };\n}\n\n/** reference: https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nexport function getGeolocationFromVercel(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('x-real-ip') ?? undefined,\n city: r.headers.get('x-vercel-ip-city') ?? undefined,\n country: r.headers.get('x-vercel-ip-country') ?? undefined,\n continent: r.headers.get('x-vercel-ip-continent') ?? undefined,\n longitude: toNumber(r.headers.get('x-vercel-ip-longitude')),\n latitude: toNumber(r.headers.get('x-vercel-ip-latitude')),\n region: r.headers.get('x-vercel-ip-country-region') ?? undefined,\n postal_code: r.headers.get('x-vercel-ip-postal-code') ?? undefined,\n };\n}\n\nfunction stripPort(value: string | null): string | null {\n if (!value) return null;\n const i = value.lastIndexOf(':');\n return i !== -1 && /^\\d+$/.test(value.slice(i + 1)) ? value.slice(0, i) : value;\n}\n\n/** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nexport function getGeolocationFromCloudfront(r: Request): Geolocation {\n return {\n ip_address: stripPort(r.headers.get('CloudFront-Viewer-Address')) ?? undefined,\n city: r.headers.get('CloudFront-Viewer-City') ?? undefined,\n country: r.headers.get('CloudFront-Viewer-Country') ?? undefined,\n longitude: toNumber(r.headers.get('CloudFront-Viewer-Longitude')),\n latitude: toNumber(r.headers.get('CloudFront-Viewer-Latitude')),\n region: r.headers.get('CloudFront-Viewer-Country-Region') ?? undefined,\n metro_code: r.headers.get('CloudFront-Viewer-Metro-Code') ?? undefined,\n postal_code: r.headers.get('CloudFront-Viewer-Postal-Code') ?? undefined,\n time_zone: r.headers.get('CloudFront-Viewer-Time-Zone') ?? undefined,\n };\n}\n\nexport function getGeolocation(r: Request): Geolocation {\n if (r.headers.get('x-vercel-id')) return getGeolocationFromVercel(r);\n if (r.headers.get('cf-ray')) return getGeolocationFromCloudflare(r);\n return getGeolocationFromCloudfront(r);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,SAAS,SAAS,OAA0C;AAC1D,SAAO,QAAQ,OAAO,KAAK,IAAI;AACjC;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,IAAI,gBAAgB,KAAK,EAAE,QAAQ,IAAI,kBAAkB,KAAK;AAAA,IACpF,MAAM,EAAE,QAAQ,IAAI,WAAW,KAAK;AAAA,IACpC,SAAS,EAAE,QAAQ,IAAI,cAAc,KAAK;AAAA,IAC1C,WAAW,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAC9C,WAAW,SAAS,EAAE,QAAQ,IAAI,gBAAgB,CAAC;AAAA,IACnD,UAAU,SAAS,EAAE,QAAQ,IAAI,eAAe,CAAC;AAAA,IACjD,QAAQ,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAC3C,YAAY,EAAE,QAAQ,IAAI,eAAe,KAAK;AAAA,IAC9C,aAAa,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAChD,WAAW,EAAE,QAAQ,IAAI,aAAa,KAAK;AAAA,EAC7C;AACF;AAGO,SAAS,yBAAyB,GAAyB;AAChE,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,IAAI,WAAW,KAAK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AyB,CAAC;AACnE,MAAI,EAAE,QAAQ,IAAI,QAAQ,EAAG,QAAO,6BAA6B,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
@@ -1,5 +1,4 @@
1
1
  // src/utils/geolocation.ts
2
- import { extractIpAddress } from "./ip.mjs";
3
2
  function toNumber(value) {
4
3
  return value ? Number(value) : void 0;
5
4
  }
@@ -29,9 +28,14 @@ function getGeolocationFromVercel(r) {
29
28
  postal_code: r.headers.get("x-vercel-ip-postal-code") ?? void 0
30
29
  };
31
30
  }
31
+ function stripPort(value) {
32
+ if (!value) return null;
33
+ const i = value.lastIndexOf(":");
34
+ return i !== -1 && /^\d+$/.test(value.slice(i + 1)) ? value.slice(0, i) : value;
35
+ }
32
36
  function getGeolocationFromCloudfront(r) {
33
37
  return {
34
- ip_address: extractIpAddress(r.headers.get("CloudFront-Viewer-Address")) ?? void 0,
38
+ ip_address: stripPort(r.headers.get("CloudFront-Viewer-Address")) ?? void 0,
35
39
  city: r.headers.get("CloudFront-Viewer-City") ?? void 0,
36
40
  country: r.headers.get("CloudFront-Viewer-Country") ?? void 0,
37
41
  longitude: toNumber(r.headers.get("CloudFront-Viewer-Longitude")),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/geolocation.ts"],"sourcesContent":["import { extractIpAddress } from './ip';\n\nexport type Geolocation = {\n ip_address?: string;\n city?: string;\n country?: string; // ISO 3166-1 alpha-2\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string; // ISO 3166-2\n metro_code?: string;\n postal_code?: string;\n time_zone?: string;\n};\n\nfunction toNumber(value: string | null): number | undefined {\n return value ? Number(value) : undefined;\n}\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nexport function getGeolocationFromCloudflare(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('true-client-ip') ?? r.headers.get('cf-connecting-ip') ?? undefined,\n city: r.headers.get('cf-ipcity') ?? undefined,\n country: r.headers.get('cf-ipcountry') ?? undefined,\n continent: r.headers.get('cf-ipcontinent') ?? undefined,\n longitude: toNumber(r.headers.get('cf-iplongitude')),\n latitude: toNumber(r.headers.get('cf-iplatitude')),\n region: r.headers.get('cf-region-code') ?? undefined,\n metro_code: r.headers.get('cf-metro-code') ?? undefined,\n postal_code: r.headers.get('cf-postal-code') ?? undefined,\n time_zone: r.headers.get('cf-timezone') ?? undefined,\n };\n}\n\n/** reference: https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nexport function getGeolocationFromVercel(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('x-real-ip') ?? undefined,\n city: r.headers.get('x-vercel-ip-city') ?? undefined,\n country: r.headers.get('x-vercel-ip-country') ?? undefined,\n continent: r.headers.get('x-vercel-ip-continent') ?? undefined,\n longitude: toNumber(r.headers.get('x-vercel-ip-longitude')),\n latitude: toNumber(r.headers.get('x-vercel-ip-latitude')),\n region: r.headers.get('x-vercel-ip-country-region') ?? undefined,\n postal_code: r.headers.get('x-vercel-ip-postal-code') ?? undefined,\n };\n}\n\n/** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nexport function getGeolocationFromCloudfront(r: Request): Geolocation {\n return {\n ip_address: extractIpAddress(r.headers.get('CloudFront-Viewer-Address')) ?? undefined,\n city: r.headers.get('CloudFront-Viewer-City') ?? undefined,\n country: r.headers.get('CloudFront-Viewer-Country') ?? undefined,\n longitude: toNumber(r.headers.get('CloudFront-Viewer-Longitude')),\n latitude: toNumber(r.headers.get('CloudFront-Viewer-Latitude')),\n region: r.headers.get('CloudFront-Viewer-Country-Region') ?? undefined,\n metro_code: r.headers.get('CloudFront-Viewer-Metro-Code') ?? undefined,\n postal_code: r.headers.get('CloudFront-Viewer-Postal-Code') ?? undefined,\n time_zone: r.headers.get('CloudFront-Viewer-Time-Zone') ?? undefined,\n };\n}\n\nexport function getGeolocation(r: Request): Geolocation {\n if (r.headers.get('x-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IACvD,aAAa,EAAE,QAAQ,IAAI,yBAAyB,KAAK;AAAA,EAC3D;AACF;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,YAAY,iBAAiB,EAAE,QAAQ,IAAI,2BAA2B,CAAC,KAAK;AAAA,IAC5E,MAAM,EAAE,QAAQ,IAAI,wBAAwB,KAAK;AAAA,IACjD,SAAS,EAAE,QAAQ,IAAI,2BAA2B,KAAK;AAAA,IACvD,WAAW,SAAS,EAAE,QAAQ,IAAI,6BAA6B,CAAC;AAAA,IAChE,UAAU,SAAS,EAAE,QAAQ,IAAI,4BAA4B,CAAC;AAAA,IAC9D,QAAQ,EAAE,QAAQ,IAAI,kCAAkC,KAAK;AAAA,IAC7D,YAAY,EAAE,QAAQ,IAAI,8BAA8B,KAAK;AAAA,IAC7D,aAAa,EAAE,QAAQ,IAAI,+BAA+B,KAAK;AAAA,IAC/D,WAAW,EAAE,QAAQ,IAAI,6BAA6B,KAAK;AAAA,EAC7D;AACF;AAEO,SAAS,eAAe,GAAyB;AACtD,MAAI,EAAE,QAAQ,IAAI,aAAa,EAAG,QAAO,yBAAyB,CAAC;AACnE,MAAI,EAAE,QAAQ,IAAI,QAAQ,EAAG,QAAO,6BAA6B,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/geolocation.ts"],"sourcesContent":["export type Geolocation = {\n ip_address?: string;\n city?: string;\n country?: string; // ISO 3166-1 alpha-2\n continent?: string;\n longitude?: number;\n latitude?: number;\n region?: string; // ISO 3166-2\n metro_code?: string;\n postal_code?: string;\n time_zone?: string;\n};\n\nfunction toNumber(value: string | null): number | undefined {\n return value ? Number(value) : undefined;\n}\n\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nexport function getGeolocationFromCloudflare(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('true-client-ip') ?? r.headers.get('cf-connecting-ip') ?? undefined,\n city: r.headers.get('cf-ipcity') ?? undefined,\n country: r.headers.get('cf-ipcountry') ?? undefined,\n continent: r.headers.get('cf-ipcontinent') ?? undefined,\n longitude: toNumber(r.headers.get('cf-iplongitude')),\n latitude: toNumber(r.headers.get('cf-iplatitude')),\n region: r.headers.get('cf-region-code') ?? undefined,\n metro_code: r.headers.get('cf-metro-code') ?? undefined,\n postal_code: r.headers.get('cf-postal-code') ?? undefined,\n time_zone: r.headers.get('cf-timezone') ?? undefined,\n };\n}\n\n/** reference: https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nexport function getGeolocationFromVercel(r: Request): Geolocation {\n return {\n ip_address: r.headers.get('x-real-ip') ?? undefined,\n city: r.headers.get('x-vercel-ip-city') ?? undefined,\n country: r.headers.get('x-vercel-ip-country') ?? undefined,\n continent: r.headers.get('x-vercel-ip-continent') ?? undefined,\n longitude: toNumber(r.headers.get('x-vercel-ip-longitude')),\n latitude: toNumber(r.headers.get('x-vercel-ip-latitude')),\n region: r.headers.get('x-vercel-ip-country-region') ?? undefined,\n postal_code: r.headers.get('x-vercel-ip-postal-code') ?? undefined,\n };\n}\n\nfunction stripPort(value: string | null): string | null {\n if (!value) return null;\n const i = value.lastIndexOf(':');\n return i !== -1 && /^\\d+$/.test(value.slice(i + 1)) ? value.slice(0, i) : value;\n}\n\n/** reference: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nexport function getGeolocationFromCloudfront(r: Request): Geolocation {\n return {\n ip_address: stripPort(r.headers.get('CloudFront-Viewer-Address')) ?? undefined,\n city: r.headers.get('CloudFront-Viewer-City') ?? undefined,\n country: r.headers.get('CloudFront-Viewer-Country') ?? undefined,\n longitude: toNumber(r.headers.get('CloudFront-Viewer-Longitude')),\n latitude: toNumber(r.headers.get('CloudFront-Viewer-Latitude')),\n region: r.headers.get('CloudFront-Viewer-Country-Region') ?? undefined,\n metro_code: r.headers.get('CloudFront-Viewer-Metro-Code') ?? undefined,\n postal_code: r.headers.get('CloudFront-Viewer-Postal-Code') ?? undefined,\n time_zone: r.headers.get('CloudFront-Viewer-Time-Zone') ?? undefined,\n };\n}\n\nexport function getGeolocation(r: Request): Geolocation {\n if (r.headers.get('x-vercel-id')) return getGeolocationFromVercel(r);\n if (r.headers.get('cf-ray')) return getGeolocationFromCloudflare(r);\n return getGeolocationFromCloudfront(r);\n}\n"],"mappings":";AAaA,SAAS,SAAS,OAA0C;AAC1D,SAAO,QAAQ,OAAO,KAAK,IAAI;AACjC;AAGO,SAAS,6BAA6B,GAAyB;AACpE,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,IAAI,gBAAgB,KAAK,EAAE,QAAQ,IAAI,kBAAkB,KAAK;AAAA,IACpF,MAAM,EAAE,QAAQ,IAAI,WAAW,KAAK;AAAA,IACpC,SAAS,EAAE,QAAQ,IAAI,cAAc,KAAK;AAAA,IAC1C,WAAW,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAC9C,WAAW,SAAS,EAAE,QAAQ,IAAI,gBAAgB,CAAC;AAAA,IACnD,UAAU,SAAS,EAAE,QAAQ,IAAI,eAAe,CAAC;AAAA,IACjD,QAAQ,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAC3C,YAAY,EAAE,QAAQ,IAAI,eAAe,KAAK;AAAA,IAC9C,aAAa,EAAE,QAAQ,IAAI,gBAAgB,KAAK;AAAA,IAChD,WAAW,EAAE,QAAQ,IAAI,aAAa,KAAK;AAAA,EAC7C;AACF;AAGO,SAAS,yBAAyB,GAAyB;AAChE,SAAO;AAAA,IACL,YAAY,EAAE,QAAQ,IAAI,WAAW,KAAK;AAAA,IAC1C,MAAM,EAAE,QAAQ,IAAI,kBAAkB,KAAK;AAAA,IAC3C,SAAS,EAAE,QAAQ,IAAI,qBAAqB,KAAK;AAAA,IACjD,WAAW,EAAE,QAAQ,IAAI,uBAAuB,KAAK;AAAA,IACrD,WAAW,SAAS,EAAE,QAAQ,IAAI,uB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\n/**\n * In a browser, verify the set up by navigating to: https://example.com/metrics/healthy. The page\n * should read ok. Verify that geographical information is being included by navigating to:\n * https://example.com/metrics/?validate_geo=healthy. The page should read ok.\n */\nexport async function forwardToGoogleTagGateway(request: Request, gaId: string) {\n const GATEWAY_HOST = `${gaId}.fps.goog`;\n const { pathname, search } = new URL(request.url);\n\n const target = `https://${GATEWAY_HOST}${pathname}${search}`;\n\n const headers = new Headers();\n headers.set('host', GATEWAY_HOST);\n\n // Forward cookies\n const cookie = request.headers.get('cookie');\n if (cookie) headers.set('cookie', cookie);\n\n // Convert Vercel geo headers to Google Tag Gateway format\n // https://developers.google.com/tag-platform/tag-manager/gateway/setup-guide\n const { country, region } = getGeolocation(request);\n\n if (country && region) {\n headers.set('x-forwarded-countryregion', `${country}-${region}`);\n } else if (country) {\n headers.set('x-forwarded-country', country);\n } else if (region) {\n headers.set('x-forwarded-region', region);\n }\n\n const hasBody = request.method !== 'GET' && request.method !== 'HEAD';\n const response = await fetch(target, {\n method: request.method,\n headers,\n body: hasBody ? request.body : undefined,\n ...(hasBody && { duplex: 'half' as const }),\n });\n\n // Strip content-encoding/content-length because fetch() auto-decompresses\n // but keeps the original headers, causing ERR_CONTENT_DECODING_FAILED\n const responseHeaders = new Headers(response.headers);\n responseHeaders.delete('content-encoding');\n responseHeaders.delete('content-length');\n\n return new Response(response.body, { status: response.status, headers: responseHeaders });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA+B;AAO/B,eAAsB,0BAA0B,SAAkB,MAAc;AAC9E,QAAM,eAAe,GAAG,IAAI;AAC5B,QAAM,EAAE,UAAU,OAAO,IAAI,IAAI,IAAI,QAAQ,GAAG;AAEhD,QAAM,SAAS,WAAW,YAAY,GAAG,QAAQ,GAAG,MAAM;AAE1D,QAAM,UAAU,IAAI,QAAQ;AAC5B,UAAQ,IAAI,QAAQ,YAAY;AAGhC,QAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,OAAQ,SAAQ,IAAI,UAAU,MAAM;AAIxC,QAAM,EAAE,SAAS,OAAO,QAAI,mCAAe,OAAO;AAElD,MAAI,WAAW,QAAQ;AACrB,YAAQ,IAAI,6BAA6B,GAAG,OAAO,IAAI,MAAM,EAAE;AAAA,EACjE,WAAW,SAAS;AAClB,YAAQ,IAAI,uBAAuB,OAAO;AAAA,EAC5C,WAAW,QAAQ;AACjB,YAAQ,IAAI,sBAAsB,MAAM;AAAA,EAC1C;AAEA,QAAM,UAAU,QAAQ,WAAW,SAAS,QAAQ,WAAW;AAC/D,QAAM,WAAW,MAAM,MAAM,QAAQ;AAAA,IACnC,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA,MAAM,UAAU,QAAQ,OAAO;AAAA,IAC/B,GAAI,WAAW,EAAE,QAAQ,OAAgB;AAAA,EAC3C,CAAC;AAID,QAAM,kBAAkB,IAAI,QAAQ,SAAS,OAAO;AACpD,kBAAgB,OAAO,kBAAkB;AACzC,kBAAgB,OAAO,gBAAgB;AAEvC,SAAO,IAAI,SAAS,SAAS,MAAM,EAAE,QAAQ,SAAS,QAAQ,SAAS,gBAAgB,CAAC;AAC1F;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/google-tag-gateway.ts"],"sourcesContent":["import { getGeolocation } from './geolocation';\n\n/**\n * In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page\n * should read ok. Verify that geographical information is being included by navigating to:\n * https://example.com/metrics/?validate_geo=healthy. The page should read ok.\n */\nexport async function forwardToGoogleTagGateway(request: Request, gaId: string) {\n const GATEWAY_HOST = `${gaId}.fps.goog`;\n const { pathname, search } = new URL(request.url);\n\n const target = `https://${GATEWAY_HOST}${pathname}${search}`;\n\n const headers = new Headers();\n headers.set('host', GATEWAY_HOST);\n\n // Forward cookies\n const cookie = request.headers.get('cookie');\n if (cookie) headers.set('cookie', cookie);\n\n // Convert Vercel geo headers to Google Tag Gateway format\n // https://developers.google.com/tag-platform/tag-manager/gateway/setup-guide\n const { country, region } = getGeolocation(request);\n\n if (country && region) {\n headers.set('x-forwarded-countryregion', `${country}-${region}`);\n } else if (country) {\n headers.set('x-forwarded-country', country);\n } else if (region) {\n headers.set('x-forwarded-region', region);\n }\n\n const hasBody = request.method !== 'GET' && request.method !== 'HEAD';\n const response = await fetch(target, {\n method: request.method,\n headers,\n body: hasBody ? request.body : undefined,\n ...(hasBody && { duplex: 'half' as const }),\n });\n\n // Strip content-encoding/content-length because fetch() auto-decompresses\n // but keeps the original headers, causing ERR_CONTENT_DECODING_FAILED\n const responseHeaders = new Headers(response.headers);\n responseHeaders.delete('content-encoding');\n responseHeaders.delete('content-length');\n\n return new Response(response.body, { status: response.status, headers: responseHeaders });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAA+B;AAO/B,eAAsB,0BAA0B,SAAkB,MAAc;AAC9E,QAAM,eAAe,GAAG,IAAI;AAC5B,QAAM,EAAE,UAAU,OAAO,IAAI,IAAI,IAAI,QAAQ,GAAG;AAEhD,QAAM,SAAS,WAAW,YAAY,GAAG,QAAQ,GAAG,MAAM;AAE1D,QAAM,UAAU,IAAI,QAAQ;AAC5B,UAAQ,IAAI,QAAQ,YAAY;AAGhC,QAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,OAAQ,SAAQ,IAAI,UAAU,MAAM;AAIxC,QAAM,EAAE,SAAS,OAAO,QAAI,mCAAe,OAAO;AAElD,MAAI,WAAW,QAAQ;AACrB,YAAQ,IAAI,6BAA6B,GAAG,OAAO,IAAI,MAAM,EAAE;AAAA,EACjE,WAAW,SAAS;AAClB,YAAQ,IAAI,uBAAuB,OAAO;AAAA,EAC5C,WAAW,QAAQ;AACjB,YAAQ,IAAI,sBAAsB,MAAM;AAAA,EAC1C;AAEA,QAAM,UAAU,QAAQ,WAAW,SAAS,QAAQ,WAAW;AAC/D,QAAM,WAAW,MAAM,MAAM,QAAQ;AAAA,IACnC,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA,MAAM,UAAU,QAAQ,OAAO;AAAA,IAC/B,GAAI,WAAW,EAAE,QAAQ,OAAgB;AAAA,EAC3C,CAAC;AAID,QAAM,kBAAkB,IAAI,QAAQ,SAAS,OAAO;AACpD,kBAAgB,OAAO,kBAAkB;AACzC,kBAAgB,OAAO,gBAAgB;AAEvC,SAAO,IAAI,SAAS,SAAS,MAAM,EAAE,QAAQ,SAAS,QAAQ,SAAS,gBAAgB,CAAC;AAC1F;","names":[]}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * In a browser, verify the set up by navigating to: https://example.com/metrics/healthy. The page
2
+ * In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page
3
3
  * should read ok. Verify that geographical information is being included by navigating to:
4
4
  * https://example.com/metrics/?validate_geo=healthy. The page should read ok.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * In a browser, verify the set up by navigating to: https://example.com/metrics/healthy. The page
2
+ * In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page
3
3
  * should read ok. Verify that geographical information is being included by navigating to:
4
4
  * https://example.com/metrics/?validate_geo=healthy. The page should read ok.
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/google-tag-gateway.ts"],"sourcesContent":["import { getGeolocation } from './geolocation';\n\n/**\n * In a browser, verify the set up by navigating to: https://example.com/metrics/healthy. The page\n * should read ok. Verify that geographical information is being included by navigating to:\n * https://example.com/metrics/?validate_geo=healthy. The page should read ok.\n */\nexport async function forwardToGoogleTagGateway(request: Request, gaId: string) {\n const GATEWAY_HOST = `${gaId}.fps.goog`;\n const { pathname, search } = new URL(request.url);\n\n const target = `https://${GATEWAY_HOST}${pathname}${search}`;\n\n const headers = new Headers();\n headers.set('host', GATEWAY_HOST);\n\n // Forward cookies\n const cookie = request.headers.get('cookie');\n if (cookie) headers.set('cookie', cookie);\n\n // Convert Vercel geo headers to Google Tag Gateway format\n // https://developers.google.com/tag-platform/tag-manager/gateway/setup-guide\n const { country, region } = getGeolocation(request);\n\n if (country && region) {\n headers.set('x-forwarded-countryregion', `${country}-${region}`);\n } else if (country) {\n headers.set('x-forwarded-country', country);\n } else if (region) {\n headers.set('x-forwarded-region', region);\n }\n\n const hasBody = request.method !== 'GET' && request.method !== 'HEAD';\n const response = await fetch(target, {\n method: request.method,\n headers,\n body: hasBody ? request.body : undefined,\n ...(hasBody && { duplex: 'half' as const }),\n });\n\n // Strip content-encoding/content-length because fetch() auto-decompresses\n // but keeps the original headers, causing ERR_CONTENT_DECODING_FAILED\n const responseHeaders = new Headers(response.headers);\n responseHeaders.delete('content-encoding');\n responseHeaders.delete('content-length');\n\n return new Response(response.body, { status: response.status, headers: responseHeaders });\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAO/B,eAAsB,0BAA0B,SAAkB,MAAc;AAC9E,QAAM,eAAe,GAAG,IAAI;AAC5B,QAAM,EAAE,UAAU,OAAO,IAAI,IAAI,IAAI,QAAQ,GAAG;AAEhD,QAAM,SAAS,WAAW,YAAY,GAAG,QAAQ,GAAG,MAAM;AAE1D,QAAM,UAAU,IAAI,QAAQ;AAC5B,UAAQ,IAAI,QAAQ,YAAY;AAGhC,QAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,OAAQ,SAAQ,IAAI,UAAU,MAAM;AAIxC,QAAM,EAAE,SAAS,OAAO,IAAI,eAAe,OAAO;AAElD,MAAI,WAAW,QAAQ;AACrB,YAAQ,IAAI,6BAA6B,GAAG,OAAO,IAAI,MAAM,EAAE;AAAA,EACjE,WAAW,SAAS;AAClB,YAAQ,IAAI,uBAAuB,OAAO;AAAA,EAC5C,WAAW,QAAQ;AACjB,YAAQ,IAAI,sBAAsB,MAAM;AAAA,EAC1C;AAEA,QAAM,UAAU,QAAQ,WAAW,SAAS,QAAQ,WAAW;AAC/D,QAAM,WAAW,MAAM,MAAM,QAAQ;AAAA,IACnC,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA,MAAM,UAAU,QAAQ,OAAO;AAAA,IAC/B,GAAI,WAAW,EAAE,QAAQ,OAAgB;AAAA,EAC3C,CAAC;AAID,QAAM,kBAAkB,IAAI,QAAQ,SAAS,OAAO;AACpD,kBAAgB,OAAO,kBAAkB;AACzC,kBAAgB,OAAO,gBAAgB;AAEvC,SAAO,IAAI,SAAS,SAAS,MAAM,EAAE,QAAQ,SAAS,QAAQ,SAAS,gBAAgB,CAAC;AAC1F;","names":[]}
1
+ {"version":3,"sources":["../../src/utils/google-tag-gateway.ts"],"sourcesContent":["import { getGeolocation } from './geolocation';\n\n/**\n * In a browser, verify the setup by navigating to: https://example.com/metrics/healthy. The page\n * should read ok. Verify that geographical information is being included by navigating to:\n * https://example.com/metrics/?validate_geo=healthy. The page should read ok.\n */\nexport async function forwardToGoogleTagGateway(request: Request, gaId: string) {\n const GATEWAY_HOST = `${gaId}.fps.goog`;\n const { pathname, search } = new URL(request.url);\n\n const target = `https://${GATEWAY_HOST}${pathname}${search}`;\n\n const headers = new Headers();\n headers.set('host', GATEWAY_HOST);\n\n // Forward cookies\n const cookie = request.headers.get('cookie');\n if (cookie) headers.set('cookie', cookie);\n\n // Convert Vercel geo headers to Google Tag Gateway format\n // https://developers.google.com/tag-platform/tag-manager/gateway/setup-guide\n const { country, region } = getGeolocation(request);\n\n if (country && region) {\n headers.set('x-forwarded-countryregion', `${country}-${region}`);\n } else if (country) {\n headers.set('x-forwarded-country', country);\n } else if (region) {\n headers.set('x-forwarded-region', region);\n }\n\n const hasBody = request.method !== 'GET' && request.method !== 'HEAD';\n const response = await fetch(target, {\n method: request.method,\n headers,\n body: hasBody ? request.body : undefined,\n ...(hasBody && { duplex: 'half' as const }),\n });\n\n // Strip content-encoding/content-length because fetch() auto-decompresses\n // but keeps the original headers, causing ERR_CONTENT_DECODING_FAILED\n const responseHeaders = new Headers(response.headers);\n responseHeaders.delete('content-encoding');\n responseHeaders.delete('content-length');\n\n return new Response(response.body, { status: response.status, headers: responseHeaders });\n}\n"],"mappings":";AAAA,SAAS,sBAAsB;AAO/B,eAAsB,0BAA0B,SAAkB,MAAc;AAC9E,QAAM,eAAe,GAAG,IAAI;AAC5B,QAAM,EAAE,UAAU,OAAO,IAAI,IAAI,IAAI,QAAQ,GAAG;AAEhD,QAAM,SAAS,WAAW,YAAY,GAAG,QAAQ,GAAG,MAAM;AAE1D,QAAM,UAAU,IAAI,QAAQ;AAC5B,UAAQ,IAAI,QAAQ,YAAY;AAGhC,QAAM,SAAS,QAAQ,QAAQ,IAAI,QAAQ;AAC3C,MAAI,OAAQ,SAAQ,IAAI,UAAU,MAAM;AAIxC,QAAM,EAAE,SAAS,OAAO,IAAI,eAAe,OAAO;AAElD,MAAI,WAAW,QAAQ;AACrB,YAAQ,IAAI,6BAA6B,GAAG,OAAO,IAAI,MAAM,EAAE;AAAA,EACjE,WAAW,SAAS;AAClB,YAAQ,IAAI,uBAAuB,OAAO;AAAA,EAC5C,WAAW,QAAQ;AACjB,YAAQ,IAAI,sBAAsB,MAAM;AAAA,EAC1C;AAEA,QAAM,UAAU,QAAQ,WAAW,SAAS,QAAQ,WAAW;AAC/D,QAAM,WAAW,MAAM,MAAM,QAAQ;AAAA,IACnC,QAAQ,QAAQ;AAAA,IAChB;AAAA,IACA,MAAM,UAAU,QAAQ,OAAO;AAAA,IAC/B,GAAI,WAAW,EAAE,QAAQ,OAAgB;AAAA,EAC3C,CAAC;AAID,QAAM,kBAAkB,IAAI,QAAQ,SAAS,OAAO;AACpD,kBAAgB,OAAO,kBAAkB;AACzC,kBAAgB,OAAO,gBAAgB;AAEvC,SAAO,IAAI,SAAS,SAAS,MAAM,EAAE,QAAQ,SAAS,QAAQ,SAAS,gBAAgB,CAAC;AAC1F;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "2.10.1",
3
+ "version": "2.10.2",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
package/dist/utils/ip.cjs DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/utils/ip.ts
21
- var ip_exports = {};
22
- __export(ip_exports, {
23
- extractIpAddress: () => extractIpAddress
24
- });
25
- module.exports = __toCommonJS(ip_exports);
26
- var import_net = require("net");
27
- function extractIpAddress(ip) {
28
- if (!ip) return null;
29
- if ((0, import_net.isIPv4)(ip) || (0, import_net.isIPv6)(ip)) return ip;
30
- if (ip.includes(".") && ip.includes(":")) {
31
- const [address] = ip.split(":");
32
- if ((0, import_net.isIPv4)(address)) return address;
33
- }
34
- if (!ip.includes("[") && !ip.includes("]") && !ip.includes(".") && ip.includes(":")) {
35
- const parts = ip.split(":");
36
- parts.pop();
37
- const address = parts.join(":");
38
- if ((0, import_net.isIPv6)(address)) return address;
39
- }
40
- try {
41
- const url = new URL(`https://${ip}`);
42
- const hostname = url.hostname.replace("[", "").replace("]", "");
43
- if ((0, import_net.isIPv4)(hostname) || (0, import_net.isIPv6)(hostname)) return hostname;
44
- return null;
45
- } catch (_) {
46
- return null;
47
- }
48
- }
49
- // Annotate the CommonJS export names for ESM import in node:
50
- 0 && (module.exports = {
51
- extractIpAddress
52
- });
53
- //# sourceMappingURL=ip.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/ip.ts"],"sourcesContent":["import { isIPv4, isIPv6 } from 'net';\n\nexport function extractIpAddress(ip: string | undefined | null): string | null {\n if (!ip) return null;\n if (isIPv4(ip) || isIPv6(ip)) return ip;\n if (ip.includes('.') && ip.includes(':')) {\n const [address] = ip.split(':');\n if (isIPv4(address)) return address;\n }\n if (!ip.includes('[') && !ip.includes(']') && !ip.includes('.') && ip.includes(':')) {\n const parts = ip.split(':');\n parts.pop();\n const address = parts.join(':');\n if (isIPv6(address)) return address;\n }\n\n try {\n const url = new URL(`https://${ip}`);\n const hostname = url.hostname.replace('[', '').replace(']', '');\n if (isIPv4(hostname) || isIPv6(hostname)) return hostname;\n return null;\n } catch (_) {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA+B;AAExB,SAAS,iBAAiB,IAA8C;AAC7E,MAAI,CAAC,GAAI,QAAO;AAChB,UAAI,mBAAO,EAAE,SAAK,mBAAO,EAAE,EAAG,QAAO;AACrC,MAAI,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,GAAG;AACxC,UAAM,CAAC,OAAO,IAAI,GAAG,MAAM,GAAG;AAC9B,YAAI,mBAAO,OAAO,EAAG,QAAO;AAAA,EAC9B;AACA,MAAI,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,GAAG;AACnF,UAAM,QAAQ,GAAG,MAAM,GAAG;AAC1B,UAAM,IAAI;AACV,UAAM,UAAU,MAAM,KAAK,GAAG;AAC9B,YAAI,mBAAO,OAAO,EAAG,QAAO;AAAA,EAC9B;AAEA,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,WAAW,EAAE,EAAE;AACnC,UAAM,WAAW,IAAI,SAAS,QAAQ,KAAK,EAAE,EAAE,QAAQ,KAAK,EAAE;AAC9D,YAAI,mBAAO,QAAQ,SAAK,mBAAO,QAAQ,EAAG,QAAO;AACjD,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,3 +0,0 @@
1
- declare function extractIpAddress(ip: string | undefined | null): string | null;
2
-
3
- export { extractIpAddress };
@@ -1,3 +0,0 @@
1
- declare function extractIpAddress(ip: string | undefined | null): string | null;
2
-
3
- export { extractIpAddress };
package/dist/utils/ip.mjs DELETED
@@ -1,28 +0,0 @@
1
- // src/utils/ip.ts
2
- import { isIPv4, isIPv6 } from "net";
3
- function extractIpAddress(ip) {
4
- if (!ip) return null;
5
- if (isIPv4(ip) || isIPv6(ip)) return ip;
6
- if (ip.includes(".") && ip.includes(":")) {
7
- const [address] = ip.split(":");
8
- if (isIPv4(address)) return address;
9
- }
10
- if (!ip.includes("[") && !ip.includes("]") && !ip.includes(".") && ip.includes(":")) {
11
- const parts = ip.split(":");
12
- parts.pop();
13
- const address = parts.join(":");
14
- if (isIPv6(address)) return address;
15
- }
16
- try {
17
- const url = new URL(`https://${ip}`);
18
- const hostname = url.hostname.replace("[", "").replace("]", "");
19
- if (isIPv4(hostname) || isIPv6(hostname)) return hostname;
20
- return null;
21
- } catch (_) {
22
- return null;
23
- }
24
- }
25
- export {
26
- extractIpAddress
27
- };
28
- //# sourceMappingURL=ip.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/utils/ip.ts"],"sourcesContent":["import { isIPv4, isIPv6 } from 'net';\n\nexport function extractIpAddress(ip: string | undefined | null): string | null {\n if (!ip) return null;\n if (isIPv4(ip) || isIPv6(ip)) return ip;\n if (ip.includes('.') && ip.includes(':')) {\n const [address] = ip.split(':');\n if (isIPv4(address)) return address;\n }\n if (!ip.includes('[') && !ip.includes(']') && !ip.includes('.') && ip.includes(':')) {\n const parts = ip.split(':');\n parts.pop();\n const address = parts.join(':');\n if (isIPv6(address)) return address;\n }\n\n try {\n const url = new URL(`https://${ip}`);\n const hostname = url.hostname.replace('[', '').replace(']', '');\n if (isIPv4(hostname) || isIPv6(hostname)) return hostname;\n return null;\n } catch (_) {\n return null;\n }\n}\n"],"mappings":";AAAA,SAAS,QAAQ,cAAc;AAExB,SAAS,iBAAiB,IAA8C;AAC7E,MAAI,CAAC,GAAI,QAAO;AAChB,MAAI,OAAO,EAAE,KAAK,OAAO,EAAE,EAAG,QAAO;AACrC,MAAI,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,GAAG;AACxC,UAAM,CAAC,OAAO,IAAI,GAAG,MAAM,GAAG;AAC9B,QAAI,OAAO,OAAO,EAAG,QAAO;AAAA,EAC9B;AACA,MAAI,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,SAAS,GAAG,KAAK,CAAC,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,GAAG,GAAG;AACnF,UAAM,QAAQ,GAAG,MAAM,GAAG;AAC1B,UAAM,IAAI;AACV,UAAM,UAAU,MAAM,KAAK,GAAG;AAC9B,QAAI,OAAO,OAAO,EAAG,QAAO;AAAA,EAC9B;AAEA,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,WAAW,EAAE,EAAE;AACnC,UAAM,WAAW,IAAI,SAAS,QAAQ,KAAK,EAAE,EAAE,QAAQ,KAAK,EAAE;AAC9D,QAAI,OAAO,QAAQ,KAAK,OAAO,QAAQ,EAAG,QAAO;AACjD,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WAAO;AAAA,EACT;AACF;","names":[]}