@shware/http 2.0.1 → 2.1.0

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.
@@ -27,44 +27,44 @@ var import_adapter = require("hono/adapter");
27
27
  var import_ip = require("../utils/ip.cjs");
28
28
  function getGeolocationFromCloudflareWorker(c) {
29
29
  return {
30
- ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip") ?? null,
31
- city: c.req.header("cf-ipcity") ?? null,
32
- country: c.req.header("cf-ipcountry") ?? null,
33
- continent: c.req.header("cf-ipcontinent") ?? null,
34
- longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : null,
35
- latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : null,
36
- region: c.req.header("cf-region-code") ?? null,
37
- metro_code: c.req.header("cf-metro-code") ?? null,
38
- postal_code: c.req.header("cf-postal-code") ?? null,
39
- time_zone: c.req.header("cf-timezone") ?? null
30
+ ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip"),
31
+ city: c.req.header("cf-ipcity"),
32
+ country: c.req.header("cf-ipcountry"),
33
+ continent: c.req.header("cf-ipcontinent"),
34
+ longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : void 0,
35
+ latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : void 0,
36
+ region: c.req.header("cf-region-code"),
37
+ metro_code: c.req.header("cf-metro-code"),
38
+ postal_code: c.req.header("cf-postal-code"),
39
+ time_zone: c.req.header("cf-timezone")
40
40
  };
41
41
  }
42
42
  function getGeolocationFromVercel(c) {
43
43
  return {
44
- ip_address: c.req.header("x-real-ip") ?? null,
45
- city: c.req.header("x-vercel-ip-city") ?? null,
46
- country: c.req.header("x-vercel-ip-country") ?? null,
47
- continent: c.req.header("x-vercel-ip-continent") ?? null,
48
- longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : null,
49
- latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : null,
50
- region: c.req.header("x-vercel-ip-country-region") ?? null,
51
- metro_code: null,
52
- postal_code: c.req.header("x-vercel-ip-postal-code") ?? null,
53
- time_zone: null
44
+ ip_address: c.req.header("x-real-ip"),
45
+ city: c.req.header("x-vercel-ip-city"),
46
+ country: c.req.header("x-vercel-ip-country"),
47
+ continent: c.req.header("x-vercel-ip-continent"),
48
+ longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : void 0,
49
+ latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : void 0,
50
+ region: c.req.header("x-vercel-ip-country-region"),
51
+ metro_code: void 0,
52
+ postal_code: c.req.header("x-vercel-ip-postal-code"),
53
+ time_zone: void 0
54
54
  };
55
55
  }
56
56
  function getGeolocationFromCloudfront(c) {
57
57
  return {
58
- ip_address: (0, import_ip.extractIpAddress)(c.req.header("CloudFront-Viewer-Address")),
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
- time_zone: c.req.header("CloudFront-Viewer-Time-Zone") ?? null
58
+ ip_address: (0, import_ip.extractIpAddress)(c.req.header("CloudFront-Viewer-Address")) ?? void 0,
59
+ city: c.req.header("CloudFront-Viewer-City"),
60
+ country: c.req.header("CloudFront-Viewer-Country"),
61
+ continent: void 0,
62
+ longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) : void 0,
63
+ latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) : void 0,
64
+ region: c.req.header("CloudFront-Viewer-Country-Region"),
65
+ metro_code: c.req.header("CloudFront-Viewer-Metro-Code"),
66
+ postal_code: c.req.header("CloudFront-Viewer-Postal-Code"),
67
+ time_zone: c.req.header("CloudFront-Viewer-Time-Zone")
68
68
  };
69
69
  }
