@vercel/functions 1.4.0 → 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 +55 -0
- package/README.md +1 -1
- package/docs/README.md +8 -0
- package/docs/interfaces/index.Geo.md +102 -0
- package/docs/interfaces/index.Request.md +28 -0
- package/docs/interfaces/oidc.AwsCredentialsProviderInit.md +221 -0
- package/docs/modules/index.md +184 -0
- package/docs/modules/oidc.md +98 -0
- package/{dist/get-env.d.ts → get-env.d.ts} +5 -0
- package/{dist/headers.d.ts → headers.d.ts} +37 -7
- package/{dist/headers.js → headers.js} +6 -1
- package/{dist/oidc → oidc}/aws-credentials-provider.d.ts +1 -1
- package/{dist/oidc → oidc}/get-vercel-oidc-token.d.ts +3 -2
- package/package.json +6 -13
- package/{dist/wait-until.d.ts → wait-until.d.ts} +1 -1
- /package/{dist/get-context.d.ts → get-context.d.ts} +0 -0
- /package/{dist/get-context.js → get-context.js} +0 -0
- /package/{dist/get-env.js → get-env.js} +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/oidc → oidc}/aws-credentials-provider.js +0 -0
- /package/{dist/oidc → oidc}/get-vercel-oidc-token.js +0 -0
- /package/{dist/oidc → oidc}/index.d.ts +0 -0
- /package/{dist/oidc → oidc}/index.js +0 -0
- /package/{dist/wait-until.js → wait-until.js} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @vercel/functions
|
|
2
|
+
|
|
3
|
+
## 1.4.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [functions] decode city name ([#12234](https://github.com/vercel/vercel/pull/12234))
|
|
8
|
+
|
|
9
|
+
## 1.4.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Package files in the root folder ([#11982](https://github.com/vercel/vercel/pull/11982))
|
|
14
|
+
|
|
15
|
+
## 1.4.0
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- Added OIDC Token utility functions ([#11701](https://github.com/vercel/vercel/pull/11701))
|
|
20
|
+
|
|
21
|
+
## 1.3.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- [functions] add `getEnv` method. ([#11783](https://github.com/vercel/vercel/pull/11783))
|
|
26
|
+
|
|
27
|
+
## 1.2.0
|
|
28
|
+
|
|
29
|
+
### Minor Changes
|
|
30
|
+
|
|
31
|
+
- Add `geolocation` & `ipAdress` methods. ([#11802](https://github.com/vercel/vercel/pull/11802))
|
|
32
|
+
|
|
33
|
+
## 1.1.0
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- Rewrite `@vercel/functions` to TypeScript ([#11791](https://github.com/vercel/vercel/pull/11791))
|
|
38
|
+
|
|
39
|
+
## 1.0.2
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- Convert package to CommonJS ([#11569](https://github.com/vercel/vercel/pull/11569))
|
|
44
|
+
|
|
45
|
+
## 1.0.1
|
|
46
|
+
|
|
47
|
+
### Patch Changes
|
|
48
|
+
|
|
49
|
+
- Don't throw error if context is missing ([`0817527f9`](https://github.com/vercel/vercel/commit/0817527f9e9d0d5fceb73f21e695089349a96d3e))
|
|
50
|
+
|
|
51
|
+
## 1.0.0
|
|
52
|
+
|
|
53
|
+
### Major Changes
|
|
54
|
+
|
|
55
|
+
- Initial release ([#11553](https://github.com/vercel/vercel/pull/11553))
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<p align="center">Develop. Preview. Ship.</p>
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
|
-
[
|
|
9
|
+
[Join the Vercel Community](https://vercel.community/)
|
|
10
10
|
|
|
11
11
|
## OIDC Support Functions
|
|
12
12
|
|
package/docs/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Interface: Geo
|
|
2
|
+
|
|
3
|
+
[index](../modules/index.md).Geo
|
|
4
|
+
|
|
5
|
+
The location information of a given request.
|
|
6
|
+
|
|
7
|
+
## Table of contents
|
|
8
|
+
|
|
9
|
+
### Properties
|
|
10
|
+
|
|
11
|
+
- [city](index.Geo.md#city)
|
|
12
|
+
- [country](index.Geo.md#country)
|
|
13
|
+
- [countryRegion](index.Geo.md#countryregion)
|
|
14
|
+
- [flag](index.Geo.md#flag)
|
|
15
|
+
- [latitude](index.Geo.md#latitude)
|
|
16
|
+
- [longitude](index.Geo.md#longitude)
|
|
17
|
+
- [region](index.Geo.md#region)
|
|
18
|
+
|
|
19
|
+
## Properties
|
|
20
|
+
|
|
21
|
+
### city
|
|
22
|
+
|
|
23
|
+
• `Optional` **city**: `string`
|
|
24
|
+
|
|
25
|
+
The city that the request originated from.
|
|
26
|
+
|
|
27
|
+
#### Defined in
|
|
28
|
+
|
|
29
|
+
[packages/functions/src/headers.ts:50](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L50)
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
### country
|
|
34
|
+
|
|
35
|
+
• `Optional` **country**: `string`
|
|
36
|
+
|
|
37
|
+
The country that the request originated from.
|
|
38
|
+
|
|
39
|
+
#### Defined in
|
|
40
|
+
|
|
41
|
+
[packages/functions/src/headers.ts:53](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L53)
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
### countryRegion
|
|
46
|
+
|
|
47
|
+
• `Optional` **countryRegion**: `string`
|
|
48
|
+
|
|
49
|
+
The region part of the ISO 3166-2 code of the client IP.
|
|
50
|
+
See [docs](https://vercel.com/docs/concepts/edge-network/headers#x-vercel-ip-country-region).
|
|
51
|
+
|
|
52
|
+
#### Defined in
|
|
53
|
+
|
|
54
|
+
[packages/functions/src/headers.ts:64](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L64)
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
### flag
|
|
59
|
+
|
|
60
|
+
• `Optional` **flag**: `string`
|
|
61
|
+
|
|
62
|
+
The flag emoji for the country the request originated from.
|
|
63
|
+
|
|
64
|
+
#### Defined in
|
|
65
|
+
|
|
66
|
+
[packages/functions/src/headers.ts:56](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L56)
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
### latitude
|
|
71
|
+
|
|
72
|
+
• `Optional` **latitude**: `string`
|
|
73
|
+
|
|
74
|
+
The latitude of the client.
|
|
75
|
+
|
|
76
|
+
#### Defined in
|
|
77
|
+
|
|
78
|
+
[packages/functions/src/headers.ts:67](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L67)
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
### longitude
|
|
83
|
+
|
|
84
|
+
• `Optional` **longitude**: `string`
|
|
85
|
+
|
|
86
|
+
The longitude of the client.
|
|
87
|
+
|
|
88
|
+
#### Defined in
|
|
89
|
+
|
|
90
|
+
[packages/functions/src/headers.ts:70](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L70)
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### region
|
|
95
|
+
|
|
96
|
+
• `Optional` **region**: `string`
|
|
97
|
+
|
|
98
|
+
The [Vercel Edge Network region](https://vercel.com/docs/concepts/edge-network/regions) that received the request.
|
|
99
|
+
|
|
100
|
+
#### Defined in
|
|
101
|
+
|
|
102
|
+
[packages/functions/src/headers.ts:59](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L59)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Interface: Request
|
|
2
|
+
|
|
3
|
+
[index](../modules/index.md).Request
|
|
4
|
+
|
|
5
|
+
We define a new type so this function can be reused with
|
|
6
|
+
the global `Request`, `node-fetch` and other types.
|
|
7
|
+
|
|
8
|
+
## Table of contents
|
|
9
|
+
|
|
10
|
+
### Properties
|
|
11
|
+
|
|
12
|
+
- [headers](index.Request.md#headers)
|
|
13
|
+
|
|
14
|
+
## Properties
|
|
15
|
+
|
|
16
|
+
### headers
|
|
17
|
+
|
|
18
|
+
• **headers**: `Object`
|
|
19
|
+
|
|
20
|
+
#### Type declaration
|
|
21
|
+
|
|
22
|
+
| Name | Type |
|
|
23
|
+
| :---- | :--------------------------------------- |
|
|
24
|
+
| `get` | (`name`: `string`) => `null` \| `string` |
|
|
25
|
+
|
|
26
|
+
#### Defined in
|
|
27
|
+
|
|
28
|
+
[packages/functions/src/headers.ts:40](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L40)
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# Interface: AwsCredentialsProviderInit
|
|
2
|
+
|
|
3
|
+
[oidc](../modules/oidc.md).AwsCredentialsProviderInit
|
|
4
|
+
|
|
5
|
+
The init object for the `awsCredentialsProvider` function.
|
|
6
|
+
|
|
7
|
+
## Hierarchy
|
|
8
|
+
|
|
9
|
+
- [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)<`FromWebTokenInit`, `"webIdentityToken"`\>
|
|
10
|
+
|
|
11
|
+
↳ **`AwsCredentialsProviderInit`**
|
|
12
|
+
|
|
13
|
+
## Table of contents
|
|
14
|
+
|
|
15
|
+
### Properties
|
|
16
|
+
|
|
17
|
+
- [clientConfig](oidc.AwsCredentialsProviderInit.md#clientconfig)
|
|
18
|
+
- [clientPlugins](oidc.AwsCredentialsProviderInit.md#clientplugins)
|
|
19
|
+
- [durationSeconds](oidc.AwsCredentialsProviderInit.md#durationseconds)
|
|
20
|
+
- [logger](oidc.AwsCredentialsProviderInit.md#logger)
|
|
21
|
+
- [parentClientConfig](oidc.AwsCredentialsProviderInit.md#parentclientconfig)
|
|
22
|
+
- [policy](oidc.AwsCredentialsProviderInit.md#policy)
|
|
23
|
+
- [policyArns](oidc.AwsCredentialsProviderInit.md#policyarns)
|
|
24
|
+
- [providerId](oidc.AwsCredentialsProviderInit.md#providerid)
|
|
25
|
+
- [roleArn](oidc.AwsCredentialsProviderInit.md#rolearn)
|
|
26
|
+
- [roleAssumerWithWebIdentity](oidc.AwsCredentialsProviderInit.md#roleassumerwithwebidentity)
|
|
27
|
+
- [roleSessionName](oidc.AwsCredentialsProviderInit.md#rolesessionname)
|
|
28
|
+
|
|
29
|
+
## Properties
|
|
30
|
+
|
|
31
|
+
### clientConfig
|
|
32
|
+
|
|
33
|
+
• `Optional` **clientConfig**: `any`
|
|
34
|
+
|
|
35
|
+
Custom STS client configurations overriding the default ones.
|
|
36
|
+
|
|
37
|
+
#### Inherited from
|
|
38
|
+
|
|
39
|
+
Omit.clientConfig
|
|
40
|
+
|
|
41
|
+
#### Defined in
|
|
42
|
+
|
|
43
|
+
node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.609.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:135
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
### clientPlugins
|
|
48
|
+
|
|
49
|
+
• `Optional` **clientPlugins**: `Pluggable`<`any`, `any`\>[]
|
|
50
|
+
|
|
51
|
+
Custom STS client middleware plugin to modify the client default behavior.
|
|
52
|
+
|
|
53
|
+
#### Inherited from
|
|
54
|
+
|
|
55
|
+
Omit.clientPlugins
|
|
56
|
+
|
|
57
|
+
#### Defined in
|
|
58
|
+
|
|
59
|
+
node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.609.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:139
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### durationSeconds
|
|
64
|
+
|
|
65
|
+
• **durationSeconds**: `undefined` \| `number`
|
|
66
|
+
|
|
67
|
+
The duration, in seconds, of the role session. Defaults to 3600 seconds.
|
|
68
|
+
|
|
69
|
+
#### Inherited from
|
|
70
|
+
|
|
71
|
+
Omit.durationSeconds
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
### logger
|
|
76
|
+
|
|
77
|
+
• `Optional` **logger**: `Logger`
|
|
78
|
+
|
|
79
|
+
This logger is only used to provide information
|
|
80
|
+
on what credential providers were used during resolution.
|
|
81
|
+
|
|
82
|
+
It does not log credentials.
|
|
83
|
+
|
|
84
|
+
#### Inherited from
|
|
85
|
+
|
|
86
|
+
Omit.logger
|
|
87
|
+
|
|
88
|
+
#### Defined in
|
|
89
|
+
|
|
90
|
+
node_modules/.pnpm/@aws-sdk+types@3.609.0/node_modules/@aws-sdk/types/dist-types/credentials.d.ts:31
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### parentClientConfig
|
|
95
|
+
|
|
96
|
+
• `Optional` **parentClientConfig**: `Object`
|
|
97
|
+
|
|
98
|
+
Present if the credential provider was created by calling
|
|
99
|
+
the defaultCredentialProvider in a client's middleware, having
|
|
100
|
+
access to the client's config.
|
|
101
|
+
|
|
102
|
+
The region of that parent or outer client is important because
|
|
103
|
+
an inner client used by the credential provider may need
|
|
104
|
+
to match its default partition or region with that of
|
|
105
|
+
the outer client.
|
|
106
|
+
|
|
107
|
+
**`Deprecated`**
|
|
108
|
+
|
|
109
|
+
- not truly deprecated, marked as a warning to not use this.
|
|
110
|
+
|
|
111
|
+
#### Index signature
|
|
112
|
+
|
|
113
|
+
▪ [key: `string`]: `unknown`
|
|
114
|
+
|
|
115
|
+
#### Type declaration
|
|
116
|
+
|
|
117
|
+
| Name | Type |
|
|
118
|
+
| :-------- | :-------------------------------- |
|
|
119
|
+
| `region?` | `string` \| `Provider`<`string`\> |
|
|
120
|
+
|
|
121
|
+
#### Inherited from
|
|
122
|
+
|
|
123
|
+
Omit.parentClientConfig
|
|
124
|
+
|
|
125
|
+
#### Defined in
|
|
126
|
+
|
|
127
|
+
node_modules/.pnpm/@aws-sdk+types@3.609.0/node_modules/@aws-sdk/types/dist-types/credentials.d.ts:45
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
### policy
|
|
132
|
+
|
|
133
|
+
• **policy**: `undefined` \| `string`
|
|
134
|
+
|
|
135
|
+
An IAM policy in JSON format that you want to use as an inline session policy.
|
|
136
|
+
|
|
137
|
+
#### Inherited from
|
|
138
|
+
|
|
139
|
+
Omit.policy
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
### policyArns
|
|
144
|
+
|
|
145
|
+
• **policyArns**: `undefined` \| { `arn?`: `string` }[]
|
|
146
|
+
|
|
147
|
+
ARNs of the IAM managed policies that you want to use as managed session policies.
|
|
148
|
+
|
|
149
|
+
#### Inherited from
|
|
150
|
+
|
|
151
|
+
Omit.policyArns
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
### providerId
|
|
156
|
+
|
|
157
|
+
• **providerId**: `undefined` \| `string`
|
|
158
|
+
|
|
159
|
+
The fully qualified host component of the domain name of the identity provider.
|
|
160
|
+
|
|
161
|
+
#### Inherited from
|
|
162
|
+
|
|
163
|
+
Omit.providerId
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
### roleArn
|
|
168
|
+
|
|
169
|
+
• **roleArn**: `string`
|
|
170
|
+
|
|
171
|
+
ARN of the role that the caller is assuming.
|
|
172
|
+
|
|
173
|
+
#### Inherited from
|
|
174
|
+
|
|
175
|
+
Omit.roleArn
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
### roleAssumerWithWebIdentity
|
|
180
|
+
|
|
181
|
+
• `Optional` **roleAssumerWithWebIdentity**: (`params`: `AssumeRoleWithWebIdentityParams`) => [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`AwsCredentialIdentity`\>
|
|
182
|
+
|
|
183
|
+
#### Type declaration
|
|
184
|
+
|
|
185
|
+
▸ (`params`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`AwsCredentialIdentity`\>
|
|
186
|
+
|
|
187
|
+
A function that assumes a role with web identity and returns a promise fulfilled with credentials for the assumed role.
|
|
188
|
+
|
|
189
|
+
##### Parameters
|
|
190
|
+
|
|
191
|
+
| Name | Type |
|
|
192
|
+
| :------- | :-------------------------------- |
|
|
193
|
+
| `params` | `AssumeRoleWithWebIdentityParams` |
|
|
194
|
+
|
|
195
|
+
##### Returns
|
|
196
|
+
|
|
197
|
+
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`AwsCredentialIdentity`\>
|
|
198
|
+
|
|
199
|
+
#### Inherited from
|
|
200
|
+
|
|
201
|
+
Omit.roleAssumerWithWebIdentity
|
|
202
|
+
|
|
203
|
+
#### Defined in
|
|
204
|
+
|
|
205
|
+
node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.609.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:130
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
### roleSessionName
|
|
210
|
+
|
|
211
|
+
• `Optional` **roleSessionName**: `string`
|
|
212
|
+
|
|
213
|
+
An identifier for the assumed role session.
|
|
214
|
+
|
|
215
|
+
#### Inherited from
|
|
216
|
+
|
|
217
|
+
Omit.roleSessionName
|
|
218
|
+
|
|
219
|
+
#### Defined in
|
|
220
|
+
|
|
221
|
+
node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.609.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:123
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Module: index
|
|
2
|
+
|
|
3
|
+
## Table of contents
|
|
4
|
+
|
|
5
|
+
### Interfaces
|
|
6
|
+
|
|
7
|
+
- [Geo](../interfaces/index.Geo.md)
|
|
8
|
+
- [Request](../interfaces/index.Request.md)
|
|
9
|
+
|
|
10
|
+
### Functions
|
|
11
|
+
|
|
12
|
+
- [geolocation](index.md#geolocation)
|
|
13
|
+
- [getEnv](index.md#getenv)
|
|
14
|
+
- [ipAddress](index.md#ipaddress)
|
|
15
|
+
- [waitUntil](index.md#waituntil)
|
|
16
|
+
|
|
17
|
+
## Functions
|
|
18
|
+
|
|
19
|
+
### geolocation
|
|
20
|
+
|
|
21
|
+
▸ **geolocation**(`request`): [`Geo`](../interfaces/index.Geo.md)
|
|
22
|
+
|
|
23
|
+
Returns the location information for the incoming request.
|
|
24
|
+
|
|
25
|
+
**`Example`**
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { geolocation } from '@vercel/functions';
|
|
29
|
+
|
|
30
|
+
export function GET(request) {
|
|
31
|
+
const details = geolocation(request);
|
|
32
|
+
return Response.json(details);
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### Parameters
|
|
37
|
+
|
|
38
|
+
| Name | Type | Description |
|
|
39
|
+
| :-------- | :------------------------------------------ | :-------------------------------------------------------------- |
|
|
40
|
+
| `request` | [`Request`](../interfaces/index.Request.md) | The incoming request object which provides the geolocation data |
|
|
41
|
+
|
|
42
|
+
#### Returns
|
|
43
|
+
|
|
44
|
+
[`Geo`](../interfaces/index.Geo.md)
|
|
45
|
+
|
|
46
|
+
The location information of the request, in this way:
|
|
47
|
+
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"city": "New York",
|
|
51
|
+
"country": "US",
|
|
52
|
+
"flag": "🇺🇸",
|
|
53
|
+
"countryRegion": "NY",
|
|
54
|
+
"region": "dev1",
|
|
55
|
+
"latitude": "40.7128",
|
|
56
|
+
"longitude": "-74.0060"
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
#### Defined in
|
|
61
|
+
|
|
62
|
+
[packages/functions/src/headers.ts:166](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L166)
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
### getEnv
|
|
67
|
+
|
|
68
|
+
▸ **getEnv**(`env?`): `Object`
|
|
69
|
+
|
|
70
|
+
Get System Environment Variables exposed by Vercel.
|
|
71
|
+
|
|
72
|
+
**`See`**
|
|
73
|
+
|
|
74
|
+
https://vercel.com/docs/projects/environment-variables/system-environment-variables#system-environment-variables
|
|
75
|
+
|
|
76
|
+
#### Parameters
|
|
77
|
+
|
|
78
|
+
| Name | Type | Default value |
|
|
79
|
+
| :---- | :------- | :------------ |
|
|
80
|
+
| `env` | `Object` | `process.env` |
|
|
81
|
+
|
|
82
|
+
#### Returns
|
|
83
|
+
|
|
84
|
+
`Object`
|
|
85
|
+
|
|
86
|
+
| Name | Type | Description |
|
|
87
|
+
| :-------------------------------- | :---------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
88
|
+
| `CI` | `undefined` \| `string` | An indicator that the code is running in a Continuous Integration environment. **`Example`** `ts "1" ` |
|
|
89
|
+
| `VERCEL` | `undefined` \| `string` | An indicator to show that System Environment Variables have been exposed to your project's Deployments. **`Example`** `ts "1" ` |
|
|
90
|
+
| `VERCEL_AUTOMATION_BYPASS_SECRET` | `undefined` \| `string` | The Protection Bypass for Automation value, if the secret has been generated in the project's Deployment Protection settings. |
|
|
91
|
+
| `VERCEL_BRANCH_URL` | `undefined` \| `string` | The domain name of the generated Git branch URL. The value does not include the protocol scheme https://. **`Example`** `ts "*-git-*.vercel.app" ` |
|
|
92
|
+
| `VERCEL_DEPLOYMENT_ID` | `undefined` \| `string` | The unique identifier for the deployment, which can be used to implement Skew Protection. **`Example`** `ts "dpl_7Gw5ZMBpQA8h9GF832KGp7nwbuh3" ` |
|
|
93
|
+
| `VERCEL_ENV` | `undefined` \| `string` | The Environment that the app is deployed and running on. **`Example`** `ts "production" ` |
|
|
94
|
+
| `VERCEL_GIT_COMMIT_AUTHOR_LOGIN` | `undefined` \| `string` | The username attached to the author of the commit that the project was deployed by. **`Example`** `ts "johndoe" ` |
|
|
95
|
+
| `VERCEL_GIT_COMMIT_AUTHOR_NAME` | `undefined` \| `string` | The name attached to the author of the commit that the project was deployed by. **`Example`** `ts "John Doe" ` |
|
|
96
|
+
| `VERCEL_GIT_COMMIT_MESSAGE` | `undefined` \| `string` | The message attached to the commit the deployment was triggered by. **`Example`** `ts "Update about page" ` |
|
|
97
|
+
| `VERCEL_GIT_COMMIT_REF` | `undefined` \| `string` | The git branch of the commit the deployment was triggered by. **`Example`** `ts "improve-about-page" ` |
|
|
98
|
+
| `VERCEL_GIT_COMMIT_SHA` | `undefined` \| `string` | The git SHA of the commit the deployment was triggered by. **`Example`** `ts "fa1eade47b73733d6312d5abfad33ce9e4068081" ` |
|
|
99
|
+
| `VERCEL_GIT_PREVIOUS_SHA` | `undefined` \| `string` | The git SHA of the last successful deployment for the project and branch. NOTE: This Variable is only exposed when an Ignored Build Step is provided. **`Example`** `ts "fa1eade47b73733d6312d5abfad33ce9e4068080" ` |
|
|
100
|
+
| `VERCEL_GIT_PROVIDER` | `undefined` \| `string` | The Git Provider the deployment is triggered from. **`Example`** `ts "github" ` |
|
|
101
|
+
| `VERCEL_GIT_PULL_REQUEST_ID` | `undefined` \| `string` | The pull request id the deployment was triggered by. If a deployment is created on a branch before a pull request is made, this value will be an empty string. **`Example`** `ts "23" ` |
|
|
102
|
+
| `VERCEL_GIT_REPO_ID` | `undefined` \| `string` | The ID of the repository the deployment is triggered from. **`Example`** `ts "117716146" ` |
|
|
103
|
+
| `VERCEL_GIT_REPO_OWNER` | `undefined` \| `string` | The account that owns the repository the deployment is triggered from. **`Example`** `ts "acme" ` |
|
|
104
|
+
| `VERCEL_GIT_REPO_SLUG` | `undefined` \| `string` | The origin repository the deployment is triggered from. **`Example`** `ts "my-site" ` |
|
|
105
|
+
| `VERCEL_PROJECT_PRODUCTION_URL` | `undefined` \| `string` | A production domain name of the project. This is useful to reliably generate links that point to production such as OG-image URLs. The value does not include the protocol scheme https://. **`Example`** `ts "myproject.vercel.app" ` |
|
|
106
|
+
| `VERCEL_REGION` | `undefined` \| `string` | The ID of the Region where the app is running. Possible values: - arn1 (Stockholm, Sweden) - bom1 (Mumbai, India) - cdg1 (Paris, France) - cle1 (Cleveland, USA) - cpt1 (Cape Town, South Africa) - dub1 (Dublin, Ireland) - fra1 (Frankfurt, Germany) - gru1 (São Paulo, Brazil) - hkg1 (Hong Kong) - hnd1 (Tokyo, Japan) - iad1 (Washington, D.C., USA) - icn1 (Seoul, South Korea) - kix1 (Osaka, Japan) - lhr1 (London, United Kingdom) - pdx1 (Portland, USA) - sfo1 (San Francisco, USA) - sin1 (Singapore) - syd1 (Sydney, Australia) - dev1 (Development Region) **`Example`** `ts "iad1" ` |
|
|
107
|
+
| `VERCEL_SKEW_PROTECTION_ENABLED` | `undefined` \| `string` | When Skew Protection is enabled in Project Settings, this value is set to 1. **`Example`** `ts "1" ` |
|
|
108
|
+
| `VERCEL_URL` | `undefined` \| `string` | The domain name of the generated deployment URL. The value does not include the protocol scheme https://. NOTE: This Variable cannot be used in conjunction with Standard Deployment Protection. **`Example`** `ts "*.vercel.app" ` |
|
|
109
|
+
|
|
110
|
+
#### Defined in
|
|
111
|
+
|
|
112
|
+
[packages/functions/src/get-env.ts:6](https://github.com/vercel/vercel/blob/main/packages/functions/src/get-env.ts#L6)
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
### ipAddress
|
|
117
|
+
|
|
118
|
+
▸ **ipAddress**(`request`): `string` \| `undefined`
|
|
119
|
+
|
|
120
|
+
Returns the IP address of the request from the headers.
|
|
121
|
+
|
|
122
|
+
**`Example`**
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
import { ipAddress } from '@vercel/functions';
|
|
126
|
+
|
|
127
|
+
export function GET(request) {
|
|
128
|
+
const ip = ipAddress(request)
|
|
129
|
+
return new Response('Your ip is' ${ip});
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### Parameters
|
|
134
|
+
|
|
135
|
+
| Name | Type | Description |
|
|
136
|
+
| :-------- | :------------------------------------------ | :------------------------------------------------ |
|
|
137
|
+
| `request` | [`Request`](../interfaces/index.Request.md) | The incoming request object which provides the IP |
|
|
138
|
+
|
|
139
|
+
#### Returns
|
|
140
|
+
|
|
141
|
+
`string` \| `undefined`
|
|
142
|
+
|
|
143
|
+
The IP address of the request.
|
|
144
|
+
|
|
145
|
+
#### Defined in
|
|
146
|
+
|
|
147
|
+
[packages/functions/src/headers.ts:119](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L119)
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
### waitUntil
|
|
152
|
+
|
|
153
|
+
▸ **waitUntil**(`promise`): `undefined` \| `void`
|
|
154
|
+
|
|
155
|
+
Extends the lifetime of the request handler for the lifetime of the given Promise
|
|
156
|
+
|
|
157
|
+
**`See`**
|
|
158
|
+
|
|
159
|
+
https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent/waitUntil
|
|
160
|
+
|
|
161
|
+
**`Example`**
|
|
162
|
+
|
|
163
|
+
```js
|
|
164
|
+
import { waitUntil } from '@vercel/functions';
|
|
165
|
+
|
|
166
|
+
export function GET(request) {
|
|
167
|
+
waitUntil(fetch('https://vercel.com'));
|
|
168
|
+
return new Response('OK');
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
#### Parameters
|
|
173
|
+
|
|
174
|
+
| Name | Type | Description |
|
|
175
|
+
| :-------- | :---------------------------------------------------------------------------------------------------------------- | :----------------------- |
|
|
176
|
+
| `promise` | [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`unknown`\> | The promise to wait for. |
|
|
177
|
+
|
|
178
|
+
#### Returns
|
|
179
|
+
|
|
180
|
+
`undefined` \| `void`
|
|
181
|
+
|
|
182
|
+
#### Defined in
|
|
183
|
+
|
|
184
|
+
[packages/functions/src/wait-until.ts:19](https://github.com/vercel/vercel/blob/main/packages/functions/src/wait-until.ts#L19)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Module: oidc
|
|
2
|
+
|
|
3
|
+
## Table of contents
|
|
4
|
+
|
|
5
|
+
### Interfaces
|
|
6
|
+
|
|
7
|
+
- [AwsCredentialsProviderInit](../interfaces/oidc.AwsCredentialsProviderInit.md)
|
|
8
|
+
|
|
9
|
+
### Functions
|
|
10
|
+
|
|
11
|
+
- [awsCredentialsProvider](oidc.md#awscredentialsprovider)
|
|
12
|
+
- [getVercelOidcToken](oidc.md#getverceloidctoken)
|
|
13
|
+
|
|
14
|
+
## Functions
|
|
15
|
+
|
|
16
|
+
### awsCredentialsProvider
|
|
17
|
+
|
|
18
|
+
▸ **awsCredentialsProvider**(`init`): `AwsCredentialIdentityProvider`
|
|
19
|
+
|
|
20
|
+
Obtains the Vercel OIDC token and creates an AWS credential provider function
|
|
21
|
+
that gets AWS credentials by calling STS AssumeRoleWithWebIdentity API.
|
|
22
|
+
|
|
23
|
+
**`Example`**
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import * as s3 from '@aws-sdk/client-s3';
|
|
27
|
+
import { awsCredentialsProvider } from '@vercel/functions/oidc';
|
|
28
|
+
|
|
29
|
+
const s3Client = new s3.S3Client({
|
|
30
|
+
credentials: awsCredentialsProvider({
|
|
31
|
+
roleArn: 'arn:aws:iam::1234567890:role/RoleA',
|
|
32
|
+
clientConfig: { region: 'us-west-2' },
|
|
33
|
+
clientPlugins: [addFooHeadersPlugin],
|
|
34
|
+
roleAssumerWithWebIdentity: customRoleAssumer,
|
|
35
|
+
roleSessionName: 'session_123',
|
|
36
|
+
providerId: 'graph.facebook.com',
|
|
37
|
+
policyArns: [{ arn: 'arn:aws:iam::1234567890:policy/SomePolicy' }],
|
|
38
|
+
policy:
|
|
39
|
+
'{"Statement": [{"Effect": "Allow", "Action": "s3:ListBucket", "Resource": "*"}]}',
|
|
40
|
+
durationSeconds: 7200,
|
|
41
|
+
}),
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
#### Parameters
|
|
46
|
+
|
|
47
|
+
| Name | Type | Description |
|
|
48
|
+
| :----- | :------------------------------------------------------------------------------- | :------------------------- |
|
|
49
|
+
| `init` | [`AwsCredentialsProviderInit`](../interfaces/oidc.AwsCredentialsProviderInit.md) | The initialization object. |
|
|
50
|
+
|
|
51
|
+
#### Returns
|
|
52
|
+
|
|
53
|
+
`AwsCredentialIdentityProvider`
|
|
54
|
+
|
|
55
|
+
A function that provides AWS credentials.
|
|
56
|
+
|
|
57
|
+
#### Defined in
|
|
58
|
+
|
|
59
|
+
[packages/functions/src/oidc/aws-credentials-provider.ts:60](https://github.com/vercel/vercel/blob/main/packages/functions/src/oidc/aws-credentials-provider.ts#L60)
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
### getVercelOidcToken
|
|
64
|
+
|
|
65
|
+
▸ **getVercelOidcToken**(): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\>
|
|
66
|
+
|
|
67
|
+
Returns the OIDC token from the request context or the environment variable.
|
|
68
|
+
|
|
69
|
+
This function first checks if the OIDC token is available in the environment variable
|
|
70
|
+
`VERCEL_OIDC_TOKEN`. If it is not found there, it retrieves the token from the request
|
|
71
|
+
context headers.
|
|
72
|
+
|
|
73
|
+
**`Throws`**
|
|
74
|
+
|
|
75
|
+
If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set.
|
|
76
|
+
|
|
77
|
+
**`Example`**
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
// Using the OIDC token
|
|
81
|
+
getVercelOidcToken()
|
|
82
|
+
.then(token => {
|
|
83
|
+
console.log('OIDC Token:', token);
|
|
84
|
+
})
|
|
85
|
+
.catch(error => {
|
|
86
|
+
console.error('Error:', error.message);
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### Returns
|
|
91
|
+
|
|
92
|
+
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\>
|
|
93
|
+
|
|
94
|
+
A promise that resolves to the OIDC token.
|
|
95
|
+
|
|
96
|
+
#### Defined in
|
|
97
|
+
|
|
98
|
+
[packages/functions/src/oidc/get-vercel-oidc-token.ts:24](https://github.com/vercel/vercel/blob/main/packages/functions/src/oidc/get-vercel-oidc-token.ts#L24)
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get System Environment Variables exposed by Vercel.
|
|
3
|
+
*
|
|
4
|
+
* @see https://vercel.com/docs/projects/environment-variables/system-environment-variables#system-environment-variables
|
|
5
|
+
*/
|
|
1
6
|
export declare const getEnv: (env?: {
|
|
2
7
|
[key: string]: string | undefined;
|
|
3
8
|
}) => {
|
|
@@ -65,18 +65,48 @@ export interface Geo {
|
|
|
65
65
|
/**
|
|
66
66
|
* Returns the IP address of the request from the headers.
|
|
67
67
|
*
|
|
68
|
-
* @see {@link IP_HEADER_NAME}
|
|
69
68
|
* @param request The incoming request object which provides the IP
|
|
69
|
+
* @returns The IP address of the request.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
*
|
|
73
|
+
* ```js
|
|
74
|
+
* import { ipAddress } from '@vercel/functions';
|
|
75
|
+
*
|
|
76
|
+
* export function GET(request) {
|
|
77
|
+
* const ip = ipAddress(request)
|
|
78
|
+
* return new Response('Your ip is' ${ip});
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
70
82
|
*/
|
|
71
83
|
export declare function ipAddress(request: Request): string | undefined;
|
|
72
84
|
/**
|
|
73
85
|
* Returns the location information for the incoming request.
|
|
74
|
-
*
|
|
75
|
-
* @see {@link CITY_HEADER_NAME}
|
|
76
|
-
* @see {@link COUNTRY_HEADER_NAME}
|
|
77
|
-
* @see {@link REGION_HEADER_NAME}
|
|
78
|
-
* @see {@link LATITUDE_HEADER_NAME}
|
|
79
|
-
* @see {@link LONGITUDE_HEADER_NAME}
|
|
80
86
|
* @param request The incoming request object which provides the geolocation data
|
|
87
|
+
* @returns The location information of the request, in this way:
|
|
88
|
+
*
|
|
89
|
+
* ```json
|
|
90
|
+
* {
|
|
91
|
+
* "city": "New York",
|
|
92
|
+
* "country": "US",
|
|
93
|
+
* "flag": "🇺🇸",
|
|
94
|
+
* "countryRegion": "NY",
|
|
95
|
+
* "region": "dev1",
|
|
96
|
+
* "latitude": "40.7128",
|
|
97
|
+
* "longitude": "-74.0060"
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
*
|
|
103
|
+
* ```js
|
|
104
|
+
* import { geolocation } from '@vercel/functions';
|
|
105
|
+
*
|
|
106
|
+
* export function GET(request) {
|
|
107
|
+
* const details = geolocation(request);
|
|
108
|
+
* return Response.json(details);
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
81
111
|
*/
|
|
82
112
|
export declare function geolocation(request: Request): Geo;
|
|
@@ -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
|
|
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),
|
|
@@ -35,7 +35,7 @@ export interface AwsCredentialsProviderInit// eslint-disable-line @typescript-es
|
|
|
35
35
|
* @returns {AwsCredentialIdentityProvider} A function that provides AWS credentials.
|
|
36
36
|
*
|
|
37
37
|
* @example
|
|
38
|
-
* ```
|
|
38
|
+
* ```js
|
|
39
39
|
* import * as s3 from '@aws-sdk/client-s3';
|
|
40
40
|
* import { awsCredentialsProvider } from '@vercel/functions/oidc';
|
|
41
41
|
*
|
|
@@ -5,17 +5,18 @@
|
|
|
5
5
|
* `VERCEL_OIDC_TOKEN`. If it is not found there, it retrieves the token from the request
|
|
6
6
|
* context headers.
|
|
7
7
|
*
|
|
8
|
-
* @async
|
|
9
|
-
* @function
|
|
10
8
|
* @returns {Promise<string>} A promise that resolves to the OIDC token.
|
|
11
9
|
* @throws {Error} If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set.
|
|
12
10
|
*
|
|
13
11
|
* @example
|
|
12
|
+
*
|
|
13
|
+
* ```js
|
|
14
14
|
* // Using the OIDC token
|
|
15
15
|
* getVercelOidcToken().then((token) => {
|
|
16
16
|
* console.log('OIDC Token:', token);
|
|
17
17
|
* }).catch((error) => {
|
|
18
18
|
* console.error('Error:', error.message);
|
|
19
19
|
* });
|
|
20
|
+
* ```
|
|
20
21
|
*/
|
|
21
22
|
export declare function getVercelOidcToken(): Promise<string>;
|
package/package.json
CHANGED
|
@@ -2,21 +2,14 @@
|
|
|
2
2
|
"name": "@vercel/functions",
|
|
3
3
|
"description": "Runtime functions to be used with your Vercel Functions",
|
|
4
4
|
"homepage": "https://vercel.com",
|
|
5
|
-
"exports": {
|
|
6
|
-
".": {
|
|
7
|
-
"types": "./dist/index.d.ts",
|
|
8
|
-
"default": "./dist/index.js"
|
|
9
|
-
},
|
|
10
|
-
"./oidc": {
|
|
11
|
-
"types": "./dist/oidc/index.d.ts",
|
|
12
|
-
"default": "./dist/oidc/index.js"
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
5
|
"files": [
|
|
16
|
-
"
|
|
6
|
+
"**/*.js",
|
|
7
|
+
"**/*.d.ts",
|
|
8
|
+
"**/*.md"
|
|
17
9
|
],
|
|
18
|
-
"
|
|
19
|
-
"
|
|
10
|
+
"main": "./index.js",
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"version": "1.4.2",
|
|
20
13
|
"repository": {
|
|
21
14
|
"directory": "packages/functions",
|
|
22
15
|
"type": "git",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|