@vercel/functions 1.3.0 → 1.4.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 ADDED
@@ -0,0 +1,49 @@
1
+ # @vercel/functions
2
+
3
+ ## 1.4.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Package files in the root folder ([#11982](https://github.com/vercel/vercel/pull/11982))
8
+
9
+ ## 1.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Added OIDC Token utility functions ([#11701](https://github.com/vercel/vercel/pull/11701))
14
+
15
+ ## 1.3.0
16
+
17
+ ### Minor Changes
18
+
19
+ - [functions] add `getEnv` method. ([#11783](https://github.com/vercel/vercel/pull/11783))
20
+
21
+ ## 1.2.0
22
+
23
+ ### Minor Changes
24
+
25
+ - Add `geolocation` & `ipAdress` methods. ([#11802](https://github.com/vercel/vercel/pull/11802))
26
+
27
+ ## 1.1.0
28
+
29
+ ### Minor Changes
30
+
31
+ - Rewrite `@vercel/functions` to TypeScript ([#11791](https://github.com/vercel/vercel/pull/11791))
32
+
33
+ ## 1.0.2
34
+
35
+ ### Patch Changes
36
+
37
+ - Convert package to CommonJS ([#11569](https://github.com/vercel/vercel/pull/11569))
38
+
39
+ ## 1.0.1
40
+
41
+ ### Patch Changes
42
+
43
+ - Don't throw error if context is missing ([`0817527f9`](https://github.com/vercel/vercel/commit/0817527f9e9d0d5fceb73f21e695089349a96d3e))
44
+
45
+ ## 1.0.0
46
+
47
+ ### Major Changes
48
+
49
+ - Initial release ([#11553](https://github.com/vercel/vercel/pull/11553))
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ <p align="center">
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>
8
+
9
+ [Join the Vercel Community](https://vercel.community/)
10
+
11
+ ## OIDC Support Functions
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
+ ```
package/docs/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # @vercel/functions
2
+
3
+ ## Table of contents
4
+
5
+ ### Modules
6
+
7
+ - [index](modules/index.md)
8
+ - [oidc](modules/oidc.md)
@@ -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(payload);
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:158](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L158)
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:111](https://github.com/vercel/vercel/blob/main/packages/functions/src/headers.ts#L111)
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)
@@ -0,0 +1,7 @@
1
+ type Context = {
2
+ waitUntil?: (promise: Promise<unknown>) => void;
3
+ headers?: Record<string, string>;
4
+ };
5
+ export declare const SYMBOL_FOR_REQ_CONTEXT: unique symbol;
6
+ export declare function getContext(): Context;
7
+ export {};
package/get-context.js ADDED
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var get_context_exports = {};
20
+ __export(get_context_exports, {
21
+ SYMBOL_FOR_REQ_CONTEXT: () => SYMBOL_FOR_REQ_CONTEXT,
22
+ getContext: () => getContext
23
+ });
24
+ module.exports = __toCommonJS(get_context_exports);
25
+ const SYMBOL_FOR_REQ_CONTEXT = Symbol.for("@vercel/request-context");
26
+ function getContext() {
27
+ const fromSymbol = globalThis;
28
+ return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
29
+ }
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ SYMBOL_FOR_REQ_CONTEXT,
33
+ getContext
34
+ });
@@ -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
  }) => {
@@ -36,7 +36,7 @@ export declare const EMOJI_FLAG_UNICODE_STARTING_POSITION = 127397;
36
36
  * We define a new type so this function can be reused with
37
37
  * the global `Request`, `node-fetch` and other types.
38
38
  */
39
- interface Request {
39
+ export interface Request {
40
40
  headers: {
41
41
  get(name: string): string | null;
42
42
  };
@@ -65,19 +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(payload);
109
+ * }
110
+ * ```
81
111
  */
82
112
  export declare function geolocation(request: Request): Geo;
83
- export {};
@@ -1,3 +1,4 @@
1
+ export type { Request, Geo } from './headers';
1
2
  export { geolocation, ipAddress } from './headers';
2
3
  export { getEnv } from './get-env';
3
4
  export { waitUntil } from './wait-until';
@@ -0,0 +1,57 @@
1
+ import type { AwsCredentialIdentityProvider } from '@smithy/types';
2
+ import type { FromWebTokenInit } from '@aws-sdk/credential-provider-web-identity';
3
+ /**
4
+ * The init object for the `awsCredentialsProvider` function.
5
+ *
6
+ * @typedef {Object} AwsCredentialsProviderInit
7
+ * @property {string} roleArn - ARN of the role that the caller is assuming.
8
+ * @property {Object} [clientConfig] - Custom STS client configurations overriding the default ones.
9
+ * @property {Array} [clientPlugins] - Custom STS client middleware plugin to modify the client default behavior.
10
+ * @property {Function} [roleAssumerWithWebIdentity] - A function that assumes a role with web identity and returns a promise fulfilled with credentials for the assumed role.
11
+ * @property {string} [roleSessionName] - An identifier for the assumed role session.
12
+ * @property {string} [providerId] - The fully qualified host component of the domain name of the identity provider.
13
+ * @property {Array} [policyArns] - ARNs of the IAM managed policies that you want to use as managed session policies.
14
+ * @property {string} [policy] - An IAM policy in JSON format that you want to use as an inline session policy.
15
+ * @property {number} [durationSeconds=3600] - The duration, in seconds, of the role session. Defaults to 3600 seconds.
16
+ */
17
+ export interface AwsCredentialsProviderInit// eslint-disable-line @typescript-eslint/no-empty-interface
18
+ extends Omit<FromWebTokenInit, 'webIdentityToken'> {
19
+ }
20
+ /**
21
+ * Obtains the Vercel OIDC token and creates an AWS credential provider function
22
+ * that gets AWS credentials by calling STS AssumeRoleWithWebIdentity API.
23
+ *
24
+ * @param {AwsCredentialsProviderInit} init - The initialization object.
25
+ * @param {string} init.roleArn - ARN of the role that the caller is assuming.
26
+ * @param {Object} [init.clientConfig] - Custom STS client configurations overriding the default ones.
27
+ * @param {Array} [init.clientPlugins] - Custom STS client middleware plugin to modify the client default behavior.
28
+ * @param {Function} [init.roleAssumerWithWebIdentity] - A function that assumes a role with web identity and returns a promise fulfilled with credentials for the assumed role.
29
+ * @param {string} [init.roleSessionName] - An identifier for the assumed role session.
30
+ * @param {string} [init.providerId] - The fully qualified host component of the domain name of the identity provider.
31
+ * @param {Array} [init.policyArns] - ARNs of the IAM managed policies that you want to use as managed session policies.
32
+ * @param {string} [init.policy] - An IAM policy in JSON format that you want to use as an inline session policy.
33
+ * @param {number} [init.durationSeconds=3600] - The duration, in seconds, of the role session. Defaults to 3600 seconds.
34
+ *
35
+ * @returns {AwsCredentialIdentityProvider} A function that provides AWS credentials.
36
+ *
37
+ * @example
38
+ * ```js
39
+ * import * as s3 from '@aws-sdk/client-s3';
40
+ * import { awsCredentialsProvider } from '@vercel/functions/oidc';
41
+ *
42
+ * const s3Client = new s3.S3Client({
43
+ * credentials: awsCredentialsProvider({
44
+ * roleArn: "arn:aws:iam::1234567890:role/RoleA",
45
+ * clientConfig: { region: "us-west-2" },
46
+ * clientPlugins: [addFooHeadersPlugin],
47
+ * roleAssumerWithWebIdentity: customRoleAssumer,
48
+ * roleSessionName: "session_123",
49
+ * providerId: "graph.facebook.com",
50
+ * policyArns: [{ arn: "arn:aws:iam::1234567890:policy/SomePolicy" }],
51
+ * policy: "{\"Statement\": [{\"Effect\": \"Allow\", \"Action\": \"s3:ListBucket\", \"Resource\": \"*\"}]}",
52
+ * durationSeconds: 7200
53
+ * }),
54
+ * });
55
+ * ```
56
+ */
57
+ export declare function awsCredentialsProvider(init: AwsCredentialsProviderInit): AwsCredentialIdentityProvider;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var aws_credentials_provider_exports = {};
30
+ __export(aws_credentials_provider_exports, {
31
+ awsCredentialsProvider: () => awsCredentialsProvider
32
+ });
33
+ module.exports = __toCommonJS(aws_credentials_provider_exports);
34
+ var import_get_vercel_oidc_token = require("./get-vercel-oidc-token");
35
+ function awsCredentialsProvider(init) {
36
+ return async () => {
37
+ const { fromWebToken } = await import("@aws-sdk/credential-provider-web-identity");
38
+ return fromWebToken({
39
+ ...init,
40
+ webIdentityToken: await (0, import_get_vercel_oidc_token.getVercelOidcToken)()
41
+ })();
42
+ };
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ awsCredentialsProvider
47
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Returns the OIDC token from the request context or the environment variable.
3
+ *
4
+ * This function first checks if the OIDC token is available in the environment variable
5
+ * `VERCEL_OIDC_TOKEN`. If it is not found there, it retrieves the token from the request
6
+ * context headers.
7
+ *
8
+ * @returns {Promise<string>} A promise that resolves to the OIDC token.
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.
10
+ *
11
+ * @example
12
+ *
13
+ * ```js
14
+ * // Using the OIDC token
15
+ * getVercelOidcToken().then((token) => {
16
+ * console.log('OIDC Token:', token);
17
+ * }).catch((error) => {
18
+ * console.error('Error:', error.message);
19
+ * });
20
+ * ```
21
+ */
22
+ export declare function getVercelOidcToken(): Promise<string>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var get_vercel_oidc_token_exports = {};
20
+ __export(get_vercel_oidc_token_exports, {
21
+ getVercelOidcToken: () => getVercelOidcToken
22
+ });
23
+ module.exports = __toCommonJS(get_vercel_oidc_token_exports);
24
+ var import_get_context = require("../get-context");
25
+ async function getVercelOidcToken() {
26
+ if (process.env.VERCEL_OIDC_TOKEN)
27
+ return process.env.VERCEL_OIDC_TOKEN;
28
+ const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"];
29
+ if (!token) {
30
+ throw new Error(
31
+ `The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
32
+ );
33
+ }
34
+ return token;
35
+ }
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ getVercelOidcToken
39
+ });
@@ -0,0 +1,3 @@
1
+ export type { AwsCredentialsProviderInit } from './aws-credentials-provider';
2
+ export { awsCredentialsProvider } from './aws-credentials-provider';
3
+ export { getVercelOidcToken } from './get-vercel-oidc-token';
package/oidc/index.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var oidc_exports = {};
20
+ __export(oidc_exports, {
21
+ awsCredentialsProvider: () => import_aws_credentials_provider.awsCredentialsProvider,
22
+ getVercelOidcToken: () => import_get_vercel_oidc_token.getVercelOidcToken
23
+ });
24
+ module.exports = __toCommonJS(oidc_exports);
25
+ var import_aws_credentials_provider = require("./aws-credentials-provider");
26
+ var import_get_vercel_oidc_token = require("./get-vercel-oidc-token");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ awsCredentialsProvider,
30
+ getVercelOidcToken
31
+ });
package/package.json CHANGED
@@ -2,14 +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
- ".": "./dist/index.js"
7
- },
8
5
  "files": [
9
- "dist"
6
+ "**/*.js",
7
+ "**/*.d.ts",
8
+ "**/*.md"
10
9
  ],
11
- "types": "./dist/index.d.ts",
12
- "version": "1.3.0",
10
+ "main": "./index.js",
11
+ "types": "./index.d.ts",
12
+ "version": "1.4.1",
13
13
  "repository": {
14
14
  "directory": "packages/functions",
15
15
  "type": "git",
@@ -19,12 +19,23 @@
19
19
  "url": "https://github.com/vercel/vercel/issues"
20
20
  },
21
21
  "devDependencies": {
22
+ "@aws-sdk/client-s3": "3.609.0",
23
+ "@aws-sdk/credential-provider-web-identity": "3.609.0",
24
+ "@smithy/types": "3.3.0",
22
25
  "tinyspawn": "1.3.1",
23
26
  "typedoc": "0.24.6",
24
- "typedoc-plugin-markdown": "3.15.2",
25
- "typedoc-plugin-mdn-links": "3.0.3",
27
+ "typedoc-plugin-markdown": "4.1.2",
28
+ "typedoc-plugin-mdn-links": "3.2.3",
26
29
  "typescript": "4.9.5",
27
- "vitest": "1.3.1"
30
+ "vitest": "2.0.1"
31
+ },
32
+ "peerDependencies": {
33
+ "@aws-sdk/credential-provider-web-identity": "*"
34
+ },
35
+ "peerDependenciesMeta": {
36
+ "@aws-sdk/credential-provider-web-identity": {
37
+ "optional": true
38
+ }
28
39
  },
29
40
  "engines": {
30
41
  "node": ">= 16"
@@ -34,9 +45,10 @@
34
45
  "access": "public"
35
46
  },
36
47
  "scripts": {
37
- "pretest": "pnpm run build",
48
+ "pretest": "pnpm run build:code",
38
49
  "test": "vitest",
39
- "build": "node ../../utils/build.mjs",
50
+ "build": "pnpm run build:code && pnpm run build:docs",
51
+ "build:code": "node ../../utils/build.mjs",
40
52
  "build:docs": "typedoc && prettier --write docs/**/*.md docs/*.md"
41
53
  }
42
54
  }
@@ -1,4 +1,3 @@
1
- export declare const SYMBOL_FOR_REQ_CONTEXT: unique symbol;
2
1
  /**
3
2
  * Extends the lifetime of the request handler for the lifetime of the given {@link Promise}
4
3
  * @see https://developer.mozilla.org/en-US/docs/Web/API/ExtendableEvent/waitUntil
@@ -6,7 +5,7 @@ export declare const SYMBOL_FOR_REQ_CONTEXT: unique symbol;
6
5
  * @param promise The promise to wait for.
7
6
  * @example
8
7
  *
9
- * ```
8
+ * ```js
10
9
  * import { waitUntil } from '@vercel/functions';
11
10
  *
12
11
  * export function GET(request) {
@@ -18,25 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var wait_until_exports = {};
20
20
  __export(wait_until_exports, {
21
- SYMBOL_FOR_REQ_CONTEXT: () => SYMBOL_FOR_REQ_CONTEXT,
22
21
  waitUntil: () => waitUntil
23
22
  });
24
23
  module.exports = __toCommonJS(wait_until_exports);
25
- const SYMBOL_FOR_REQ_CONTEXT = Symbol.for("@vercel/request-context");
24
+ var import_get_context = require("./get-context");
26
25
  const waitUntil = (promise) => {
27
26
  if (promise === null || typeof promise !== "object" || typeof promise.then !== "function") {
28
27
  throw new TypeError(
29
28
  `waitUntil can only be called with a Promise, got ${typeof promise}`
30
29
  );
31
30
  }
32
- return getContext().waitUntil?.(promise);
31
+ return (0, import_get_context.getContext)().waitUntil?.(promise);
33
32
  };
34
- function getContext() {
35
- const fromSymbol = globalThis;
36
- return fromSymbol[SYMBOL_FOR_REQ_CONTEXT]?.get?.() ?? {};
37
- }
38
33
  // Annotate the CommonJS export names for ESM import in node:
39
34
  0 && (module.exports = {
40
- SYMBOL_FOR_REQ_CONTEXT,
41
35
  waitUntil
42
36
  });
File without changes
File without changes
File without changes