@shware/http 0.2.14 → 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
54
|
+
time_zone: null
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
return {
|
|
58
|
-
|
|
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
|
-
|
|
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
|
|
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,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A,MACxD,WAAW;AAAA,IACb;AAAA,EACF;AAIA,SAAO;AAAA,IACL,YAAY,EAAE,IAAI,OAAO,2BAA2B,GAAG,MAAM,GAAG,EAAE,GAAG,CAAC,KAAK;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,7 +1,7 @@
|
|
|
1
1
|
import { Context } from 'hono';
|
|
2
2
|
|
|
3
3
|
type Geolocation = {
|
|
4
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
+
time_zone: null
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
return {
|
|
34
|
-
|
|
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
|
-
|
|
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
|
|
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;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