@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")
|
|
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")) :
|
|
35
|
-
latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) :
|
|
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")
|
|
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")
|
|
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")) :
|
|
49
|
-
latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) :
|
|
50
|
-
region: c.req.header("x-vercel-ip-country-region")
|
|
51
|
-
metro_code:
|
|
52
|
-
postal_code: c.req.header("x-vercel-ip-postal-code")
|
|
53
|
-
time_zone:
|
|
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")
|
|
60
|
-
country: c.req.header("CloudFront-Viewer-Country")
|
|
61
|
-
continent:
|
|
62
|
-
longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) :
|
|
63
|
-
latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) :
|
|
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")
|
|
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
|
|
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,IAA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|
-
ip_address
|
|
5
|
-
city
|
|
6
|
-
country
|
|
7
|
-
continent
|
|
8
|
-
longitude
|
|
9
|
-
latitude
|
|
10
|
-
region
|
|
11
|
-
metro_code
|
|
12
|
-
postal_code
|
|
13
|
-
time_zone
|
|
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
|
|
5
|
-
city
|
|
6
|
-
country
|
|
7
|
-
continent
|
|
8
|
-
longitude
|
|
9
|
-
latitude
|
|
10
|
-
region
|
|
11
|
-
metro_code
|
|
12
|
-
postal_code
|
|
13
|
-
time_zone
|
|
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")
|
|
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")) :
|
|
11
|
-
latitude: c.req.header("cf-iplatitude") ? Number(c.req.header("cf-iplatitude")) :
|
|
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")
|
|
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")
|
|
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")) :
|
|
25
|
-
latitude: c.req.header("x-vercel-ip-latitude") ? Number(c.req.header("x-vercel-ip-latitude")) :
|
|
26
|
-
region: c.req.header("x-vercel-ip-country-region")
|
|
27
|
-
metro_code:
|
|
28
|
-
postal_code: c.req.header("x-vercel-ip-postal-code")
|
|
29
|
-
time_zone:
|
|
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")
|
|
36
|
-
country: c.req.header("CloudFront-Viewer-Country")
|
|
37
|
-
continent:
|
|
38
|
-
longitude: c.req.header("CloudFront-Viewer-Longitude") ? Number(c.req.header("CloudFront-Viewer-Longitude")) :
|
|
39
|
-
latitude: c.req.header("CloudFront-Viewer-Latitude") ? Number(c.req.header("CloudFront-Viewer-Latitude")) :
|
|
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")
|
|
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
|
|
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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