@shware/http 0.2.12 → 0.2.13

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.
@@ -24,8 +24,8 @@ __export(geolocation_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(geolocation_exports);
26
26
  var import_adapter = require("hono/adapter");
27
+ var runtime = (0, import_adapter.getRuntimeKey)();
27
28
  function geolocation(c) {
28
- const runtime = (0, import_adapter.getRuntimeKey)();
29
29
  if (runtime === "workerd") {
30
30
  return {
31
31
  ip: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip") ?? null,
@@ -34,25 +34,37 @@ function geolocation(c) {
34
34
  continent: c.req.header("cf-ipcontinent") ?? null,
35
35
  longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : null,
36
36
  latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : null,
37
- region: c.req.header("cf-region") ?? null,
38
- region_code: c.req.header("cf-region-code") ?? null,
37
+ region: c.req.header("cf-region-code") ?? null,
39
38
  metro_code: c.req.header("cf-metro-code") ?? null,
40
39
  postal_code: c.req.header("cf-postal-code") ?? null,
41
40
  timezone: c.req.header("cf-timezone") ?? null
42
41
  };
43
42
  }
43
+ if (c.req.header("x-vercel-id")) {
44
+ return {
45
+ ip: c.req.header("x-real-ip") ?? null,
46
+ city: c.req.header("x-vercel-ip-city") ?? null,
47
+ country: c.req.header("x-vercel-ip-country") ?? null,
48
+ continent: c.req.header("x-vercel-ip-continent") ?? null,
49
+ longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : null,
50
+ latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : null,
51
+ region: c.req.header("x-vercel-ip-country-region") ?? null,
52
+ metro_code: null,
53
+ postal_code: c.req.header("x-vercel-ip-postal-code") ?? null,
54
+ timezone: null
55
+ };
56
+ }
44
57
  return {
45
- ip: c.req.header("x-real-ip") ?? null,
46
- city: c.req.header("x-vercel-ip-city") ?? null,
47
- country: c.req.header("x-vercel-ip-country") ?? null,
48
- continent: c.req.header("x-vercel-ip-continent") ?? null,
49
- longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : null,
50
- latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : null,
51
- region: null,
52
- region_code: c.req.header("x-vercel-ip-country-region") ?? null,
53
- metro_code: null,
54
- postal_code: c.req.header("x-vercel-ip-postal-code") ?? null,
55
- timezone: null
58
+ ip: c.req.header("CloudFront-Viewer-Address") ?? null,
59
+ city: c.req.header("CloudFront-Viewer-City") ?? null,
60
+ country: c.req.header("CloudFront-Viewer-Country") ?? null,
61
+ continent: null,
62
+ longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) : null,
63
+ latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) : null,
64
+ region: c.req.header("CloudFront-Viewer-Country-Region") ?? null,
65
+ metro_code: c.req.header("CloudFront-Viewer-Metro-Code") ?? null,
66
+ postal_code: c.req.header("CloudFront-Viewer-Postal-Code") ?? null,
67
+ timezone: c.req.header("CloudFront-Viewer-Time-Zone") ?? null
56
68
  };
57
69
  }
58
70
  // Annotate the CommonJS export names for ESM import in node:
