@shware/http 0.2.13 → 0.2.15

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.
@@ -28,7 +28,7 @@ var runtime = (0, import_adapter.getRuntimeKey)();
28
28
  function geolocation(c) {
29
29
  if (runtime === "workerd") {
30
30
  return {
31
- ip: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip") ?? null,
31
+ ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip") ?? null,
32
32
  city: c.req.header("cf-ipcity") ?? null,
33
33
  country: c.req.header("cf-ipcountry") ?? null,
34
34
  continent: c.req.header("cf-ipcontinent") ?? null,
@@ -37,12 +37,12 @@ function geolocation(c) {
37
37
  region: c.req.header("cf-region-code") ?? null,
38
38
  metro_code: c.req.header("cf-metro-code") ?? null,
39
39
  postal_code: c.req.header("cf-postal-code") ?? null,
40
- timezone: c.req.header("cf-timezone") ?? null
40
+ time_zone: c.req.header("cf-timezone") ?? null
41
41
  };
42
42
  }
43
43
  if (c.req.header("x-vercel-id")) {
44
44
  return {
45
- ip: c.req.header("x-real-ip") ?? null,
45
+ ip_address: c.req.header("x-real-ip") ?? null,
46
46
  city: c.req.header("x-vercel-ip-city") ?? null,
47
47
  country: c.req.header("x-vercel-ip-country") ?? null,
48
48
  continent: c.req.header("x-vercel-ip-continent") ?? null,
@@ -51,11 +51,11 @@ function geolocation(c) {
51
51
  region: c.req.header("x-vercel-ip-country-region") ?? null,
52
52
  metro_code: null,
53
53
  postal_code: c.req.header("x-vercel-ip-postal-code") ?? null,
54
- timezone: null
54
+ time_zone: null
55
55
  };
56
56
  }
57
57
  return {
58
- ip: c.req.header("CloudFront-Viewer-Address") ?? null,
58
+ ip_address: c.req.header("CloudFront-Viewer-Address")?.split(":").at(0) ?? null,
59
59
  city: c.req.header("CloudFront-Viewer-City") ?? null,
60
60
  country: c.req.header("CloudFront-Viewer-Country") ?? null,
61
61
  continent: null,
@@ -64,7 +64,7 @@ function geolocation(c) {
64
64
  region: c.req.header("CloudFront-Viewer-Country-Region") ?? null,
65
65
  metro_code: c.req.header("CloudFront-Viewer-Metro-Code") ?? null,
66
66
  postal_code: c.req.header("CloudFront-Viewer-Postal-Code") ?? null,
67
- timezone: c.req.header("CloudFront-Viewer-Time-Zone") ?? null
67
+ time_zone: c.req.header("CloudFront-Viewer-Time-Zone") ?? null
68
68
  };
69
69
  }
70
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; // 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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I,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":[]}
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,OAAO,WAAW,KAAK;AAAA,MACnC,SAAS,EAAE,IAAI,OAAO,cAAc,KAAK;A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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,7 +1,7 @@
1
1
  import { Context } from 'hono';
2
2
 
3
3
  type Geolocation = {
4
- ip: string | null;
4
+ ip_address: string | null;
5
5
  city: string | null;
6
6
  country: string | null;
7
7
  continent: string | null;
@@ -10,7 +10,7 @@ type Geolocation = {
10
10
  region: string | null;
11
11
  metro_code: string | null;
12
12
  postal_code: string | null;
13
- timezone: string | null;
13
+ time_zone: string | null;
14
14
  };
15
15
  declare function geolocation(c: Context): Geolocation | null;
16
16
 
@@ -1,7 +1,7 @@
1
1
  import { Context } from 'hono';
2
2
 
3
3
  type Geolocation = {
4
- ip: string | null;
4
+ ip_address: string | null;
5
5
  city: string | null;
6
6
  country: string | null;
7
7
  continent: string | null;
@@ -10,7 +10,7 @@ type Geolocation = {
10
10
  region: string | null;
11
11
  metro_code: string | null;
12
12
  postal_code: string | null;
13
- timezone: string | null;
13
+ time_zone: string | null;
14
14
  };
15
15
  declare function geolocation(c: Context): Geolocation | null;
16
16
 
@@ -4,7 +4,7 @@ var runtime = getRuntimeKey();
4
4
  function geolocation(c) {
5
5
  if (runtime === "workerd") {
6
6
  return {
7
- ip: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip") ?? null,
7
+ ip_address: c.req.header("true-client-ip") ?? c.req.header("cf-connecting-ip") ?? null,
8
8
  city: c.req.header("cf-ipcity") ?? null,
9
9
  country: c.req.header("cf-ipcountry") ?? null,
10
10
  continent: c.req.header("cf-ipcontinent") ?? null,
@@ -13,12 +13,12 @@ function geolocation(c) {
13
13
  region: c.req.header("cf-region-code") ?? null,
14
14
  metro_code: c.req.header("cf-metro-code") ?? null,
15
15
  postal_code: c.req.header("cf-postal-code") ?? null,
16
- timezone: c.req.header("cf-timezone") ?? null
16
+ time_zone: c.req.header("cf-timezone") ?? null
17
17
  };
18
18
  }
19
19
  if (c.req.header("x-vercel-id")) {
20
20
  return {
21
- ip: c.req.header("x-real-ip") ?? null,
21
+ ip_address: c.req.header("x-real-ip") ?? null,
22
22
  city: c.req.header("x-vercel-ip-city") ?? null,
23
23
  country: c.req.header("x-vercel-ip-country") ?? null,
24
24
  continent: c.req.header("x-vercel-ip-continent") ?? null,
@@ -27,11 +27,11 @@ function geolocation(c) {
27
27
  region: c.req.header("x-vercel-ip-country-region") ?? null,
28
28
  metro_code: null,
29
29
  postal_code: c.req.header("x-vercel-ip-postal-code") ?? null,
30
- timezone: null
30
+ time_zone: null
31
31
  };
32
32
  }
33
33
  return {
34
- ip: c.req.header("CloudFront-Viewer-Address") ?? null,
34
+ ip_address: c.req.header("CloudFront-Viewer-Address")?.split(":").at(0) ?? null,
35
35
  city: c.req.header("CloudFront-Viewer-City") ?? null,
36
36
  country: c.req.header("CloudFront-Viewer-Country") ?? null,
37
37
  continent: null,
@@ -40,7 +40,7 @@ function geolocation(c) {
40
40
  region: c.req.header("CloudFront-Viewer-Country-Region") ?? null,
41
41
  metro_code: c.req.header("CloudFront-Viewer-Metro-Code") ?? null,
42
42
  postal_code: c.req.header("CloudFront-Viewer-Postal-Code") ?? null,
43
- timezone: c.req.header("CloudFront-Viewer-Time-Zone") ?? null
43
+ time_zone: c.req.header("CloudFront-Viewer-Time-Zone") ?? null
44
44
  };
45
45
  }
46
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; // 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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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_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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B,KAAK;AAAA,IAC9D,WAAW,EAAE,IAAI,OAAO,6BAA6B,KAAK;AAAA,EAC5D;AACF;","names":[]}
@@ -33,7 +33,7 @@ function errorHandler(error, c) {
33
33
  error.body?.error?.details?.push(...details.list);
34
34
  return c.json(error.body, error.status);
35
35
  }
36
- console.log("Unknown error:", error);
36
+ console.error(error);
37
37
  return import_status.Status.internal("Unknown error").response(details);
38
38
  }
39
39
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.url}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n console.log('Unknown error:', error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAAoC;AACpC,oBAAwB;AAOjB,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,GAAG;AACjD,QAAM,UAAU,sBAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,2BAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,UAAQ,IAAI,kBAAkB,KAAK;AACnC,SAAO,qBAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.url}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n console.error(error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAAoC;AACpC,oBAAwB;AAOjB,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,GAAG;AACjD,QAAM,UAAU,sBAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,2BAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,UAAQ,MAAM,KAAK;AACnB,SAAO,qBAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
@@ -9,7 +9,7 @@ function errorHandler(error, c) {
9
9
  error.body?.error?.details?.push(...details.list);
10
10
  return c.json(error.body, error.status);
11
11
  }
12
- console.log("Unknown error:", error);
12
+ console.error(error);
13
13
  return Status.internal("Unknown error").response(details);
14
14
  }
15
15
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.url}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n console.log('Unknown error:', error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";AAIA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,eAAe;AAOjB,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,GAAG;AACjD,QAAM,UAAU,QAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,aAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,UAAQ,IAAI,kBAAkB,KAAK;AACnC,SAAO,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
1
+ {"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.url}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n\n if (error instanceof StatusError) {\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n console.error(error);\n return Status.internal('Unknown error').response(details);\n}\n"],"mappings":";AAIA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,eAAe;AAOjB,SAAS,aACd,OACA,GAC8B;AAC9B,QAAM,YAAY,EAAE,IAAI,WAAW;AACnC,QAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,GAAG;AACjD,QAAM,UAAU,QAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AAEpE,MAAI,iBAAiB,aAAa;AAChC,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,UAAQ,MAAM,KAAK;AACnB,SAAO,OAAO,SAAS,eAAe,EAAE,SAAS,OAAO;AAC1D;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shware/http",
3
- "version": "0.2.13",
3
+ "version": "0.2.15",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {