@vercel/functions 3.5.0 → 3.5.1
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 +8 -0
- package/docs/README.md +7 -5
- package/docs/index/README.md +37 -0
- package/docs/index/functions/addCacheTag.md +19 -0
- package/docs/index/functions/attachDatabasePool.md +45 -0
- package/docs/index/functions/dangerouslyDeleteBySrcImage.md +23 -0
- package/docs/index/functions/dangerouslyDeleteByTag.md +23 -0
- package/docs/index/functions/geolocation.md +49 -0
- package/docs/index/functions/getCache.md +36 -0
- package/docs/index/functions/getEnv.md +291 -0
- package/docs/index/functions/invalidateBySrcImage.md +19 -0
- package/docs/index/functions/invalidateByTag.md +19 -0
- package/docs/index/functions/ipAddress.md +36 -0
- package/docs/index/functions/next.md +47 -0
- package/docs/index/functions/rewrite.md +66 -0
- package/docs/index/functions/waitUntil.md +38 -0
- package/docs/index/interfaces/DangerouslyDeleteOptions.md +18 -0
- package/docs/index/interfaces/Geo.md +90 -0
- package/docs/index/interfaces/PurgeApi.md +123 -0
- package/docs/index/interfaces/Request.md +19 -0
- package/docs/index/interfaces/RuntimeCache.md +133 -0
- package/docs/index/type-aliases/AddCacheTagApi.md +26 -0
- package/docs/index/variables/experimental_attachDatabasePool.md +49 -0
- package/docs/oidc/README.md +15 -0
- package/docs/oidc/functions/awsCredentialsProvider.md +24 -0
- package/docs/oidc/functions/getVercelOidcToken.md +58 -0
- package/docs/oidc/functions/getVercelOidcTokenSync.md +36 -0
- package/docs/oidc/interfaces/AwsCredentialsProviderInit.md +195 -0
- package/package.json +5 -5
- package/docs/interfaces/index.DangerouslyDeleteOptions.md +0 -22
- package/docs/interfaces/index.Geo.md +0 -115
- package/docs/interfaces/index.PurgeApi.md +0 -134
- package/docs/interfaces/index.Request.md +0 -23
- package/docs/interfaces/index.RuntimeCache.md +0 -131
- package/docs/interfaces/oidc.AwsCredentialsProviderInit.md +0 -221
- package/docs/modules/index.md +0 -536
- package/docs/modules/oidc.md +0 -133
package/docs/modules/index.md
DELETED
|
@@ -1,536 +0,0 @@
|
|
|
1
|
-
# Module: index
|
|
2
|
-
|
|
3
|
-
## Table of contents
|
|
4
|
-
|
|
5
|
-
### Interfaces
|
|
6
|
-
|
|
7
|
-
- [DangerouslyDeleteOptions](../interfaces/index.DangerouslyDeleteOptions.md)
|
|
8
|
-
- [Geo](../interfaces/index.Geo.md)
|
|
9
|
-
- [PurgeApi](../interfaces/index.PurgeApi.md)
|
|
10
|
-
- [Request](../interfaces/index.Request.md)
|
|
11
|
-
- [RuntimeCache](../interfaces/index.RuntimeCache.md)
|
|
12
|
-
|
|
13
|
-
### Type Aliases
|
|
14
|
-
|
|
15
|
-
- [AddCacheTagApi](index.md#addcachetagapi)
|
|
16
|
-
|
|
17
|
-
### Functions
|
|
18
|
-
|
|
19
|
-
- [addCacheTag](index.md#addcachetag)
|
|
20
|
-
- [attachDatabasePool](index.md#attachdatabasepool)
|
|
21
|
-
- [dangerouslyDeleteBySrcImage](index.md#dangerouslydeletebysrcimage)
|
|
22
|
-
- [dangerouslyDeleteByTag](index.md#dangerouslydeletebytag)
|
|
23
|
-
- [experimental_attachDatabasePool](index.md#experimental_attachdatabasepool)
|
|
24
|
-
- [geolocation](index.md#geolocation)
|
|
25
|
-
- [getCache](index.md#getcache)
|
|
26
|
-
- [getEnv](index.md#getenv)
|
|
27
|
-
- [invalidateBySrcImage](index.md#invalidatebysrcimage)
|
|
28
|
-
- [invalidateByTag](index.md#invalidatebytag)
|
|
29
|
-
- [ipAddress](index.md#ipaddress)
|
|
30
|
-
- [next](index.md#next)
|
|
31
|
-
- [rewrite](index.md#rewrite)
|
|
32
|
-
- [waitUntil](index.md#waituntil)
|
|
33
|
-
|
|
34
|
-
## Type Aliases
|
|
35
|
-
|
|
36
|
-
### AddCacheTagApi
|
|
37
|
-
|
|
38
|
-
Ƭ **AddCacheTagApi**: (`tag`: `string` \| `string`[]) => [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
39
|
-
|
|
40
|
-
#### Type declaration
|
|
41
|
-
|
|
42
|
-
▸ (`tag`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
43
|
-
|
|
44
|
-
Vercel AddCacheTag API.
|
|
45
|
-
A function that adds one or more tags to the cache content.
|
|
46
|
-
|
|
47
|
-
##### Parameters
|
|
48
|
-
|
|
49
|
-
| Name | Type | Description |
|
|
50
|
-
| :---- | :--------------------- | :-------------------------------------------- |
|
|
51
|
-
| `tag` | `string` \| `string`[] | One or more tags to add to the cache content. |
|
|
52
|
-
|
|
53
|
-
##### Returns
|
|
54
|
-
|
|
55
|
-
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
56
|
-
|
|
57
|
-
A promise that resolves when the tag is added.
|
|
58
|
-
|
|
59
|
-
#### Defined in
|
|
60
|
-
|
|
61
|
-
[packages/functions/src/addcachetag/types.ts:8](https://github.com/vercel/vercel/blob/main/packages/functions/src/addcachetag/types.ts#L8)
|
|
62
|
-
|
|
63
|
-
## Functions
|
|
64
|
-
|
|
65
|
-
### addCacheTag
|
|
66
|
-
|
|
67
|
-
▸ **addCacheTag**(`tag`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
68
|
-
|
|
69
|
-
#### Parameters
|
|
70
|
-
|
|
71
|
-
| Name | Type |
|
|
72
|
-
| :---- | :--------------------- |
|
|
73
|
-
| `tag` | `string` \| `string`[] |
|
|
74
|
-
|
|
75
|
-
#### Returns
|
|
76
|
-
|
|
77
|
-
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
78
|
-
|
|
79
|
-
#### Defined in
|
|
80
|
-
|
|
81
|
-
[packages/functions/src/addcachetag/index.ts:3](https://github.com/vercel/vercel/blob/main/packages/functions/src/addcachetag/index.ts#L3)
|
|
82
|
-
|
|
83
|
-
---
|
|
84
|
-
|
|
85
|
-
### attachDatabasePool
|
|
86
|
-
|
|
87
|
-
▸ **attachDatabasePool**(`dbPool`): `void`
|
|
88
|
-
|
|
89
|
-
Call this function right after creating a database pool with the database pool object
|
|
90
|
-
as argument.
|
|
91
|
-
This ensures that the current function instance stays alive long enough for
|
|
92
|
-
idle database connections to be removed from the pool.
|
|
93
|
-
|
|
94
|
-
**`Example`**
|
|
95
|
-
|
|
96
|
-
```ts
|
|
97
|
-
const pgPool = new Pool({
|
|
98
|
-
connectionString: process.env.DATABASE_URL,
|
|
99
|
-
});
|
|
100
|
-
attachDatabasePool(pgPool);
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
#### Parameters
|
|
104
|
-
|
|
105
|
-
| Name | Type | Description |
|
|
106
|
-
| :------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
107
|
-
| `dbPool` | `DbPool` | The database pool object. The supported pool types are: - PostgreSQL (pg) - MySQL2 - MariaDB - MongoDB - Redis (ioredis) - Cassandra (cassandra-driver) - OTHER: This method uses duck-typing to detect the pool type. Respectively you can pass in any object with a compatible interface. |
|
|
108
|
-
|
|
109
|
-
#### Returns
|
|
110
|
-
|
|
111
|
-
`void`
|
|
112
|
-
|
|
113
|
-
#### Defined in
|
|
114
|
-
|
|
115
|
-
[packages/functions/src/db-connections/index.ts:225](https://github.com/vercel/vercel/blob/main/packages/functions/src/db-connections/index.ts#L225)
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
### dangerouslyDeleteBySrcImage
|
|
120
|
-
|
|
121
|
-
▸ **dangerouslyDeleteBySrcImage**(`src`, `options?`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
122
|
-
|
|
123
|
-
#### Parameters
|
|
124
|
-
|
|
125
|
-
| Name | Type |
|
|
126
|
-
| :--------- | :---------------------------------------------------------------------------- |
|
|
127
|
-
| `src` | `string` \| `string`[] |
|
|
128
|
-
| `options?` | [`DangerouslyDeleteOptions`](../interfaces/index.DangerouslyDeleteOptions.md) |
|
|
129
|
-
|
|
130
|
-
#### Returns
|
|
131
|
-
|
|
132
|
-
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
133
|
-
|
|
134
|
-
#### Defined in
|
|
135
|
-
|
|
136
|
-
[packages/functions/src/purge/index.ts:28](https://github.com/vercel/vercel/blob/main/packages/functions/src/purge/index.ts#L28)
|
|
137
|
-
|
|
138
|
-
---
|
|
139
|
-
|
|
140
|
-
### dangerouslyDeleteByTag
|
|
141
|
-
|
|
142
|
-
▸ **dangerouslyDeleteByTag**(`tag`, `options?`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
143
|
-
|
|
144
|
-
#### Parameters
|
|
145
|
-
|
|
146
|
-
| Name | Type |
|
|
147
|
-
| :--------- | :---------------------------------------------------------------------------- |
|
|
148
|
-
| `tag` | `string` \| `string`[] |
|
|
149
|
-
| `options?` | [`DangerouslyDeleteOptions`](../interfaces/index.DangerouslyDeleteOptions.md) |
|
|
150
|
-
|
|
151
|
-
#### Returns
|
|
152
|
-
|
|
153
|
-
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
154
|
-
|
|
155
|
-
#### Defined in
|
|
156
|
-
|
|
157
|
-
[packages/functions/src/purge/index.ts:12](https://github.com/vercel/vercel/blob/main/packages/functions/src/purge/index.ts#L12)
|
|
158
|
-
|
|
159
|
-
---
|
|
160
|
-
|
|
161
|
-
### experimental_attachDatabasePool
|
|
162
|
-
|
|
163
|
-
▸ **experimental_attachDatabasePool**(`dbPool`): `void`
|
|
164
|
-
|
|
165
|
-
**`Deprecated`**
|
|
166
|
-
|
|
167
|
-
Use attachDatabasePool instead.
|
|
168
|
-
|
|
169
|
-
#### Parameters
|
|
170
|
-
|
|
171
|
-
| Name | Type |
|
|
172
|
-
| :------- | :------- |
|
|
173
|
-
| `dbPool` | `DbPool` |
|
|
174
|
-
|
|
175
|
-
#### Returns
|
|
176
|
-
|
|
177
|
-
`void`
|
|
178
|
-
|
|
179
|
-
#### Defined in
|
|
180
|
-
|
|
181
|
-
[packages/functions/src/db-connections/index.ts:225](https://github.com/vercel/vercel/blob/main/packages/functions/src/db-connections/index.ts#L225)
|
|
182
|
-
|
|
183
|
-
---
|
|
184
|
-
|
|
185
|
-
### geolocation
|
|
186
|
-
|
|
187
|
-
▸ **geolocation**(`request`): [`Geo`](../interfaces/index.Geo.md)
|
|
188
|
-
|
|
189
|
-
Returns the location information for the incoming request.
|
|
190
|
-
|
|
191
|
-
**`Example`**
|
|
192
|
-
|
|
193
|
-
```js
|
|
194
|
-
import { geolocation } from '@vercel/functions';
|
|
195
|
-
|
|
196
|
-
export function GET(request) {
|
|
197
|
-
const details = geolocation(request);
|
|
198
|
-
return Response.json(details);
|
|
199
|
-
}
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
#### Parameters
|
|
203
|
-
|
|
204
|
-
| Name | Type | Description |
|
|
205
|
-
| :-------- | :------------------------------------------ | :-------------------------------------------------------------- |
|
|
206
|
-
| `request` | [`Request`](../interfaces/index.Request.md) | The incoming request object which provides the geolocation data |
|
|
207
|
-
|
|
208
|
-
#### Returns
|
|
209
|
-
|
|
210
|
-
[`Geo`](../interfaces/index.Geo.md)
|
|
211
|
-
|
|
212
|
-
The location information of the request, in this way:
|
|
213
|
-
|
|
214
|
-
```json
|
|
215
|
-
{
|
|
216
|
-
"city": "New York",
|
|
217
|
-
"country": "US",
|
|
218
|
-
"flag": "🇺🇸",
|
|
219
|
-
"countryRegion": "NY",
|
|
220
|
-
"region": "iad1",
|
|
221
|
-
"latitude": "40.7128",
|
|
222
|
-
"longitude": "-74.0060"
|
|
223
|
-
"postalCode": "10001"
|
|
224
|
-
}
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
#### Defined in
|
|
228
|
-
|
|
229
|
-
[packages/functions/src/headers.ts:180](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L180)
|
|
230
|
-
|
|
231
|
-
---
|
|
232
|
-
|
|
233
|
-
### getCache
|
|
234
|
-
|
|
235
|
-
▸ **getCache**(`cacheOptions?`): [`RuntimeCache`](../interfaces/index.RuntimeCache.md)
|
|
236
|
-
|
|
237
|
-
Retrieves the Vercel Runtime Cache.
|
|
238
|
-
|
|
239
|
-
Keys are hashed to ensure they are unique and consistent. The hashing function can be overridden by providing a custom
|
|
240
|
-
`keyHashFunction` in the `cacheOptions` parameter.
|
|
241
|
-
|
|
242
|
-
To specify a namespace for the cache keys, you can pass a `namespace` option in the `cacheOptions` parameter. If
|
|
243
|
-
a namespace is provided, the cache keys will be prefixed with the namespace followed by a separator (default is `$`). The
|
|
244
|
-
namespaceSeparator can also be customized using the `namespaceSeparator` option.
|
|
245
|
-
|
|
246
|
-
**`Throws`**
|
|
247
|
-
|
|
248
|
-
If no cache is available in the context and `InMemoryCache` cannot be created.
|
|
249
|
-
|
|
250
|
-
#### Parameters
|
|
251
|
-
|
|
252
|
-
| Name | Type | Description |
|
|
253
|
-
| :-------------- | :------------- | :------------------------------------ |
|
|
254
|
-
| `cacheOptions?` | `CacheOptions` | Optional configuration for the cache. |
|
|
255
|
-
|
|
256
|
-
#### Returns
|
|
257
|
-
|
|
258
|
-
[`RuntimeCache`](../interfaces/index.RuntimeCache.md)
|
|
259
|
-
|
|
260
|
-
An instance of the Vercel Runtime Cache.
|
|
261
|
-
|
|
262
|
-
#### Defined in
|
|
263
|
-
|
|
264
|
-
[packages/functions/src/cache/index.ts:33](https://github.com/vercel/vercel/blob/main/packages/functions/src/cache/index.ts#L33)
|
|
265
|
-
|
|
266
|
-
---
|
|
267
|
-
|
|
268
|
-
### getEnv
|
|
269
|
-
|
|
270
|
-
▸ **getEnv**(`env?`): `Object`
|
|
271
|
-
|
|
272
|
-
Get System Environment Variables exposed by Vercel.
|
|
273
|
-
|
|
274
|
-
**`See`**
|
|
275
|
-
|
|
276
|
-
https://vercel.com/docs/projects/environment-variables/system-environment-variables#system-environment-variables
|
|
277
|
-
|
|
278
|
-
#### Parameters
|
|
279
|
-
|
|
280
|
-
| Name | Type | Default value |
|
|
281
|
-
| :---- | :------- | :------------ |
|
|
282
|
-
| `env` | `Object` | `process.env` |
|
|
283
|
-
|
|
284
|
-
#### Returns
|
|
285
|
-
|
|
286
|
-
`Object`
|
|
287
|
-
|
|
288
|
-
| Name | Type | Description |
|
|
289
|
-
| :-------------------------------- | :---------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
290
|
-
| `CI` | `undefined` \| `string` | An indicator that the code is running in a Continuous Integration environment. **`Example`** `ts "1" ` |
|
|
291
|
-
| `VERCEL` | `undefined` \| `string` | An indicator to show that System Environment Variables have been exposed to your project's Deployments. **`Example`** `ts "1" ` |
|
|
292
|
-
| `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. |
|
|
293
|
-
| `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" ` |
|
|
294
|
-
| `VERCEL_DEPLOYMENT_ID` | `undefined` \| `string` | The unique identifier for the deployment, which can be used to implement Skew Protection. **`Example`** `ts "dpl_7Gw5ZMBpQA8h9GF832KGp7nwbuh3" ` |
|
|
295
|
-
| `VERCEL_ENV` | `undefined` \| `string` | The Environment that the app is deployed and running on. **`Example`** `ts "production" ` |
|
|
296
|
-
| `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" ` |
|
|
297
|
-
| `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" ` |
|
|
298
|
-
| `VERCEL_GIT_COMMIT_MESSAGE` | `undefined` \| `string` | The message attached to the commit the deployment was triggered by. **`Example`** `ts "Update about page" ` |
|
|
299
|
-
| `VERCEL_GIT_COMMIT_REF` | `undefined` \| `string` | The git branch of the commit the deployment was triggered by. **`Example`** `ts "improve-about-page" ` |
|
|
300
|
-
| `VERCEL_GIT_COMMIT_SHA` | `undefined` \| `string` | The git SHA of the commit the deployment was triggered by. **`Example`** `ts "fa1eade47b73733d6312d5abfad33ce9e4068081" ` |
|
|
301
|
-
| `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" ` |
|
|
302
|
-
| `VERCEL_GIT_PROVIDER` | `undefined` \| `string` | The Git Provider the deployment is triggered from. **`Example`** `ts "github" ` |
|
|
303
|
-
| `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" ` |
|
|
304
|
-
| `VERCEL_GIT_REPO_ID` | `undefined` \| `string` | The ID of the repository the deployment is triggered from. **`Example`** `ts "117716146" ` |
|
|
305
|
-
| `VERCEL_GIT_REPO_OWNER` | `undefined` \| `string` | The account that owns the repository the deployment is triggered from. **`Example`** `ts "acme" ` |
|
|
306
|
-
| `VERCEL_GIT_REPO_SLUG` | `undefined` \| `string` | The origin repository the deployment is triggered from. **`Example`** `ts "my-site" ` |
|
|
307
|
-
| `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" ` |
|
|
308
|
-
| `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" ` |
|
|
309
|
-
| `VERCEL_SKEW_PROTECTION_ENABLED` | `undefined` \| `string` | When Skew Protection is enabled in Project Settings, this value is set to 1. **`Example`** `ts "1" ` |
|
|
310
|
-
| `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" ` |
|
|
311
|
-
|
|
312
|
-
#### Defined in
|
|
313
|
-
|
|
314
|
-
[packages/functions/src/get-env.ts:6](https://github.com/vercel/vercel/blob/main/packages/functions/src/get-env.ts#L6)
|
|
315
|
-
|
|
316
|
-
---
|
|
317
|
-
|
|
318
|
-
### invalidateBySrcImage
|
|
319
|
-
|
|
320
|
-
▸ **invalidateBySrcImage**(`src`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
321
|
-
|
|
322
|
-
#### Parameters
|
|
323
|
-
|
|
324
|
-
| Name | Type |
|
|
325
|
-
| :---- | :--------------------- |
|
|
326
|
-
| `src` | `string` \| `string`[] |
|
|
327
|
-
|
|
328
|
-
#### Returns
|
|
329
|
-
|
|
330
|
-
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
331
|
-
|
|
332
|
-
#### Defined in
|
|
333
|
-
|
|
334
|
-
[packages/functions/src/purge/index.ts:23](https://github.com/vercel/vercel/blob/main/packages/functions/src/purge/index.ts#L23)
|
|
335
|
-
|
|
336
|
-
---
|
|
337
|
-
|
|
338
|
-
### invalidateByTag
|
|
339
|
-
|
|
340
|
-
▸ **invalidateByTag**(`tag`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
341
|
-
|
|
342
|
-
#### Parameters
|
|
343
|
-
|
|
344
|
-
| Name | Type |
|
|
345
|
-
| :---- | :--------------------- |
|
|
346
|
-
| `tag` | `string` \| `string`[] |
|
|
347
|
-
|
|
348
|
-
#### Returns
|
|
349
|
-
|
|
350
|
-
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`void`\>
|
|
351
|
-
|
|
352
|
-
#### Defined in
|
|
353
|
-
|
|
354
|
-
[packages/functions/src/purge/index.ts:4](https://github.com/vercel/vercel/blob/main/packages/functions/src/purge/index.ts#L4)
|
|
355
|
-
|
|
356
|
-
---
|
|
357
|
-
|
|
358
|
-
### ipAddress
|
|
359
|
-
|
|
360
|
-
▸ **ipAddress**(`input`): `string` \| `undefined`
|
|
361
|
-
|
|
362
|
-
Returns the IP address of the request from the headers.
|
|
363
|
-
|
|
364
|
-
**`Example`**
|
|
365
|
-
|
|
366
|
-
```js
|
|
367
|
-
import { ipAddress } from '@vercel/functions';
|
|
368
|
-
|
|
369
|
-
export function GET(request) {
|
|
370
|
-
const ip = ipAddress(request);
|
|
371
|
-
return new Response(`Your IP is ${ip}`);
|
|
372
|
-
}
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
#### Parameters
|
|
376
|
-
|
|
377
|
-
| Name | Type | Description |
|
|
378
|
-
| :------ | :------------------------------------------------------- | :-------------------------------------- |
|
|
379
|
-
| `input` | `Headers` \| [`Request`](../interfaces/index.Request.md) | The incoming request object or headers. |
|
|
380
|
-
|
|
381
|
-
#### Returns
|
|
382
|
-
|
|
383
|
-
`string` \| `undefined`
|
|
384
|
-
|
|
385
|
-
The IP address of the request.
|
|
386
|
-
|
|
387
|
-
#### Defined in
|
|
388
|
-
|
|
389
|
-
[packages/functions/src/headers.ts:131](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L131)
|
|
390
|
-
|
|
391
|
-
---
|
|
392
|
-
|
|
393
|
-
### next
|
|
394
|
-
|
|
395
|
-
▸ **next**(`init?`): [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
396
|
-
|
|
397
|
-
Returns a Response that instructs the system to continue processing the request.
|
|
398
|
-
|
|
399
|
-
**`Example`**
|
|
400
|
-
|
|
401
|
-
<caption>No-op middleware</caption>
|
|
402
|
-
|
|
403
|
-
```ts
|
|
404
|
-
import { next } from '@vercel/edge';
|
|
405
|
-
|
|
406
|
-
export default function middleware(_req: Request) {
|
|
407
|
-
return next();
|
|
408
|
-
}
|
|
409
|
-
```
|
|
410
|
-
|
|
411
|
-
**`Example`**
|
|
412
|
-
|
|
413
|
-
<caption>Add response headers to all requests</caption>
|
|
414
|
-
|
|
415
|
-
```ts
|
|
416
|
-
import { next } from '@vercel/edge';
|
|
417
|
-
|
|
418
|
-
export default function middleware(_req: Request) {
|
|
419
|
-
return next({
|
|
420
|
-
headers: { 'x-from-middleware': 'true' },
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
#### Parameters
|
|
426
|
-
|
|
427
|
-
| Name | Type | Description |
|
|
428
|
-
| :------ | :------------------ | :---------------------------------- |
|
|
429
|
-
| `init?` | `ExtraResponseInit` | Additional options for the response |
|
|
430
|
-
|
|
431
|
-
#### Returns
|
|
432
|
-
|
|
433
|
-
[`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
434
|
-
|
|
435
|
-
#### Defined in
|
|
436
|
-
|
|
437
|
-
[packages/functions/src/middleware.ts:145](https://github.com/vercel/vercel/blob/main/packages/functions/src/middleware.ts#L145)
|
|
438
|
-
|
|
439
|
-
---
|
|
440
|
-
|
|
441
|
-
### rewrite
|
|
442
|
-
|
|
443
|
-
▸ **rewrite**(`destination`, `init?`): [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
444
|
-
|
|
445
|
-
Returns a response that rewrites the request to a different URL.
|
|
446
|
-
|
|
447
|
-
**`Example`**
|
|
448
|
-
|
|
449
|
-
<caption>Rewrite all feature-flagged requests from `/:path*` to `/experimental/:path*`</caption>
|
|
450
|
-
|
|
451
|
-
```ts
|
|
452
|
-
import { rewrite, next } from '@vercel/edge';
|
|
453
|
-
|
|
454
|
-
export default async function middleware(req: Request) {
|
|
455
|
-
const flagged = await getFlag(req, 'isExperimental');
|
|
456
|
-
if (flagged) {
|
|
457
|
-
const url = new URL(req.url);
|
|
458
|
-
url.pathname = `/experimental{url.pathname}`;
|
|
459
|
-
return rewrite(url);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
return next();
|
|
463
|
-
}
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
**`Example`**
|
|
467
|
-
|
|
468
|
-
<caption>JWT authentication for `/api/:path*` requests</caption>
|
|
469
|
-
|
|
470
|
-
```ts
|
|
471
|
-
import { rewrite, next } from '@vercel/edge';
|
|
472
|
-
|
|
473
|
-
export default function middleware(req: Request) {
|
|
474
|
-
const auth = checkJwt(req.headers.get('Authorization'));
|
|
475
|
-
if (!checkJwt) {
|
|
476
|
-
return rewrite(new URL('/api/error-unauthorized', req.url));
|
|
477
|
-
}
|
|
478
|
-
const url = new URL(req.url);
|
|
479
|
-
url.searchParams.set('_userId', auth.userId);
|
|
480
|
-
return rewrite(url);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
export const config = { matcher: '/api/users/:path*' };
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
#### Parameters
|
|
487
|
-
|
|
488
|
-
| Name | Type | Description |
|
|
489
|
-
| :------------ | :------------------------------------------------------------------------ | :---------------------------------- |
|
|
490
|
-
| `destination` | `string` \| [`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL) | new URL to rewrite the request to |
|
|
491
|
-
| `init?` | `ExtraResponseInit` | Additional options for the response |
|
|
492
|
-
|
|
493
|
-
#### Returns
|
|
494
|
-
|
|
495
|
-
[`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
496
|
-
|
|
497
|
-
#### Defined in
|
|
498
|
-
|
|
499
|
-
[packages/functions/src/middleware.ts:101](https://github.com/vercel/vercel/blob/main/packages/functions/src/middleware.ts#L101)
|
|
500
|
-
|
|
501
|
-
---
|
|
502
|
-
|
|
503
|
-
### waitUntil
|
|
504
|
-
|
|
505
|
-
▸ **waitUntil**(`promise`): `undefined` \| `void`
|
|
506
|
-
|
|
507
|
-
Extends the lifetime of the request handler for the lifetime of the given Promise
|
|
508
|
-
|
|
509
|
-
**`See`**
|
|
510
|
-
|
|
511
|
-
https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent/waitUntil
|
|
512
|
-
|
|
513
|
-
**`Example`**
|
|
514
|
-
|
|
515
|
-
```js
|
|
516
|
-
import { waitUntil } from '@vercel/functions';
|
|
517
|
-
|
|
518
|
-
export function GET(request) {
|
|
519
|
-
waitUntil(fetch('https://vercel.com'));
|
|
520
|
-
return new Response('OK');
|
|
521
|
-
}
|
|
522
|
-
```
|
|
523
|
-
|
|
524
|
-
#### Parameters
|
|
525
|
-
|
|
526
|
-
| Name | Type | Description |
|
|
527
|
-
| :-------- | :---------------------------------------------------------------------------------------------------------------- | :----------------------- |
|
|
528
|
-
| `promise` | [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`unknown`\> | The promise to wait for. |
|
|
529
|
-
|
|
530
|
-
#### Returns
|
|
531
|
-
|
|
532
|
-
`undefined` \| `void`
|
|
533
|
-
|
|
534
|
-
#### Defined in
|
|
535
|
-
|
|
536
|
-
[packages/functions/src/wait-until.ts:19](https://github.com/vercel/vercel/blob/main/packages/functions/src/wait-until.ts#L19)
|
package/docs/modules/oidc.md
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
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
|
-
- [getVercelOidcTokenSync](oidc.md#getverceloidctokensync)
|
|
14
|
-
|
|
15
|
-
## Functions
|
|
16
|
-
|
|
17
|
-
### awsCredentialsProvider
|
|
18
|
-
|
|
19
|
-
▸ **awsCredentialsProvider**(`init`): `AwsCredentialIdentityProvider`
|
|
20
|
-
|
|
21
|
-
#### Parameters
|
|
22
|
-
|
|
23
|
-
| Name | Type |
|
|
24
|
-
| :----- | :------------------------------------------------------------------------------- |
|
|
25
|
-
| `init` | [`AwsCredentialsProviderInit`](../interfaces/oidc.AwsCredentialsProviderInit.md) |
|
|
26
|
-
|
|
27
|
-
#### Returns
|
|
28
|
-
|
|
29
|
-
`AwsCredentialIdentityProvider`
|
|
30
|
-
|
|
31
|
-
#### Defined in
|
|
32
|
-
|
|
33
|
-
[packages/functions/src/oidc/aws-credentials-provider.ts:70](https://github.com/vercel/vercel/blob/main/packages/functions/src/oidc/aws-credentials-provider.ts#L70)
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
### getVercelOidcToken
|
|
38
|
-
|
|
39
|
-
▸ **getVercelOidcToken**(`options?`): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\>
|
|
40
|
-
|
|
41
|
-
Gets the current OIDC token from the request context or the environment variable.
|
|
42
|
-
|
|
43
|
-
Do not cache this value, as it is subject to change in production!
|
|
44
|
-
|
|
45
|
-
This function is used to retrieve the OIDC token from the request context or the environment variable.
|
|
46
|
-
It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
|
|
47
|
-
|
|
48
|
-
Unlike the `getVercelOidcTokenSync` function, this function will refresh the token if it is expired in a development environment.
|
|
49
|
-
|
|
50
|
-
**`Throws`**
|
|
51
|
-
|
|
52
|
-
If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set. If the token
|
|
53
|
-
is expired in a development environment, will also throw an error if the token cannot be refreshed: no CLI credentials are available, CLI credentials are expired, no project configuration is available
|
|
54
|
-
or the token refresh request fails.
|
|
55
|
-
|
|
56
|
-
**`Example`**
|
|
57
|
-
|
|
58
|
-
```js
|
|
59
|
-
// Using the OIDC token
|
|
60
|
-
getVercelOidcToken()
|
|
61
|
-
.then(token => {
|
|
62
|
-
console.log('OIDC Token:', token);
|
|
63
|
-
})
|
|
64
|
-
.catch(error => {
|
|
65
|
-
console.error('Error:', error.message);
|
|
66
|
-
});
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
**`Example`**
|
|
70
|
-
|
|
71
|
-
```js
|
|
72
|
-
// Using the OIDC token with explicit team and project (supports IDs and slugs)
|
|
73
|
-
getVercelOidcToken({ team: 'my-team', project: 'my-project' })
|
|
74
|
-
.then(token => {
|
|
75
|
-
console.log('OIDC Token:', token);
|
|
76
|
-
})
|
|
77
|
-
.catch(error => {
|
|
78
|
-
console.error('Error:', error.message);
|
|
79
|
-
});
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
#### Parameters
|
|
83
|
-
|
|
84
|
-
| Name | Type | Description |
|
|
85
|
-
| :--------- | :-------------------------- | :------------------------------------------ |
|
|
86
|
-
| `options?` | `GetVercelOidcTokenOptions` | Optional configuration for token retrieval. |
|
|
87
|
-
|
|
88
|
-
#### Returns
|
|
89
|
-
|
|
90
|
-
[`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\>
|
|
91
|
-
|
|
92
|
-
A promise that resolves to the OIDC token.
|
|
93
|
-
|
|
94
|
-
#### Defined in
|
|
95
|
-
|
|
96
|
-
packages/oidc/dist/get-vercel-oidc-token.d.ts:60
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
### getVercelOidcTokenSync
|
|
101
|
-
|
|
102
|
-
▸ **getVercelOidcTokenSync**(): `string`
|
|
103
|
-
|
|
104
|
-
Gets the current OIDC token from the request context or the environment variable.
|
|
105
|
-
|
|
106
|
-
Do not cache this value, as it is subject to change in production!
|
|
107
|
-
|
|
108
|
-
This function is used to retrieve the OIDC token from the request context or the environment variable.
|
|
109
|
-
It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
|
|
110
|
-
|
|
111
|
-
This function will not refresh the token if it is expired. For refreshing the token, use the @{link getVercelOidcToken} function.
|
|
112
|
-
|
|
113
|
-
**`Throws`**
|
|
114
|
-
|
|
115
|
-
If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set.
|
|
116
|
-
|
|
117
|
-
**`Example`**
|
|
118
|
-
|
|
119
|
-
```js
|
|
120
|
-
// Using the OIDC token
|
|
121
|
-
const token = getVercelOidcTokenSync();
|
|
122
|
-
console.log('OIDC Token:', token);
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
#### Returns
|
|
126
|
-
|
|
127
|
-
`string`
|
|
128
|
-
|
|
129
|
-
The OIDC token.
|
|
130
|
-
|
|
131
|
-
#### Defined in
|
|
132
|
-
|
|
133
|
-
packages/oidc/dist/get-vercel-oidc-token.d.ts:82
|