@vercel/functions 1.5.0 β 1.5.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 +12 -0
- package/README.md +3 -58
- package/docs/interfaces/index.Geo.md +20 -7
- package/docs/interfaces/index.Request.md +1 -1
- package/docs/modules/index.md +10 -9
- package/headers.d.ts +8 -1
- package/headers.js +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @vercel/functions
|
|
2
2
|
|
|
3
|
+
## 1.5.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [vercel/functions] add geolocation.postalCode ([#12753](https://github.com/vercel/vercel/pull/12753))
|
|
8
|
+
|
|
9
|
+
## 1.5.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [@vercel/functions] update headers doc ([#12649](https://github.com/vercel/vercel/pull/12649))
|
|
14
|
+
|
|
3
15
|
## 1.5.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,60 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
<a href="https://vercel.com">
|
|
3
|
-
<img src="https://assets.vercel.com/image/upload/v1588805858/repositories/vercel/logo.png" height="96">
|
|
4
|
-
<h3 align="center">Vercel</h3>
|
|
5
|
-
</a>
|
|
6
|
-
<p align="center">Develop. Preview. Ship.</p>
|
|
7
|
-
</p>
|
|
1
|
+
# `@vercel/functions`
|
|
8
2
|
|
|
9
|
-
|
|
3
|
+
Runtime functions to be used with your Vercel Functions.
|
|
10
4
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### AWS S3 Example
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import * as s3 from '@aws-sdk/client-s3';
|
|
17
|
-
import { awsCredentialsProvider } from '@vercel/functions/oidc';
|
|
18
|
-
|
|
19
|
-
const s3Client = new s3.S3Client({
|
|
20
|
-
credentials: awsCredentialsProvider({
|
|
21
|
-
roleArn: process.env.AWS_ROLE_ARN,
|
|
22
|
-
}),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export const GET = () => {
|
|
26
|
-
const result = await s3Client.send(
|
|
27
|
-
new s3.ListObjectsV2Command({
|
|
28
|
-
Bucket: process.env.BUCKET_NAME,
|
|
29
|
-
})
|
|
30
|
-
);
|
|
31
|
-
return Response.json({ objects: result.Contents });
|
|
32
|
-
};
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Azure CosmosDB Example
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
import { ClientAssertionCredential } from '@azure/identity';
|
|
39
|
-
import { CosmosClient } from '@azure/cosmos';
|
|
40
|
-
import { getVercelOidcToken } from '@vercel/functions/oidc';
|
|
41
|
-
|
|
42
|
-
const credentialsProvider = new ClientAssertionCredential(
|
|
43
|
-
process.env.AZURE_TENANT_ID,
|
|
44
|
-
process.env.AZURE_CLIENT_ID,
|
|
45
|
-
getVercelOidcToken
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const cosmosClient = new CosmosClient({
|
|
49
|
-
endpoint: process.env.COSMOS_DB_ENDPOINT,
|
|
50
|
-
aadCredentials: credentialsProvider,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
export const GET = () => {
|
|
54
|
-
const container = cosmosClient
|
|
55
|
-
.database(process.env.COSMOS_DB_NAME)
|
|
56
|
-
.container(process.env.COSMOS_DB_CONTAINER);
|
|
57
|
-
const items = await container.items.query('SELECT * FROM f').fetchAll();
|
|
58
|
-
return Response.json({ items: items.resources });
|
|
59
|
-
};
|
|
60
|
-
```
|
|
5
|
+
Please [follow the documentation](https://vercel.com/docs/functions/vercel-functions-package) for examples and usage.
|
|
@@ -14,6 +14,7 @@ The location information of a given request.
|
|
|
14
14
|
- [flag](index.Geo.md#flag)
|
|
15
15
|
- [latitude](index.Geo.md#latitude)
|
|
16
16
|
- [longitude](index.Geo.md#longitude)
|
|
17
|
+
- [postalCode](index.Geo.md#postalcode)
|
|
17
18
|
- [region](index.Geo.md#region)
|
|
18
19
|
|
|
19
20
|
## Properties
|
|
@@ -26,7 +27,7 @@ The city that the request originated from.
|
|
|
26
27
|
|
|
27
28
|
#### Defined in
|
|
28
29
|
|
|
29
|
-
[packages/functions/src/headers.ts:
|
|
30
|
+
[packages/functions/src/headers.ts:59](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L59)
|
|
30
31
|
|
|
31
32
|
---
|
|
32
33
|
|
|
@@ -38,7 +39,7 @@ The country that the request originated from.
|
|
|
38
39
|
|
|
39
40
|
#### Defined in
|
|
40
41
|
|
|
41
|
-
[packages/functions/src/headers.ts:
|
|
42
|
+
[packages/functions/src/headers.ts:62](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L62)
|
|
42
43
|
|
|
43
44
|
---
|
|
44
45
|
|
|
@@ -51,7 +52,7 @@ See [docs](https://vercel.com/docs/concepts/edge-network/headers#x-vercel-ip-cou
|
|
|
51
52
|
|
|
52
53
|
#### Defined in
|
|
53
54
|
|
|
54
|
-
[packages/functions/src/headers.ts:
|
|
55
|
+
[packages/functions/src/headers.ts:73](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L73)
|
|
55
56
|
|
|
56
57
|
---
|
|
57
58
|
|
|
@@ -63,7 +64,7 @@ The flag emoji for the country the request originated from.
|
|
|
63
64
|
|
|
64
65
|
#### Defined in
|
|
65
66
|
|
|
66
|
-
[packages/functions/src/headers.ts:
|
|
67
|
+
[packages/functions/src/headers.ts:65](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L65)
|
|
67
68
|
|
|
68
69
|
---
|
|
69
70
|
|
|
@@ -75,7 +76,7 @@ The latitude of the client.
|
|
|
75
76
|
|
|
76
77
|
#### Defined in
|
|
77
78
|
|
|
78
|
-
[packages/functions/src/headers.ts:
|
|
79
|
+
[packages/functions/src/headers.ts:76](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L76)
|
|
79
80
|
|
|
80
81
|
---
|
|
81
82
|
|
|
@@ -87,7 +88,19 @@ The longitude of the client.
|
|
|
87
88
|
|
|
88
89
|
#### Defined in
|
|
89
90
|
|
|
90
|
-
[packages/functions/src/headers.ts:
|
|
91
|
+
[packages/functions/src/headers.ts:79](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L79)
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
### postalCode
|
|
96
|
+
|
|
97
|
+
β’ `Optional` **postalCode**: `string`
|
|
98
|
+
|
|
99
|
+
The postal code of the client
|
|
100
|
+
|
|
101
|
+
#### Defined in
|
|
102
|
+
|
|
103
|
+
[packages/functions/src/headers.ts:82](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L82)
|
|
91
104
|
|
|
92
105
|
---
|
|
93
106
|
|
|
@@ -99,4 +112,4 @@ The [Vercel Edge Network region](https://vercel.com/docs/concepts/edge-network/r
|
|
|
99
112
|
|
|
100
113
|
#### Defined in
|
|
101
114
|
|
|
102
|
-
[packages/functions/src/headers.ts:
|
|
115
|
+
[packages/functions/src/headers.ts:68](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L68)
|
|
@@ -20,4 +20,4 @@ Represents the headers of a request.
|
|
|
20
20
|
|
|
21
21
|
#### Defined in
|
|
22
22
|
|
|
23
|
-
[packages/functions/src/headers.ts:
|
|
23
|
+
[packages/functions/src/headers.ts:52](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L52)
|
package/docs/modules/index.md
CHANGED
|
@@ -47,19 +47,20 @@ The location information of the request, in this way:
|
|
|
47
47
|
|
|
48
48
|
```json
|
|
49
49
|
{
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
"city": "New York",
|
|
51
|
+
"country": "US",
|
|
52
|
+
"flag": "πΊπΈ",
|
|
53
|
+
"countryRegion": "NY",
|
|
54
|
+
"region": "iad1",
|
|
55
|
+
"latitude": "40.7128",
|
|
56
|
+
"longitude": "-74.0060"
|
|
57
|
+
"postalCode": "10001"
|
|
57
58
|
}
|
|
58
59
|
```
|
|
59
60
|
|
|
60
61
|
#### Defined in
|
|
61
62
|
|
|
62
|
-
[packages/functions/src/headers.ts:
|
|
63
|
+
[packages/functions/src/headers.ts:180](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L180)
|
|
63
64
|
|
|
64
65
|
---
|
|
65
66
|
|
|
@@ -144,7 +145,7 @@ The IP address of the request.
|
|
|
144
145
|
|
|
145
146
|
#### Defined in
|
|
146
147
|
|
|
147
|
-
[packages/functions/src/headers.ts:
|
|
148
|
+
[packages/functions/src/headers.ts:131](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L131)
|
|
148
149
|
|
|
149
150
|
---
|
|
150
151
|
|
package/headers.d.ts
CHANGED
|
@@ -24,6 +24,10 @@ export declare const LONGITUDE_HEADER_NAME = "x-vercel-ip-longitude";
|
|
|
24
24
|
* See [docs](https://vercel.com/docs/concepts/edge-network/headers#x-vercel-ip-country-region).
|
|
25
25
|
*/
|
|
26
26
|
export declare const REGION_HEADER_NAME = "x-vercel-ip-country-region";
|
|
27
|
+
/**
|
|
28
|
+
* Postal code of the original client IP as calculated by Vercel Proxy.
|
|
29
|
+
*/
|
|
30
|
+
export declare const POSTAL_CODE_HEADER_NAME = "x-vercel-ip-postal-code";
|
|
27
31
|
/**
|
|
28
32
|
* The request ID for each request generated by Vercel Proxy.
|
|
29
33
|
*/
|
|
@@ -67,6 +71,8 @@ export interface Geo {
|
|
|
67
71
|
latitude?: string;
|
|
68
72
|
/** The longitude of the client. */
|
|
69
73
|
longitude?: string;
|
|
74
|
+
/** The postal code of the client */
|
|
75
|
+
postalCode?: string;
|
|
70
76
|
}
|
|
71
77
|
/**
|
|
72
78
|
* Returns the IP address of the request from the headers.
|
|
@@ -98,9 +104,10 @@ export declare function ipAddress(input: Request | Headers): string | undefined;
|
|
|
98
104
|
* "country": "US",
|
|
99
105
|
* "flag": "πΊπΈ",
|
|
100
106
|
* "countryRegion": "NY",
|
|
101
|
-
* "region": "
|
|
107
|
+
* "region": "iad1",
|
|
102
108
|
* "latitude": "40.7128",
|
|
103
109
|
* "longitude": "-74.0060"
|
|
110
|
+
* "postalCode": "10001"
|
|
104
111
|
* }
|
|
105
112
|
* ```
|
|
106
113
|
*
|
package/headers.js
CHANGED
|
@@ -24,6 +24,7 @@ __export(headers_exports, {
|
|
|
24
24
|
IP_HEADER_NAME: () => IP_HEADER_NAME,
|
|
25
25
|
LATITUDE_HEADER_NAME: () => LATITUDE_HEADER_NAME,
|
|
26
26
|
LONGITUDE_HEADER_NAME: () => LONGITUDE_HEADER_NAME,
|
|
27
|
+
POSTAL_CODE_HEADER_NAME: () => POSTAL_CODE_HEADER_NAME,
|
|
27
28
|
REGION_HEADER_NAME: () => REGION_HEADER_NAME,
|
|
28
29
|
REQUEST_ID_HEADER_NAME: () => REQUEST_ID_HEADER_NAME,
|
|
29
30
|
geolocation: () => geolocation,
|
|
@@ -36,6 +37,7 @@ const IP_HEADER_NAME = "x-real-ip";
|
|
|
36
37
|
const LATITUDE_HEADER_NAME = "x-vercel-ip-latitude";
|
|
37
38
|
const LONGITUDE_HEADER_NAME = "x-vercel-ip-longitude";
|
|
38
39
|
const REGION_HEADER_NAME = "x-vercel-ip-country-region";
|
|
40
|
+
const POSTAL_CODE_HEADER_NAME = "x-vercel-ip-postal-code";
|
|
39
41
|
const REQUEST_ID_HEADER_NAME = "x-vercel-id";
|
|
40
42
|
const EMOJI_FLAG_UNICODE_STARTING_POSITION = 127397;
|
|
41
43
|
function getHeader(headers, key) {
|
|
@@ -74,7 +76,8 @@ function geolocation(request) {
|
|
|
74
76
|
getHeader(request.headers, REQUEST_ID_HEADER_NAME)
|
|
75
77
|
),
|
|
76
78
|
latitude: getHeader(request.headers, LATITUDE_HEADER_NAME),
|
|
77
|
-
longitude: getHeader(request.headers, LONGITUDE_HEADER_NAME)
|
|
79
|
+
longitude: getHeader(request.headers, LONGITUDE_HEADER_NAME),
|
|
80
|
+
postalCode: getHeader(request.headers, POSTAL_CODE_HEADER_NAME)
|
|
78
81
|
};
|
|
79
82
|
}
|
|
80
83
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -85,6 +88,7 @@ function geolocation(request) {
|
|
|
85
88
|
IP_HEADER_NAME,
|
|
86
89
|
LATITUDE_HEADER_NAME,
|
|
87
90
|
LONGITUDE_HEADER_NAME,
|
|
91
|
+
POSTAL_CODE_HEADER_NAME,
|
|
88
92
|
REGION_HEADER_NAME,
|
|
89
93
|
REQUEST_ID_HEADER_NAME,
|
|
90
94
|
geolocation,
|