@@ -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: string | null;\n city: string | null;\n country: string | null;\n continent: string | null;\n longitude: number | null;\n latitude: number | null;\n region: string | null;\n region_code: string | null;\n metro_code: string | null;\n postal_code: string | null;\n timezone: string | null;\n};\n\nexport function geolocation(c: Context): Geolocation {\n const runtime = getRuntimeKey();\n /** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\n if (runtime === 'workerd') {\n return {\n ip: 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') ?? null,\n region_code: 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 timezone: c.req.header('cf-timezone') ?? null,\n };\n }\n\n /** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\n return {\n ip: 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: null,\n region_code: 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 timezone: null,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAiBvB,SAAS,YAAY,GAAyB;AACnD,QAAM,cAAU,8BAAc;AAE9B,MAAI,YAAY,WAAW;AACzB,WAAO;AAAA,MACL,IAAI,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,MAC1E,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,WAAW,KAAK;AAAA,MACrC,aAAa,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,MAC/C,YAAY,EAAE,IAAI,OAAO,eAAe,KAAK;AAAA,MAC7C,aAAa,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,MAC/C,UAAU,EAAE,IAAI,OAAO,aAAa,KAAK;AAAA,IAC3C;AAAA,EACF;AAGA,SAAO;AAAA,IACL,IAAI,EAAE,IAAI,OAAO,WAAW,KAAK;AAAA,IACjC,MAAM,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,IAC1C,SAAS,EAAE,IAAI,OAAO,qBAAqB,KAAK;AAAA,IAChD,WAAW,EAAE,IAAI,OAAO,uBAAuB,KAAK;AAAA,IACpD,WAAW,EAAE,IAAI,OAAO,uBAAuB,IAC3C,OAAO,EAAE,IAAI,OAAO,uBAAuB,CAAC,IAC5C;AAAA,IACJ,UAAU,EAAE,IAAI,OAAO,sBAAsB,IACzC,OAAO,EAAE,IAAI,OAAO,sBAAsB,CAAC,IAC3C;AAAA,IACJ,QAAQ;AAAA,IACR,aAAa,EAAE,IAAI,OAAO,4BAA4B,KAAK;AAAA,IAC3D,YAAY;AAAA,IACZ,aAAa,EAAE,IAAI,OAAO,yBAAyB,KAAK;AAAA,IACxD,UAAU;AAAA,EACZ;AACF;","names":[]}
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: 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 timezone: 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: 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 timezone: 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: 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 timezone: 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: c.req.header('CloudFront-Viewer-Address') ?? 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 timezone: 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,IAAI,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,MAC1E,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,UAAU,EAAE,IAAI,OAAO,aAAa,KAAK;AAAA,IAC3C;AAAA,EACF;AAGA,MAAI,EAAE,IAAI,OAAO,aAAa,GAAG;AAC/B,WAAO;AAAA,MACL,IAAI,EAAE,IAAI,OAAO,WAAW,KAAK;AAAA,MACjC,MAAM,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,MAC1C,SAAS,EAAE,IAAI,OAAO,qBAAqB,KAAK;AAAA,MAChD,WAAW,EAAE,IAAI,OAAO,uBAAuB,KAAK;AAAA,MACpD,WAAW,EAAE,IAAI,OAAO,uBAAuB,IAC3C,OAAO,EAAE,IAAI,OAAO,uBAAuB,CAAC,IAC5C;AAAA,MACJ,UAAU,EAAE,IAAI,OAAO,sBAAsB,IACzC,OAAO,EAAE,IAAI,OAAO,sBAAsB,CAAC,IAC3C;AAAA,MACJ,QAAQ,EAAE,IAAI,OAAO,4BAA4B,KAAK;AAAA,MACtD,YAAY;AAAA,MACZ,aAAa,EAAE,IAAI,OAAO,yBAAyB,KAAK;AAAA,MACxD,UAAU;AAAA,IACZ;AAAA,EACF;AAIA,SAAO;AAAA,IACL,IAAI,EAAE,IAAI,OAAO,2BAA2B,KAAK;AAAA,IACjD,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,UAAU,EAAE,IAAI,OAAO,6BAA6B,KAAK;AAAA,EAC3D;AACF;","names":[]}
@@ -8,11 +8,10 @@ type Geolocation = {
8
8
  longitude: number | null;
9
9
  latitude: number | null;
10
10
  region: string | null;
11
- region_code: string | null;
12
11
  metro_code: string | null;
13
12
  postal_code: string | null;
14
13
  timezone: string | null;
15
14
  };
16
- declare function geolocation(c: Context): Geolocation;
15
+ declare function geolocation(c: Context): Geolocation | null;
17
16
 
18
17
  export { type Geolocation, geolocation };
@@ -8,11 +8,10 @@ type Geolocation = {
8
8
  longitude: number | null;
9
9
  latitude: number | null;
10
10
  region: string | null;
11
- region_code: string | null;
12
11
  metro_code: string | null;
13
12
  postal_code: string | null;
14
13
  timezone: string | null;
15
14
  };
16
- declare function geolocation(c: Context): Geolocation;
15
+ declare function geolocation(c: Context): Geolocation | null;
17
16
 
18
17
  export { type Geolocation, geolocation };
@@ -1,7 +1,7 @@
1
1
  // src/hono/geolocation.ts
2
2
  import { getRuntimeKey } from "hono/adapter";
3
+ var runtime = getRuntimeKey();
3
4
  function geolocation(c) {
4
- const runtime = getRuntimeKey();
5
5
  if (runtime === "workerd") {
6
6
  return {
7
7
  ip: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip") ?? null,
@@ -10,25 +10,37 @@ function geolocation(c) {
10
10
  continent: c.req.header("cf-ipcontinent") ?? null,
11
11
  longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : null,
12
12
  latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : null,
13
- region: c.req.header("cf-region") ?? null,
14
- region_code: c.req.header("cf-region-code") ?? null,
13
+ region: c.req.header("cf-region-code") ?? null,
15
14
  metro_code: c.req.header("cf-metro-code") ?? null,
16
15
  postal_code: c.req.header("cf-postal-code") ?? null,
17
16
  timezone: c.req.header("cf-timezone") ?? null
18
17
  };
19
18
  }
19
+ if (c.req.header("x-vercel-id")) {
20
+ return {
21
+ ip: c.req.header("x-real-ip") ?? null,
22
+ city: c.req.header("x-vercel-ip-city") ?? null,
23
+ country: c.req.header("x-vercel-ip-country") ?? null,
24
+ continent: c.req.header("x-vercel-ip-continent") ?? null,
25
+ longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : null,
26
+ latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : null,
27
+ region: c.req.header("x-vercel-ip-country-region") ?? null,
28
+ metro_code: null,
29
+ postal_code: c.req.header("x-vercel-ip-postal-code") ?? null,
30
+ timezone: null
31
+ };
32
+ }
20
33
  return {
21
- ip: c.req.header("x-real-ip") ?? null,
22
- city: c.req.header("x-vercel-ip-city") ?? null,
23
- country: c.req.header("x-vercel-ip-country") ?? null,
24
- continent: c.req.header("x-vercel-ip-continent") ?? null,
25
- longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : null,
26
- latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : null,
27
- region: null,
28
- region_code: c.req.header("x-vercel-ip-country-region") ?? null,
29
- metro_code: null,
30
- postal_code: c.req.header("x-vercel-ip-postal-code") ?? null,
31
- timezone: null
34
+ ip: c.req.header("CloudFront-Viewer-Address") ?? null,
35
+ city: c.req.header("CloudFront-Viewer-City") ?? null,
36
+ country: c.req.header("CloudFront-Viewer-Country") ?? null,
37
+ continent: null,
38
+ longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) : null,
39
+ latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) : null,
40
+ region: c.req.header("CloudFront-Viewer-Country-Region") ?? null,
41
+ metro_code: c.req.header("CloudFront-Viewer-Metro-Code") ?? null,
42
+ postal_code: c.req.header("CloudFront-Viewer-Postal-Code") ?? null,
43
+ timezone: c.req.header("CloudFront-Viewer-Time-Zone") ?? null
32
44
  };
33
45
  }
34
46
  export {
@@ -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: string | null;\n city: string | null;\n country: string | null;\n continent: string | null;\n longitude: number | null;\n latitude: number | null;\n region: string | null;\n region_code: string | null;\n metro_code: string | null;\n postal_code: string | null;\n timezone: string | null;\n};\n\nexport function geolocation(c: Context): Geolocation {\n const runtime = getRuntimeKey();\n /** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\n if (runtime === 'workerd') {\n return {\n ip: 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') ?? null,\n region_code: 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 timezone: c.req.header('cf-timezone') ?? null,\n };\n }\n\n /** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\n return {\n ip: 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: null,\n region_code: 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 timezone: null,\n };\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAiBvB,SAAS,YAAY,GAAyB;AACnD,QAAM,UAAU,cAAc;AAE9B,MAAI,YAAY,WAAW;AACzB,WAAO;AAAA,MACL,IAAI,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,M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Content":["import { getRuntimeKey } from 'hono/adapter';\nimport type { Context } from 'hono';\n\nexport type Geolocation = {\n ip: 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 timezone: 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: 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 timezone: 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: 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 timezone: 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: c.req.header('CloudFront-Viewer-Address') ?? 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 timezone: 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,IAAI,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,MAC1E,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,UAAU,EAAE,IAAI,OAAO,aAAa,KAAK;AAAA,IAC3C;AAAA,EACF;AAGA,MAAI,E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
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -30,10 +30,10 @@
30
30
  ],
31
31
  "devDependencies": {
32
32
  "@types/jest": "^29.5.14",
33
- "@types/node": "^22.13.10",
33
+ "@types/node": "^22.13.13",
34
34
  "jest": "^29.7.0",
35
- "ts-jest": "^29.2.6",
36
- "typescript": "5.8.2"
35
+ "ts-jest": "^29.3.0",
36
+ "typescript": "^5.8.2"
37
37
  },
38
38
  "dependencies": {
39
39
  "zod": "^3.24.2"