@vercel/functions 1.4.1 → 1.4.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @vercel/functions
2
2
 
3
+ ## 1.4.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [functions] decode city name ([#12234](https://github.com/vercel/vercel/pull/12234))
8
+
3
9
  ## 1.4.1
4
10
 
5
11
  ### Patch Changes
@@ -29,7 +29,7 @@ import { geolocation } from '@vercel/functions';
29
29
 
30
30
  export function GET(request) {
31
31
  const details = geolocation(request);
32
- return Response.json(payload);
32
+ return Response.json(details);
33
33
  }
34
34
  ```
35
35
 
@@ -59,7 +59,7 @@ The location information of the request, in this way:
59
59
 
60
60
  #### Defined in
61
61
 
62
- [packages/functions/src/headers.ts:158](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L158)
62
+ [packages/functions/src/headers.ts:166](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L166)
63
63
 
64
64
  ---
65
65
 
@@ -144,7 +144,7 @@ The IP address of the request.
144
144
 
145
145
  #### Defined in
146
146
 
147
- [packages/functions/src/headers.ts:111](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L111)
147
+ [packages/functions/src/headers.ts:119](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L119)
148
148
 
149
149
  ---
150
150
 
package/headers.d.ts CHANGED
@@ -105,7 +105,7 @@ export declare function ipAddress(request: Request): string | undefined;
105
105
  *
106
106
  * export function GET(request) {
107
107
  * const details = geolocation(request);
108
- * return Response.json(payload);
108
+ * return Response.json(details);
109
109
  * }
110
110
  * ```
111
111
  */
package/headers.js CHANGED
@@ -41,6 +41,10 @@ const EMOJI_FLAG_UNICODE_STARTING_POSITION = 127397;
41
41
  function getHeader(request, key) {
42
42
  return request.headers.get(key) ?? void 0;
43
43
  }
44
+ function getHeaderWithDecode(request, key) {
45
+ const header = getHeader(request, key);
46
+ return header ? decodeURIComponent(header) : void 0;
47
+ }
44
48
  function getFlag(countryCode) {
45
49
  const regex = new RegExp("^[A-Z]{2}$").test(countryCode);
46
50
  if (!countryCode || !regex)
@@ -60,7 +64,8 @@ function getRegionFromRequestId(requestId) {
60
64
  }
61
65
  function geolocation(request) {
62
66
  return {
63
- city: getHeader(request, CITY_HEADER_NAME),
67
+ // city name may be encoded to support multi-byte characters
68
+ city: getHeaderWithDecode(request, CITY_HEADER_NAME),
64
69
  country: getHeader(request, COUNTRY_HEADER_NAME),
65
70
  flag: getFlag(getHeader(request, COUNTRY_HEADER_NAME)),
66
71
  countryRegion: getHeader(request, REGION_HEADER_NAME),
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  ],
10
10
  "main": "./index.js",
11
11
  "types": "./index.d.ts",
12
- "version": "1.4.1",
12
+ "version": "1.4.2",
13
13
  "repository": {
14
14
  "directory": "packages/functions",
15
15
  "type": "git",