70
70
  function geolocation(c) {
@@ -1 +1 @@
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\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nfunction getGeolocationFromCloudflareWorker(c: Context): Geolocation {\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 */\nfunction getGeolocationFromVercel(c: Context): Geolocation {\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/** ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nfunction getGeolocationFromCloudfront(c: Context): Geolocation {\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\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflareWorker(c);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c);\n return getGeolocationFromCloudfront(c);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAC9B,gBAAiC;AAiBjC,SAAS,mCAAmC,GAAyB;AACnE,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAA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AAE,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;AAEO,SAAS,YAAY,GAAyB;AACnD,UAAI,8BAAc,MAAM,UAAW,QAAO,mCAAmC,CAAC;AAC9E,MAAI,EAAE,IAAI,OAAO,aAAa,EAAG,QAAO,yBAAyB,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","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;\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\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nfunction getGeolocationFromCloudflareWorker(c: Context): Geolocation {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip'),\n city: c.req.header('cf-ipcity'),\n country: c.req.header('cf-ipcountry'),\n continent: c.req.header('cf-ipcontinent'),\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : undefined,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : undefined,\n region: c.req.header('cf-region-code'),\n metro_code: c.req.header('cf-metro-code'),\n postal_code: c.req.header('cf-postal-code'),\n time_zone: c.req.header('cf-timezone'),\n };\n}\n\n/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nfunction getGeolocationFromVercel(c: Context): Geolocation {\n return {\n ip_address: c.req.header('x-real-ip'),\n city: c.req.header('x-vercel-ip-city'),\n country: c.req.header('x-vercel-ip-country'),\n continent: c.req.header('x-vercel-ip-continent'),\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : undefined,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : undefined,\n region: c.req.header('x-vercel-ip-country-region'),\n metro_code: undefined,\n postal_code: c.req.header('x-vercel-ip-postal-code'),\n time_zone: undefined,\n };\n}\n\n/** ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nfunction getGeolocationFromCloudfront(c: Context): Geolocation {\n return {\n ip_address: extractIpAddress(c.req.header('CloudFront-Viewer-Address')) ?? undefined,\n city: c.req.header('CloudFront-Viewer-City'),\n country: c.req.header('CloudFront-Viewer-Country'),\n continent: undefined,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : undefined,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : undefined,\n region: c.req.header('CloudFront-Viewer-Country-Region'),\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code'),\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code'),\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone'),\n };\n}\n\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflareWorker(c);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c);\n return getGeolocationFromCloudfront(c);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA8B;AAC9B,gBAAiC;AAiBjC,SAAS,mCAAmC,GAAyB;AACnE,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB;AAAA,IAC7E,MAAM,EAAE,IAAI,OAAO,WAAW;AAAA,IAC9B,SAAS,EAAE,IAAI,OAAO,cAAc;AAAA,IACpC,WAAW,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACxC,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,IACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,IAClF,QAAQ,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACrC,YAAY,EAAE,IAAI,OAAO,eAAe;AAAA,IACxC,aAAa,EAAE,IAAI,OAAO,gBAAgB;AAAA,IAC1C,WAAW,EAAE,IAAI,OAAO,aAAa;AAAA,EACvC;AACF;AAGA,SAAS,yBAAyB,GAAyB;AACzD,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,WAAW;AAAA,IACpC,MAAM,EAAE,IAAI,OAAO,kBAAkB;AAAA,IACrC,SAAS,EAAE,IAAI,OAAO,qBAAqB;AAAA,IAC3C,WAAW,EAAE,IAAI,OAAO,uBAAuB;AAAA,IAC/C,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,EAAE,IAAI,OAAO,4BAA4B;AAAA,IACjD,YAAY;AAAA,IACZ,aAAa,EAAE,IAAI,OAAO,yBAAyB;AAAA,IACnD,WAAW;AAAA,EACb;AACF;AAGA,SAAS,6BAA6B,GAAyB;AAC7D,SAAO;AAAA,IACL,gBAAY,4BAAiB,EAAE,IAAI,OAAO,2BAA2B,CAAC,KAAK;AAAA,IAC3E,MAAM,EAAE,IAAI,OAAO,wBAAwB;AAAA,IAC3C,SAAS,EAAE,IAAI,OAAO,2BAA2B;AAAA,IACjD,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;AAAA,IACvD,YAAY,EAAE,IAAI,OAAO,8BAA8B;AAAA,IACvD,aAAa,EAAE,IAAI,OAAO,+BAA+B;AAAA,IACzD,WAAW,EAAE,IAAI,OAAO,6BAA6B;AAAA,EACvD;AACF;AAEO,SAAS,YAAY,GAAyB;AACnD,UAAI,8BAAc,MAAM,UAAW,QAAO,mCAAmC,CAAC;AAC9E,MAAI,EAAE,IAAI,OAAO,aAAa,EAAG,QAAO,yBAAyB,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
@@ -1,16 +1,16 @@
1
1
  import { Context } from 'hono';
2
2
 
3
3
  type Geolocation = {
4
- ip_address: string | null;
5
- city: string | null;
6
- country: string | null;
7
- continent: string | null;
8
- longitude: number | null;
9
- latitude: number | null;
10
- region: string | null;
11
- metro_code: string | null;
12
- postal_code: string | null;
13
- time_zone: string | null;
4
+ ip_address?: string;
5
+ city?: string;
6
+ country?: string;
7
+ continent?: string;
8
+ longitude?: number;
9
+ latitude?: number;
10
+ region?: string;
11
+ metro_code?: string;
12
+ postal_code?: string;
13
+ time_zone?: string;
14
14
  };
15
15
  declare function geolocation(c: Context): Geolocation;
16
16
 
@@ -1,16 +1,16 @@
1
1
  import { Context } from 'hono';
2
2
 
3
3
  type Geolocation = {
4
- ip_address: string | null;
5
- city: string | null;
6
- country: string | null;
7
- continent: string | null;
8
- longitude: number | null;
9
- latitude: number | null;
10
- region: string | null;
11
- metro_code: string | null;
12
- postal_code: string | null;
13
- time_zone: string | null;
4
+ ip_address?: string;
5
+ city?: string;
6
+ country?: string;
7
+ continent?: string;
8
+ longitude?: number;
9
+ latitude?: number;
10
+ region?: string;
11
+ metro_code?: string;
12
+ postal_code?: string;
13
+ time_zone?: string;
14
14
  };
15
15
  declare function geolocation(c: Context): Geolocation;
16
16
 
@@ -3,44 +3,44 @@ import { getRuntimeKey } from "hono/adapter";
3
3
  import { extractIpAddress } from "../utils/ip.mjs";
4
4
  function getGeolocationFromCloudflareWorker(c) {
5
5
  return {
6
- ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip") ?? null,
7
- city: c.req.header("cf-ipcity") ?? null,
8
- country: c.req.header("cf-ipcountry") ?? null,
9
- continent: c.req.header("cf-ipcontinent") ?? null,
10
- longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : null,
11
- latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : null,
12
- region: c.req.header("cf-region-code") ?? null,
13
- metro_code: c.req.header("cf-metro-code") ?? null,
14
- postal_code: c.req.header("cf-postal-code") ?? null,
15
- time_zone: c.req.header("cf-timezone") ?? null
6
+ ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip"),
7
+ city: c.req.header("cf-ipcity"),
8
+ country: c.req.header("cf-ipcountry"),
9
+ continent: c.req.header("cf-ipcontinent"),
10
+ longitude: c.req.header("cf-iplongitude") ? Number(c.req.header("cf-iplongitude")) : void 0,
11
+ latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) : void 0,
12
+ region: c.req.header("cf-region-code"),
13
+ metro_code: c.req.header("cf-metro-code"),
14
+ postal_code: c.req.header("cf-postal-code"),
15
+ time_zone: c.req.header("cf-timezone")
16
16
  };
17
17
  }
18
18
  function getGeolocationFromVercel(c) {
19
19
  return {
20
- ip_address: c.req.header("x-real-ip") ?? null,
21
- city: c.req.header("x-vercel-ip-city") ?? null,
22
- country: c.req.header("x-vercel-ip-country") ?? null,
23
- continent: c.req.header("x-vercel-ip-continent") ?? null,
24
- longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : null,
25
- latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : null,
26
- region: c.req.header("x-vercel-ip-country-region") ?? null,
27
- metro_code: null,
28
- postal_code: c.req.header("x-vercel-ip-postal-code") ?? null,
29
- time_zone: null
20
+ ip_address: c.req.header("x-real-ip"),
21
+ city: c.req.header("x-vercel-ip-city"),
22
+ country: c.req.header("x-vercel-ip-country"),
23
+ continent: c.req.header("x-vercel-ip-continent"),
24
+ longitude: c.req.header("x-vercel-ip-longitude") ? Number(c.req.header("x-vercel-ip-longitude")) : void 0,
25
+ latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) : void 0,
26
+ region: c.req.header("x-vercel-ip-country-region"),
27
+ metro_code: void 0,
28
+ postal_code: c.req.header("x-vercel-ip-postal-code"),
29
+ time_zone: void 0
30
30
  };
31
31
  }
32
32
  function getGeolocationFromCloudfront(c) {
33
33
  return {
34
- ip_address: extractIpAddress(c.req.header("CloudFront-Viewer-Address")),
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
- time_zone: c.req.header("CloudFront-Viewer-Time-Zone") ?? null
34
+ ip_address: extractIpAddress(c.req.header("CloudFront-Viewer-Address")) ?? void 0,
35
+ city: c.req.header("CloudFront-Viewer-City"),
36
+ country: c.req.header("CloudFront-Viewer-Country"),
37
+ continent: void 0,
38
+ longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) : void 0,
39
+ latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) : void 0,
40
+ region: c.req.header("CloudFront-Viewer-Country-Region"),
41
+ metro_code: c.req.header("CloudFront-Viewer-Metro-Code"),
42
+ postal_code: c.req.header("CloudFront-Viewer-Postal-Code"),
43
+ time_zone: c.req.header("CloudFront-Viewer-Time-Zone")
44
44
  };
45
45
  }
46
46
  function geolocation(c) {
@@ -1 +1 @@
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\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nfunction getGeolocationFromCloudflareWorker(c: Context): Geolocation {\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 */\nfunction getGeolocationFromVercel(c: Context): Geolocation {\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/** ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nfunction getGeolocationFromCloudfront(c: Context): Geolocation {\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\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflareWorker(c);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c);\n return getGeolocationFromCloudfront(c);\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AAiBjC,SAAS,mCAAmC,GAAyB;AACnE,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB,KAAK;AAAA,IAClF,MAAM,EAAE,IAAI,OAAO,WAAW,KAAK;AAAA,IACnC,SAAS,EAAE,IAAI,OAAO,cAAc,KAAK;AAAA,IACzC,WAAW,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,IAC7C,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,IACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,IAClF,QAAQ,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,IAC1C,YAAY,EAAE,IAAI,OAAO,eAAe,KAAK;AAAA,IAC7C,aAAa,EAAE,IAAI,OAAO,gBAAgB,KAAK;AAAA,IAC/C,WAAW,EAAE,IAAI,OAAO,aAAa,KAAK;AAAA,EAC5C;AACF;AAGA,SAAS,yBAAyB,GAAyB;AACzD,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,WAAW,KAAK;AAAA,IACzC,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,EAAE,IAAI,OAAO,4BAA4B,KAAK;AAAA,IACtD,YAAY;AAAA,IACZ,aAAa,EAAE,IAAI,OAAO,yBAAyB,KAAK;AAAA,IACxD,WAAW;AAAA,EACb;AACF;AAGA,SAAS,6BAA6B,GAAyB;AAC7D,SAAO;AAAA,IACL,YAAY,iBAAiB,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;AAEO,SAAS,YAAY,GAAyB;AACnD,MAAI,cAAc,MAAM,UAAW,QAAO,mCAAmC,CAAC;AAC9E,MAAI,EAAE,IAAI,OAAO,aAAa,EAAG,QAAO,yBAAyB,CAAC;AAClE,SAAO,6BAA6B,CAAC;AACvC;","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;\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\n/** reference: https://developers.cloudflare.com/rules/transform/managed-transforms/reference/#add-visitor-location-headers */\nfunction getGeolocationFromCloudflareWorker(c: Context): Geolocation {\n return {\n ip_address: c.req.header('true-client-ip') ?? c.req.header('cf-connecting-ip'),\n city: c.req.header('cf-ipcity'),\n country: c.req.header('cf-ipcountry'),\n continent: c.req.header('cf-ipcontinent'),\n longitude: c.req.header('cf-iplongitude') ? Number(c.req.header('cf-iplongitude')) : undefined,\n latitude: c.req.header('cf-iplatitude') ? Number(c.req.header('cf-iplatitude')) : undefined,\n region: c.req.header('cf-region-code'),\n metro_code: c.req.header('cf-metro-code'),\n postal_code: c.req.header('cf-postal-code'),\n time_zone: c.req.header('cf-timezone'),\n };\n}\n\n/** https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts */\nfunction getGeolocationFromVercel(c: Context): Geolocation {\n return {\n ip_address: c.req.header('x-real-ip'),\n city: c.req.header('x-vercel-ip-city'),\n country: c.req.header('x-vercel-ip-country'),\n continent: c.req.header('x-vercel-ip-continent'),\n longitude: c.req.header('x-vercel-ip-longitude')\n ? Number(c.req.header('x-vercel-ip-longitude'))\n : undefined,\n latitude: c.req.header('x-vercel-ip-latitude')\n ? Number(c.req.header('x-vercel-ip-latitude'))\n : undefined,\n region: c.req.header('x-vercel-ip-country-region'),\n metro_code: undefined,\n postal_code: c.req.header('x-vercel-ip-postal-code'),\n time_zone: undefined,\n };\n}\n\n/** ref: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html#cloudfront-headers-viewer-location */\nfunction getGeolocationFromCloudfront(c: Context): Geolocation {\n return {\n ip_address: extractIpAddress(c.req.header('CloudFront-Viewer-Address')) ?? undefined,\n city: c.req.header('CloudFront-Viewer-City'),\n country: c.req.header('CloudFront-Viewer-Country'),\n continent: undefined,\n longitude: c.req.header('CloudFront-Viewer-Longitude')\n ? Number(c.req.header('CloudFront-Viewer-Longitude'))\n : undefined,\n latitude: c.req.header('CloudFront-Viewer-Latitude')\n ? Number(c.req.header('CloudFront-Viewer-Latitude'))\n : undefined,\n region: c.req.header('CloudFront-Viewer-Country-Region'),\n metro_code: c.req.header('CloudFront-Viewer-Metro-Code'),\n postal_code: c.req.header('CloudFront-Viewer-Postal-Code'),\n time_zone: c.req.header('CloudFront-Viewer-Time-Zone'),\n };\n}\n\nexport function geolocation(c: Context): Geolocation {\n if (getRuntimeKey() === 'workerd') return getGeolocationFromCloudflareWorker(c);\n if (c.req.header('x-vercel-id')) return getGeolocationFromVercel(c);\n return getGeolocationFromCloudfront(c);\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAC9B,SAAS,wBAAwB;AAiBjC,SAAS,mCAAmC,GAAyB;AACnE,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,gBAAgB,KAAK,EAAE,IAAI,OAAO,kBAAkB;AAAA,IAC7E,MAAM,EAAE,IAAI,OAAO,WAAW;AAAA,IAC9B,SAAS,EAAE,IAAI,OAAO,cAAc;AAAA,IACpC,WAAW,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACxC,WAAW,EAAE,IAAI,OAAO,gBAAgB,IAAI,OAAO,EAAE,IAAI,OAAO,gBAAgB,CAAC,IAAI;AAAA,IACrF,UAAU,EAAE,IAAI,OAAO,eAAe,IAAI,OAAO,EAAE,IAAI,OAAO,eAAe,CAAC,IAAI;AAAA,IAClF,QAAQ,EAAE,IAAI,OAAO,gBAAgB;AAAA,IACrC,YAAY,EAAE,IAAI,OAAO,eAAe;AAAA,IACxC,aAAa,EAAE,IAAI,OAAO,gBAAgB;AAAA,IAC1C,WAAW,EAAE,IAAI,OAAO,aAAa;AAAA,EACvC;AACF;AAGA,SAAS,yBAAyB,GAAyB;AACzD,SAAO;AAAA,IACL,YAAY,EA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;AAClE,SAAO,6BAA6B,CAAC;AACvC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {