@shware/http 0.2.15 → 0.2.17

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.
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ // src/__tests__/ip.test.ts
4
+ var import_ip = require("../utils/ip.cjs");
5
+ describe("extractIpAddress", () => {
6
+ it("should extract the ipv4 address from the request", () => {
7
+ expect((0, import_ip.extractIpAddress)("127.0.0.1")).toBe("127.0.0.1");
8
+ expect((0, import_ip.extractIpAddress)("192.168.0.1")).toBe("192.168.0.1");
9
+ expect((0, import_ip.extractIpAddress)("127.0.0.1:8080")).toBe("127.0.0.1");
10
+ expect((0, import_ip.extractIpAddress)("192.168.0.1:8080")).toBe("192.168.0.1");
11
+ expect((0, import_ip.extractIpAddress)("127.0.0.1:8080/path")).toBe("127.0.0.1");
12
+ });
13
+ it("should extract the ipv6 address from the request", () => {
14
+ expect((0, import_ip.extractIpAddress)("::1")).toBe("::1");
15
+ expect((0, import_ip.extractIpAddress)("[::1]:8080")).toBe("::1");
16
+ expect((0, import_ip.extractIpAddress)("2001:0db8:85a3:0000:0000:8a2e:0370:7334")).toBe(
17
+ "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
18
+ );
19
+ expect((0, import_ip.extractIpAddress)("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80")).toBe(
20
+ "2001:db8:85a3::8a2e:370:7334"
21
+ // remove leading zeros
22
+ );
23
+ expect((0, import_ip.extractIpAddress)("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path")).toBe(
24
+ "2001:db8:85a3::8a2e:370:7334"
25
+ // remove leading zeros
26
+ );
27
+ });
28
+ it("should return null if the ip address is not valid", () => {
29
+ expect((0, import_ip.extractIpAddress)(null)).toBeNull();
30
+ expect((0, import_ip.extractIpAddress)(void 0)).toBeNull();
31
+ expect((0, import_ip.extractIpAddress)("invalid")).toBeNull();
32
+ expect((0, import_ip.extractIpAddress)("example.com")).toBeNull();
33
+ });
34
+ });
35
+ //# sourceMappingURL=ip.test.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/__tests__/ip.test.ts"],"sourcesContent":["import { extractIpAddress } from '../utils/ip';\n\ndescribe('extractIpAddress', () => {\n it('should extract the ipv4 address from the request', () => {\n expect(extractIpAddress('127.0.0.1')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1:8080')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080/path')).toBe('127.0.0.1');\n });\n\n it('should extract the ipv6 address from the request', () => {\n expect(extractIpAddress('::1')).toBe('::1');\n expect(extractIpAddress('[::1]:8080')).toBe('::1');\n\n expect(extractIpAddress('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).toBe(\n '2001:0db8:85a3:0000:0000:8a2e:0370:7334'\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n });\n\n it('should return null if the ip address is not valid', () => {\n expect(extractIpAddress(null)).toBeNull();\n expect(extractIpAddress(undefined)).toBeNull();\n expect(extractIpAddress('invalid')).toBeNull();\n expect(extractIpAddress('example.com')).toBeNull();\n });\n});\n"],"mappings":";;;AAAA,gBAAiC;AAEjC,SAAS,oBAAoB,MAAM;AACjC,KAAG,oDAAoD,MAAM;AAC3D,eAAO,4BAAiB,WAAW,CAAC,EAAE,KAAK,WAAW;AACtD,eAAO,4BAAiB,aAAa,CAAC,EAAE,KAAK,aAAa;AAC1D,eAAO,4BAAiB,gBAAgB,CAAC,EAAE,KAAK,WAAW;AAC3D,eAAO,4BAAiB,kBAAkB,CAAC,EAAE,KAAK,aAAa;AAC/D,eAAO,4BAAiB,qBAAqB,CAAC,EAAE,KAAK,WAAW;AAAA,EAClE,CAAC;AAED,KAAG,oDAAoD,MAAM;AAC3D,eAAO,4BAAiB,KAAK,CAAC,EAAE,KAAK,KAAK;AAC1C,eAAO,4BAAiB,YAAY,CAAC,EAAE,KAAK,KAAK;AAEjD,eAAO,4BAAiB,yCAAyC,CAAC,EAAE;AAAA,MAClE;AAAA,IACF;AACA,eAAO,4BAAiB,8CAA8C,CAAC,EAAE;AAAA,MACvE;AAAA;AAAA,IACF;AACA,eAAO,4BAAiB,mDAAmD,CAAC,EAAE;AAAA,MAC5E;AAAA;AAAA,IACF;AAAA,EACF,CAAC;AAED,KAAG,qDAAqD,MAAM;AAC5D,eAAO,4BAAiB,IAAI,CAAC,EAAE,SAAS;AACxC,eAAO,4BAAiB,MAAS,CAAC,EAAE,SAAS;AAC7C,eAAO,4BAAiB,SAAS,CAAC,EAAE,SAAS;AAC7C,eAAO,4BAAiB,aAAa,CAAC,EAAE,SAAS;AAAA,EACnD,CAAC;AACH,CAAC;","names":[]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,33 @@
1
+ // src/__tests__/ip.test.ts
2
+ import { extractIpAddress } from "../utils/ip.mjs";
3
+ describe("extractIpAddress", () => {
4
+ it("should extract the ipv4 address from the request", () => {
5
+ expect(extractIpAddress("127.0.0.1")).toBe("127.0.0.1");
6
+ expect(extractIpAddress("192.168.0.1")).toBe("192.168.0.1");
7
+ expect(extractIpAddress("127.0.0.1:8080")).toBe("127.0.0.1");
8
+ expect(extractIpAddress("192.168.0.1:8080")).toBe("192.168.0.1");
9
+ expect(extractIpAddress("127.0.0.1:8080/path")).toBe("127.0.0.1");
10
+ });
11
+ it("should extract the ipv6 address from the request", () => {
12
+ expect(extractIpAddress("::1")).toBe("::1");
13
+ expect(extractIpAddress("[::1]:8080")).toBe("::1");
14
+ expect(extractIpAddress("2001:0db8:85a3:0000:0000:8a2e:0370:7334")).toBe(
15
+ "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
16
+ );
17
+ expect(extractIpAddress("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80")).toBe(
18
+ "2001:db8:85a3::8a2e:370:7334"
19
+ // remove leading zeros
20
+ );
21
+ expect(extractIpAddress("[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path")).toBe(
22
+ "2001:db8:85a3::8a2e:370:7334"
23
+ // remove leading zeros
24
+ );
25
+ });
26
+ it("should return null if the ip address is not valid", () => {
27
+ expect(extractIpAddress(null)).toBeNull();
28
+ expect(extractIpAddress(void 0)).toBeNull();
29
+ expect(extractIpAddress("invalid")).toBeNull();
30
+ expect(extractIpAddress("example.com")).toBeNull();
31
+ });
32
+ });
33
+ //# sourceMappingURL=ip.test.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/__tests__/ip.test.ts"],"sourcesContent":["import { extractIpAddress } from '../utils/ip';\n\ndescribe('extractIpAddress', () => {\n it('should extract the ipv4 address from the request', () => {\n expect(extractIpAddress('127.0.0.1')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080')).toBe('127.0.0.1');\n expect(extractIpAddress('192.168.0.1:8080')).toBe('192.168.0.1');\n expect(extractIpAddress('127.0.0.1:8080/path')).toBe('127.0.0.1');\n });\n\n it('should extract the ipv6 address from the request', () => {\n expect(extractIpAddress('::1')).toBe('::1');\n expect(extractIpAddress('[::1]:8080')).toBe('::1');\n\n expect(extractIpAddress('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).toBe(\n '2001:0db8:85a3:0000:0000:8a2e:0370:7334'\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n expect(extractIpAddress('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80/path')).toBe(\n '2001:db8:85a3::8a2e:370:7334' // remove leading zeros\n );\n });\n\n it('should return null if the ip address is not valid', () => {\n expect(extractIpAddress(null)).toBeNull();\n expect(extractIpAddress(undefined)).toBeNull();\n expect(extractIpAddress('invalid')).toBeNull();\n expect(extractIpAddress('example.com')).toBeNull();\n });\n});\n"],"mappings":";AAAA,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB,MAAM;AACjC,KAAG,oDAAoD,MAAM;AAC3D,WAAO,iBAAiB,WAAW,CAAC,EAAE,KAAK,WAAW;AACtD,WAAO,iBAAiB,aAAa,CAAC,EAAE,KAAK,aAAa;AAC1D,WAAO,iBAAiB,gBAAgB,CAAC,EAAE,KAAK,WAAW;AAC3D,WAAO,iBAAiB,kBAAkB,CAAC,EAAE,KAAK,aAAa;AAC/D,WAAO,iBAAiB,qBAAqB,CAAC,EAAE,KAAK,WAAW;AAAA,EAClE,CAAC;AAED,KAAG,oDAAoD,MAAM;AAC3D,WAAO,iBAAiB,KAAK,CAAC,EAAE,KAAK,KAAK;AAC1C,WAAO,iBAAiB,YAAY,CAAC,EAAE,KAAK,KAAK;AAEjD,WAAO,iBAAiB,yCAAyC,CAAC,EAAE;AAAA,MAClE;AAAA,IACF;AACA,WAAO,iBAAiB,8CAA8C,CAAC,EAAE;AAAA,MACvE;AAAA;AAAA,IACF;AACA,WAAO,iBAAiB,mDAAmD,CAAC,EAAE;AAAA,MAC5E;AAAA;AAAA,IACF;AAAA,EACF,CAAC;AAED,KAAG,qDAAqD,MAAM;AAC5D,WAAO,iBAAiB,IAAI,CAAC,EAAE,SAAS;AACxC,WAAO,iBAAiB,MAAS,CAAC,EAAE,SAAS;AAC7C,WAAO,iBAAiB,SAAS,CAAC,EAAE,SAAS;AAC7C,WAAO,iBAAiB,aAAa,CAAC,EAAE,SAAS;AAAA,EACnD,CAAC;AACH,CAAC;","names":[]}
@@ -24,6 +24,7 @@ __export(geolocation_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(geolocation_exports);
26
26
  var import_adapter = require("hono/adapter");
27
+ var import_ip = require("../utils/ip.cjs");
27
28
  var runtime = (0, import_adapter.getRuntimeKey)();
28
29
  function geolocation(c) {
29
30
  if (runtime === "workerd") {
@@ -55,7 +56,7 @@ function geolocation(c) {
55
56
  };
56
57
  }
57
58
  return {
58
- ip_address: c.req.header("CloudFront-Viewer-Address")?.split(":").at(0) ?? null,
59
+ ip_address: (0, import_ip.extractIpAddress)(c.req.header("CloudFront-Viewer-Address")),
59
60
  city: c.req.header("CloudFront-Viewer-City") ?? null,
60
61
  country: c.req.header("CloudFront-Viewer-Country") ?? null,
61
62
  continent: null,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import { getRuntimeKey } from 'hono/adapter';\nimport type { Context } from 'hono';\n\nexport type Geolocation = {\n ip_address: string | null;\n city: string | null;\n country: string | null; // ISO 3166-1 alpha-2\n continent: string | null;\n longitude: number | null;\n latitude: number | null;\n region: string | null; // ISO 3166-2\n metro_code: string | null;\n postal_code: string | null;\n time_zone: string | null;\n};\n\nconst runtime = getRuntimeKey();\nexport function geolocation(c: Context): Geolocation | null {\n /** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\n if (runtime === 'workerd') {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip') ?? null,\n city: c.req.header('cf-ipcity') ?? null,\n country: c.req.header('cf-ipcountry') ?? null,\n continent: c.req.header('cf-ipcontinent') ?? null,\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : null,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : null,\n region: c.req.header('cf-region-code') ?? null,\n metro_code: c.req.header('cf-metro-code') ?? null,\n postal_code: c.req.header('cf-postal-code') ?? null,\n time_zone: c.req.header('cf-timezone') ?? null,\n };\n }\n\n /** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\n if (c.req.header('x-vercel-id')) {\n return {\n ip_address: c.req.header('x-real-ip') ?? null,\n city: c.req.header('x-vercel-ip-city') ?? null,\n country: c.req.header('x-vercel-ip-country') ?? null,\n continent: c.req.header('x-vercel-ip-continent') ?? null,\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : null,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : null,\n region: c.req.header('x-vercel-ip-country-region') ?? null,\n metro_code: null,\n postal_code: c.req.header('x-vercel-ip-postal-code') ?? null,\n time_zone: null,\n };\n }\n\n // cloudfront\n // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location\n return {\n ip_address: c.req.header('CloudFront-Viewer-Address')?.split(':').at(0) ?? null,\n city: c.req.header('CloudFront-Viewer-City') ?? null,\n country: c.req.header('CloudFront-Viewer-Country') ?? null,\n continent: null,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : null,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : null,\n region: c.req.header('CloudFront-Viewer-Country-Region') ?? null,\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code') ?? null,\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code') ?? null,\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone') ?? null,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAgB9B,IAAM,cAAU,8BAAc;AACvB,SAAS,YAAY,GAAgC;AAE1D,MAAI,YAAY,WAAW;AACzB,WAAO;AAAA,MACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,MAClF,MAAM,EAAE,IAAI,O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K;AAAA,IAC3E,MAAM,EAAE,IAAI,OAAO,wBAAwB,KAAK;AAAA,IAChD,SAAS,EAAE,IAAI,OAAO,2BAA2B,KAAK;AAAA,IACtD,WAAW;AAAA,IACX,WAAW,EAAE,IAAI,OAAO,6BAA6B,IACjD,OAAO,EAAE,IAAI,OAAO,6BAA6B,CAAC,IAClD;AAAA,IACJ,UAAU,EAAE,IAAI,OAAO,4BAA4B,IAC/C,OAAO,EAAE,IAAI,OAAO,4BAA4B,CAAC,IACjD;AAAA,IACJ,QAAQ,EAAE,IAAI,OAAO,kCAAkC,KAAK;AAAA,IAC5D,YAAY,EAAE,IAAI,OAAO,8BAA8B,KAAK;AAAA,IAC5D,aAAa,EAAE,IAAI,OAAO,+BAA+B,KAAK;AAAA,IAC9D,WAAW,EAAE,IAAI,OAAO,6BAA6B,KAAK;AAAA,EAC5D;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import { getRuntimeKey } from 'hono/adapter';\nimport { extractIpAddress } from '../utils/ip';\nimport type { Context } from 'hono';\n\nexport type Geolocation = {\n ip_address: string | null;\n city: string | null;\n country: string | null; // ISO 3166-1 alpha-2\n continent: string | null;\n longitude: number | null;\n latitude: number | null;\n region: string | null; // ISO 3166-2\n metro_code: string | null;\n postal_code: string | null;\n time_zone: string | null;\n};\n\nconst runtime = getRuntimeKey();\nexport function geolocation(c: Context): Geolocation | null {\n /** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\n if (runtime === 'workerd') {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip') ?? null,\n city: c.req.header('cf-ipcity') ?? null,\n country: c.req.header('cf-ipcountry') ?? null,\n continent: c.req.header('cf-ipcontinent') ?? null,\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : null,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : null,\n region: c.req.header('cf-region-code') ?? null,\n metro_code: c.req.header('cf-metro-code') ?? null,\n postal_code: c.req.header('cf-postal-code') ?? null,\n time_zone: c.req.header('cf-timezone') ?? null,\n };\n }\n\n /** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\n if (c.req.header('x-vercel-id')) {\n return {\n ip_address: c.req.header('x-real-ip') ?? null,\n city: c.req.header('x-vercel-ip-city') ?? null,\n country: c.req.header('x-vercel-ip-country') ?? null,\n continent: c.req.header('x-vercel-ip-continent') ?? null,\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : null,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : null,\n region: c.req.header('x-vercel-ip-country-region') ?? null,\n metro_code: null,\n postal_code: c.req.header('x-vercel-ip-postal-code') ?? null,\n time_zone: null,\n };\n }\n\n // cloudfront\n // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location\n return {\n ip_address: extractIpAddress(c.req.header('CloudFront-Viewer-Address')),\n city: c.req.header('CloudFront-Viewer-City') ?? null,\n country: c.req.header('CloudFront-Viewer-Country') ?? null,\n continent: null,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : null,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : null,\n region: c.req.header('CloudFront-Viewer-Country-Region') ?? null,\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code') ?? null,\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code') ?? null,\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone') ?? null,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAC9B,gBAAiC;AAgBjC,IAAM,cAAU,8BAAc;AACvB,SAAS,YAAY,G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,OAAO,yBAAyB,KAAK;AAAA,MACxD,WAAW;AAAA,IACb;AAAA,EACF;AAIA,SAAO;AAAA,IACL,gBAAY,4BAAiB,EAAE,IAAI,OAAO,2BAA2B,CAAC;AAAA,IACtE,MAAM,EAAE,IAAI,OAAO,wBAAwB,KAAK;AAAA,IAChD,SAAS,EAAE,IAAI,OAAO,2BAA2B,KAAK;AAAA,IACtD,WAAW;AAAA,IACX,WAAW,EAAE,IAAI,OAAO,6BAA6B,IACjD,OAAO,EAAE,IAAI,OAAO,6BAA6B,CAAC,IAClD;AAAA,IACJ,UAAU,EAAE,IAAI,OAAO,4BAA4B,IAC/C,OAAO,EAAE,IAAI,OAAO,4BAA4B,CAAC,IACjD;AAAA,IACJ,QAAQ,EAAE,IAAI,OAAO,kCAAkC,KAAK;AAAA,IAC5D,YAAY,EAAE,IAAI,OAAO,8BAA8B,KAAK;AAAA,IAC5D,aAAa,EAAE,IAAI,OAAO,+BAA+B,KAAK;AAAA,IAC9D,WAAW,EAAE,IAAI,OAAO,6BAA6B,KAAK;AAAA,EAC5D;AACF;","names":[]}
@@ -1,5 +1,6 @@
1
1
  // src/hono/geolocation.ts
2
2
  import { getRuntimeKey } from "hono/adapter";
3
+ import { extractIpAddress } from "../utils/ip.mjs";
3
4
  var runtime = getRuntimeKey();
4
5
  function geolocation(c) {
5
6
  if (runtime === "workerd") {
@@ -31,7 +32,7 @@ function geolocation(c) {
31
32
  };
32
33
  }
33
34
  return {
34
- ip_address: c.req.header("CloudFront-Viewer-Address")?.split(":").at(0) ?? null,
35
+ ip_address: extractIpAddress(c.req.header("CloudFront-Viewer-Address")),
35
36
  city: c.req.header("CloudFront-Viewer-City") ?? null,
36
37
  country: c.req.header("CloudFront-Viewer-Country") ?? null,
37
38
  continent: null,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/geolocation.ts"],"sourcesContent":["import { getRuntimeKey } from 'hono/adapter';\nimport type { Context } from 'hono';\n\nexport type Geolocation = {\n ip_address: string | null;\n city: string | null;\n country: string | null; // ISO 3166-1 alpha-2\n continent: string | null;\n longitude: number | null;\n latitude: number | null;\n region: string | null; // ISO 3166-2\n metro_code: string | null;\n postal_code: string | null;\n time_zone: string | null;\n};\n\nconst runtime = getRuntimeKey();\nexport function geolocation(c: Context): Geolocation | null {\n /** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\n if (runtime === 'workerd') {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip') ?? null,\n city: c.req.header('cf-ipcity') ?? null,\n country: c.req.header('cf-ipcountry') ?? null,\n continent: c.req.header('cf-ipcontinent') ?? null,\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : null,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : null,\n region: c.req.header('cf-region-code') ?? null,\n metro_code: c.req.header('cf-metro-code') ?? null,\n postal_code: c.req.header('cf-postal-code') ?? null,\n time_zone: c.req.header('cf-timezone') ?? null,\n };\n }\n\n /** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\n if (c.req.header('x-vercel-id')) {\n return {\n ip_address: c.req.header('x-real-ip') ?? null,\n city: c.req.header('x-vercel-ip-city') ?? null,\n country: c.req.header('x-vercel-ip-country') ?? null,\n continent: c.req.header('x-vercel-ip-continent') ?? null,\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : null,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : null,\n region: c.req.header('x-vercel-ip-country-region') ?? null,\n metro_code: null,\n postal_code: c.req.header('x-vercel-ip-postal-code') ?? null,\n time_zone: null,\n };\n }\n\n // cloudfront\n // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location\n return {\n ip_address: c.req.header('CloudFront-Viewer-Address')?.split(':').at(0) ?? null,\n city: c.req.header('CloudFront-Viewer-City') ?? null,\n country: c.req.header('CloudFront-Viewer-Country') ?? null,\n continent: null,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : null,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : null,\n region: c.req.header('CloudFront-Viewer-Country-Region') ?? null,\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code') ?? null,\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code') ?? null,\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone') ?? null,\n };\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAgB9B,IAAM,UAAU,cAAc;AACvB,SAAS,YAAY,GAAgC;AAE1D,MAAI,YAAY,WAAW;AACzB,WAAO;AAAA,MACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,MAClF,MAAM,EAAE,IAAI,OAAO,WAAW,KAAK;AAAA,MACnC,SAAS,EAAE,IAAI,OAAO,cAAc,KAAK;AAAA,MACzC,WAAW,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,MAC7C,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,MACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,MAClF,QAAQ,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,MAC1C,YAAY,EAAE,IAAI,OAAO,eAAe,KAAK;AAAA,MAC7C,aAAa,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,MAC/C,WAAW,EAAE,IAAI,OAAO,aAAa,KAAK;AAAA,IAC5C;AAAA,EACF;AAGA,MAAI,EAAE,IAAI,OAAO,aAAa,GAAG;AAC/B,WAAO;AAAA,MACL,YA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getRuntimeKey } from 'hono/adapter';\nimport { extractIpAddress } from '../utils/ip';\nimport type { Context } from 'hono';\n\nexport type Geolocation = {\n ip_address: string | null;\n city: string | null;\n country: string | null; // ISO 3166-1 alpha-2\n continent: string | null;\n longitude: number | null;\n latitude: number | null;\n region: string | null; // ISO 3166-2\n metro_code: string | null;\n postal_code: string | null;\n time_zone: string | null;\n};\n\nconst runtime = getRuntimeKey();\nexport function geolocation(c: Context): Geolocation | null {\n /** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\n if (runtime === 'workerd') {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip') ?? null,\n city: c.req.header('cf-ipcity') ?? null,\n country: c.req.header('cf-ipcountry') ?? null,\n continent: c.req.header('cf-ipcontinent') ?? null,\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : null,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : null,\n region: c.req.header('cf-region-code') ?? null,\n metro_code: c.req.header('cf-metro-code') ?? null,\n postal_code: c.req.header('cf-postal-code') ?? null,\n time_zone: c.req.header('cf-timezone') ?? null,\n };\n }\n\n /** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\n if (c.req.header('x-vercel-id')) {\n return {\n ip_address: c.req.header('x-real-ip') ?? null,\n city: c.req.header('x-vercel-ip-city') ?? null,\n country: c.req.header('x-vercel-ip-country') ?? null,\n continent: c.req.header('x-vercel-ip-continent') ?? null,\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : null,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : null,\n region: c.req.header('x-vercel-ip-country-region') ?? null,\n metro_code: null,\n postal_code: c.req.header('x-vercel-ip-postal-code') ?? null,\n time_zone: null,\n };\n }\n\n // cloudfront\n // https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location\n return {\n ip_address: extractIpAddress(c.req.header('CloudFront-Viewer-Address')),\n city: c.req.header('CloudFront-Viewer-City') ?? null,\n country: c.req.header('CloudFront-Viewer-Country') ?? null,\n continent: null,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : null,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : null,\n region: c.req.header('CloudFront-Viewer-Country-Region') ?? null,\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code') ?? null,\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code') ?? null,\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone') ?? null,\n };\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AAgBjC,IAAM,UAAU,cAAc;AACvB,SAAS,YAAY,GAAgC;AAE1D,MAAI,YAAY,WAAW;AACzB,WAAO;AAAA,MACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,MAClF,MAAM,EAAE,IAAI,OAAO,WAAW,KAAK;AAAA,MACnC,SAAS,EAAE,IAAI,OAAO,cAAc,KAAK;AAAA,MACzC,WAAW,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,MAC7C,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,MACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,MAClF,QAAQ,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,MAC1C,YAAY,EAAE,IAAI,OAAO,eAAe,KAAK;AAAA,MAC7C,aAAa,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,MAC/C,WAAW,EAAE,IA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B,KAAK;AAAA,EAC5D;AACF;","names":[]}
@@ -0,0 +1,43 @@
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
+ try {
31
+ const url = new URL(`https://${ip}`);
32
+ const hostname = url.hostname.replace("[", "").replace("]", "");
33
+ if ((0, import_net.isIPv4)(hostname) || (0, import_net.isIPv6)(hostname)) return hostname;
34
+ return null;
35
+ } catch (_) {
36
+ return null;
37
+ }
38
+ }
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ extractIpAddress
42
+ });
43
+ //# sourceMappingURL=ip.cjs.map
@@ -0,0 +1 @@
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 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;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":[]}
@@ -0,0 +1,3 @@
1
+ declare function extractIpAddress(ip: string | undefined | null): string | null;
2
+
3
+ export { extractIpAddress };
@@ -0,0 +1,3 @@
1
+ declare function extractIpAddress(ip: string | undefined | null): string | null;
2
+
3
+ export { extractIpAddress };
@@ -0,0 +1,18 @@
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
+ try {
7
+ const url = new URL(`https://${ip}`);
8
+ const hostname = url.hostname.replace("[", "").replace("]", "");
9
+ if (isIPv4(hostname) || isIPv6(hostname)) return hostname;
10
+ return null;
11
+ } catch (_) {
12
+ return null;
13
+ }
14
+ }
15
+ export {
16
+ extractIpAddress
17
+ };
18
+ //# sourceMappingURL=ip.mjs.map
@@ -0,0 +1 @@
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 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;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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {