@vercel/functions 1.2.0 → 1.4.0
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/README.md +60 -0
- package/dist/get-context.d.ts +7 -0
- package/dist/get-context.js +34 -0
- package/dist/get-env.d.ts +133 -0
- package/dist/get-env.js +162 -0
- package/dist/headers.d.ts +1 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/oidc/aws-credentials-provider.d.ts +57 -0
- package/dist/oidc/aws-credentials-provider.js +47 -0
- package/dist/oidc/get-vercel-oidc-token.d.ts +21 -0
- package/dist/oidc/get-vercel-oidc-token.js +39 -0
- package/dist/oidc/index.d.ts +3 -0
- package/dist/oidc/index.js +31 -0
- package/dist/wait-until.d.ts +0 -1
- package/dist/wait-until.js +2 -8
- package/package.json +26 -7
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
|
+
[](https://github.com/vercel/vercel/discussions)
|
|
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
|
+
```
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export declare const getEnv: (env?: {
|
|
2
|
+
[key: string]: string | undefined;
|
|
3
|
+
}) => {
|
|
4
|
+
/**
|
|
5
|
+
* An indicator to show that System Environment Variables have been exposed to your project's Deployments.
|
|
6
|
+
* @example "1"
|
|
7
|
+
*/
|
|
8
|
+
VERCEL: string | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* An indicator that the code is running in a Continuous Integration environment.
|
|
11
|
+
* @example "1"
|
|
12
|
+
*/
|
|
13
|
+
CI: string | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* The Environment that the app is deployed and running on.
|
|
16
|
+
* @example "production"
|
|
17
|
+
*/
|
|
18
|
+
VERCEL_ENV: string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The domain name of the generated deployment URL. The value does not include the protocol scheme https://.
|
|
21
|
+
* NOTE: This Variable cannot be used in conjunction with Standard Deployment Protection.
|
|
22
|
+
* @example "*.vercel.app"
|
|
23
|
+
*/
|
|
24
|
+
VERCEL_URL: string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* The domain name of the generated Git branch URL. The value does not include the protocol scheme https://.
|
|
27
|
+
* @example "*-git-*.vercel.app"
|
|
28
|
+
*/
|
|
29
|
+
VERCEL_BRANCH_URL: string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* A production domain name of the project. This is useful to reliably generate links that point to production such as OG-image URLs.
|
|
32
|
+
* The value does not include the protocol scheme https://.
|
|
33
|
+
* @example "myproject.vercel.app"
|
|
34
|
+
*/
|
|
35
|
+
VERCEL_PROJECT_PRODUCTION_URL: string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The ID of the Region where the app is running.
|
|
38
|
+
*
|
|
39
|
+
* Possible values:
|
|
40
|
+
* - arn1 (Stockholm, Sweden)
|
|
41
|
+
* - bom1 (Mumbai, India)
|
|
42
|
+
* - cdg1 (Paris, France)
|
|
43
|
+
* - cle1 (Cleveland, USA)
|
|
44
|
+
* - cpt1 (Cape Town, South Africa)
|
|
45
|
+
* - dub1 (Dublin, Ireland)
|
|
46
|
+
* - fra1 (Frankfurt, Germany)
|
|
47
|
+
* - gru1 (São Paulo, Brazil)
|
|
48
|
+
* - hkg1 (Hong Kong)
|
|
49
|
+
* - hnd1 (Tokyo, Japan)
|
|
50
|
+
* - iad1 (Washington, D.C., USA)
|
|
51
|
+
* - icn1 (Seoul, South Korea)
|
|
52
|
+
* - kix1 (Osaka, Japan)
|
|
53
|
+
* - lhr1 (London, United Kingdom)
|
|
54
|
+
* - pdx1 (Portland, USA)
|
|
55
|
+
* - sfo1 (San Francisco, USA)
|
|
56
|
+
* - sin1 (Singapore)
|
|
57
|
+
* - syd1 (Sydney, Australia)
|
|
58
|
+
* - dev1 (Development Region)
|
|
59
|
+
*
|
|
60
|
+
* @example "iad1"
|
|
61
|
+
*/
|
|
62
|
+
VERCEL_REGION: string | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* The unique identifier for the deployment, which can be used to implement Skew Protection.
|
|
65
|
+
* @example "dpl_7Gw5ZMBpQA8h9GF832KGp7nwbuh3"
|
|
66
|
+
*/
|
|
67
|
+
VERCEL_DEPLOYMENT_ID: string | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* When Skew Protection is enabled in Project Settings, this value is set to 1.
|
|
70
|
+
* @example "1"
|
|
71
|
+
*/
|
|
72
|
+
VERCEL_SKEW_PROTECTION_ENABLED: string | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* The Protection Bypass for Automation value, if the secret has been generated in the project's Deployment Protection settings.
|
|
75
|
+
*/
|
|
76
|
+
VERCEL_AUTOMATION_BYPASS_SECRET: string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* The Git Provider the deployment is triggered from.
|
|
79
|
+
* @example "github"
|
|
80
|
+
*/
|
|
81
|
+
VERCEL_GIT_PROVIDER: string | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* The origin repository the deployment is triggered from.
|
|
84
|
+
* @example "my-site"
|
|
85
|
+
*/
|
|
86
|
+
VERCEL_GIT_REPO_SLUG: string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* The account that owns the repository the deployment is triggered from.
|
|
89
|
+
* @example "acme"
|
|
90
|
+
*/
|
|
91
|
+
VERCEL_GIT_REPO_OWNER: string | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* The ID of the repository the deployment is triggered from.
|
|
94
|
+
* @example "117716146"
|
|
95
|
+
*/
|
|
96
|
+
VERCEL_GIT_REPO_ID: string | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* The git branch of the commit the deployment was triggered by.
|
|
99
|
+
* @example "improve-about-page"
|
|
100
|
+
*/
|
|
101
|
+
VERCEL_GIT_COMMIT_REF: string | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* The git SHA of the commit the deployment was triggered by.
|
|
104
|
+
* @example "fa1eade47b73733d6312d5abfad33ce9e4068081"
|
|
105
|
+
*/
|
|
106
|
+
VERCEL_GIT_COMMIT_SHA: string | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* The message attached to the commit the deployment was triggered by.
|
|
109
|
+
* @example "Update about page"
|
|
110
|
+
*/
|
|
111
|
+
VERCEL_GIT_COMMIT_MESSAGE: string | undefined;
|
|
112
|
+
/**
|
|
113
|
+
* The username attached to the author of the commit that the project was deployed by.
|
|
114
|
+
* @example "johndoe"
|
|
115
|
+
*/
|
|
116
|
+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: string | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* The name attached to the author of the commit that the project was deployed by.
|
|
119
|
+
* @example "John Doe"
|
|
120
|
+
*/
|
|
121
|
+
VERCEL_GIT_COMMIT_AUTHOR_NAME: string | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* The git SHA of the last successful deployment for the project and branch.
|
|
124
|
+
* NOTE: This Variable is only exposed when an Ignored Build Step is provided.
|
|
125
|
+
* @example "fa1eade47b73733d6312d5abfad33ce9e4068080"
|
|
126
|
+
*/
|
|
127
|
+
VERCEL_GIT_PREVIOUS_SHA: string | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* 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.
|
|
130
|
+
* @example "23"
|
|
131
|
+
*/
|
|
132
|
+
VERCEL_GIT_PULL_REQUEST_ID: string | undefined;
|
|
133
|
+
};
|
package/dist/get-env.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
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_env_exports = {};
|
|
20
|
+
__export(get_env_exports, {
|
|
21
|
+
getEnv: () => getEnv
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(get_env_exports);
|
|
24
|
+
const getEnv = (env = process.env) => ({
|
|
25
|
+
/**
|
|
26
|
+
* An indicator to show that System Environment Variables have been exposed to your project's Deployments.
|
|
27
|
+
* @example "1"
|
|
28
|
+
*/
|
|
29
|
+
VERCEL: get(env, "VERCEL"),
|
|
30
|
+
/**
|
|
31
|
+
* An indicator that the code is running in a Continuous Integration environment.
|
|
32
|
+
* @example "1"
|
|
33
|
+
*/
|
|
34
|
+
CI: get(env, "CI"),
|
|
35
|
+
/**
|
|
36
|
+
* The Environment that the app is deployed and running on.
|
|
37
|
+
* @example "production"
|
|
38
|
+
*/
|
|
39
|
+
VERCEL_ENV: get(env, "VERCEL_ENV"),
|
|
40
|
+
/**
|
|
41
|
+
* The domain name of the generated deployment URL. The value does not include the protocol scheme https://.
|
|
42
|
+
* NOTE: This Variable cannot be used in conjunction with Standard Deployment Protection.
|
|
43
|
+
* @example "*.vercel.app"
|
|
44
|
+
*/
|
|
45
|
+
VERCEL_URL: get(env, "VERCEL_URL"),
|
|
46
|
+
/**
|
|
47
|
+
* The domain name of the generated Git branch URL. The value does not include the protocol scheme https://.
|
|
48
|
+
* @example "*-git-*.vercel.app"
|
|
49
|
+
*/
|
|
50
|
+
VERCEL_BRANCH_URL: get(env, "VERCEL_BRANCH_URL"),
|
|
51
|
+
/**
|
|
52
|
+
* A production domain name of the project. This is useful to reliably generate links that point to production such as OG-image URLs.
|
|
53
|
+
* The value does not include the protocol scheme https://.
|
|
54
|
+
* @example "myproject.vercel.app"
|
|
55
|
+
*/
|
|
56
|
+
VERCEL_PROJECT_PRODUCTION_URL: get(env, "VERCEL_PROJECT_PRODUCTION_URL"),
|
|
57
|
+
/**
|
|
58
|
+
* The ID of the Region where the app is running.
|
|
59
|
+
*
|
|
60
|
+
* Possible values:
|
|
61
|
+
* - arn1 (Stockholm, Sweden)
|
|
62
|
+
* - bom1 (Mumbai, India)
|
|
63
|
+
* - cdg1 (Paris, France)
|
|
64
|
+
* - cle1 (Cleveland, USA)
|
|
65
|
+
* - cpt1 (Cape Town, South Africa)
|
|
66
|
+
* - dub1 (Dublin, Ireland)
|
|
67
|
+
* - fra1 (Frankfurt, Germany)
|
|
68
|
+
* - gru1 (São Paulo, Brazil)
|
|
69
|
+
* - hkg1 (Hong Kong)
|
|
70
|
+
* - hnd1 (Tokyo, Japan)
|
|
71
|
+
* - iad1 (Washington, D.C., USA)
|
|
72
|
+
* - icn1 (Seoul, South Korea)
|
|
73
|
+
* - kix1 (Osaka, Japan)
|
|
74
|
+
* - lhr1 (London, United Kingdom)
|
|
75
|
+
* - pdx1 (Portland, USA)
|
|
76
|
+
* - sfo1 (San Francisco, USA)
|
|
77
|
+
* - sin1 (Singapore)
|
|
78
|
+
* - syd1 (Sydney, Australia)
|
|
79
|
+
* - dev1 (Development Region)
|
|
80
|
+
*
|
|
81
|
+
* @example "iad1"
|
|
82
|
+
*/
|
|
83
|
+
VERCEL_REGION: get(env, "VERCEL_REGION"),
|
|
84
|
+
/**
|
|
85
|
+
* The unique identifier for the deployment, which can be used to implement Skew Protection.
|
|
86
|
+
* @example "dpl_7Gw5ZMBpQA8h9GF832KGp7nwbuh3"
|
|
87
|
+
*/
|
|
88
|
+
VERCEL_DEPLOYMENT_ID: get(env, "VERCEL_DEPLOYMENT_ID"),
|
|
89
|
+
/**
|
|
90
|
+
* When Skew Protection is enabled in Project Settings, this value is set to 1.
|
|
91
|
+
* @example "1"
|
|
92
|
+
*/
|
|
93
|
+
VERCEL_SKEW_PROTECTION_ENABLED: get(env, "VERCEL_SKEW_PROTECTION_ENABLED"),
|
|
94
|
+
/**
|
|
95
|
+
* The Protection Bypass for Automation value, if the secret has been generated in the project's Deployment Protection settings.
|
|
96
|
+
*/
|
|
97
|
+
VERCEL_AUTOMATION_BYPASS_SECRET: get(env, "VERCEL_AUTOMATION_BYPASS_SECRET"),
|
|
98
|
+
/**
|
|
99
|
+
* The Git Provider the deployment is triggered from.
|
|
100
|
+
* @example "github"
|
|
101
|
+
*/
|
|
102
|
+
VERCEL_GIT_PROVIDER: get(env, "VERCEL_GIT_PROVIDER"),
|
|
103
|
+
/**
|
|
104
|
+
* The origin repository the deployment is triggered from.
|
|
105
|
+
* @example "my-site"
|
|
106
|
+
*/
|
|
107
|
+
VERCEL_GIT_REPO_SLUG: get(env, "VERCEL_GIT_REPO_SLUG"),
|
|
108
|
+
/**
|
|
109
|
+
* The account that owns the repository the deployment is triggered from.
|
|
110
|
+
* @example "acme"
|
|
111
|
+
*/
|
|
112
|
+
VERCEL_GIT_REPO_OWNER: get(env, "VERCEL_GIT_REPO_OWNER"),
|
|
113
|
+
/**
|
|
114
|
+
* The ID of the repository the deployment is triggered from.
|
|
115
|
+
* @example "117716146"
|
|
116
|
+
*/
|
|
117
|
+
VERCEL_GIT_REPO_ID: get(env, "VERCEL_GIT_REPO_ID"),
|
|
118
|
+
/**
|
|
119
|
+
* The git branch of the commit the deployment was triggered by.
|
|
120
|
+
* @example "improve-about-page"
|
|
121
|
+
*/
|
|
122
|
+
VERCEL_GIT_COMMIT_REF: get(env, "VERCEL_GIT_COMMIT_REF"),
|
|
123
|
+
/**
|
|
124
|
+
* The git SHA of the commit the deployment was triggered by.
|
|
125
|
+
* @example "fa1eade47b73733d6312d5abfad33ce9e4068081"
|
|
126
|
+
*/
|
|
127
|
+
VERCEL_GIT_COMMIT_SHA: get(env, "VERCEL_GIT_COMMIT_SHA"),
|
|
128
|
+
/**
|
|
129
|
+
* The message attached to the commit the deployment was triggered by.
|
|
130
|
+
* @example "Update about page"
|
|
131
|
+
*/
|
|
132
|
+
VERCEL_GIT_COMMIT_MESSAGE: get(env, "VERCEL_GIT_COMMIT_MESSAGE"),
|
|
133
|
+
/**
|
|
134
|
+
* The username attached to the author of the commit that the project was deployed by.
|
|
135
|
+
* @example "johndoe"
|
|
136
|
+
*/
|
|
137
|
+
VERCEL_GIT_COMMIT_AUTHOR_LOGIN: get(env, "VERCEL_GIT_COMMIT_AUTHOR_LOGIN"),
|
|
138
|
+
/**
|
|
139
|
+
* The name attached to the author of the commit that the project was deployed by.
|
|
140
|
+
* @example "John Doe"
|
|
141
|
+
*/
|
|
142
|
+
VERCEL_GIT_COMMIT_AUTHOR_NAME: get(env, "VERCEL_GIT_COMMIT_AUTHOR_NAME"),
|
|
143
|
+
/**
|
|
144
|
+
* The git SHA of the last successful deployment for the project and branch.
|
|
145
|
+
* NOTE: This Variable is only exposed when an Ignored Build Step is provided.
|
|
146
|
+
* @example "fa1eade47b73733d6312d5abfad33ce9e4068080"
|
|
147
|
+
*/
|
|
148
|
+
VERCEL_GIT_PREVIOUS_SHA: get(env, "VERCEL_GIT_PREVIOUS_SHA"),
|
|
149
|
+
/**
|
|
150
|
+
* 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.
|
|
151
|
+
* @example "23"
|
|
152
|
+
*/
|
|
153
|
+
VERCEL_GIT_PULL_REQUEST_ID: get(env, "VERCEL_GIT_PULL_REQUEST_ID")
|
|
154
|
+
});
|
|
155
|
+
const get = (env, key) => {
|
|
156
|
+
const value = env[key];
|
|
157
|
+
return value === "" ? void 0 : value;
|
|
158
|
+
};
|
|
159
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
160
|
+
0 && (module.exports = {
|
|
161
|
+
getEnv
|
|
162
|
+
});
|
package/dist/headers.d.ts
CHANGED
|
@@ -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
|
};
|
|
@@ -80,4 +80,3 @@ export declare function ipAddress(request: Request): string | undefined;
|
|
|
80
80
|
* @param request The incoming request object which provides the geolocation data
|
|
81
81
|
*/
|
|
82
82
|
export declare function geolocation(request: Request): Geo;
|
|
83
|
-
export {};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -19,15 +19,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var src_exports = {};
|
|
20
20
|
__export(src_exports, {
|
|
21
21
|
geolocation: () => import_headers.geolocation,
|
|
22
|
+
getEnv: () => import_get_env.getEnv,
|
|
22
23
|
ipAddress: () => import_headers.ipAddress,
|
|
23
24
|
waitUntil: () => import_wait_until.waitUntil
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(src_exports);
|
|
26
27
|
var import_headers = require("./headers");
|
|
28
|
+
var import_get_env = require("./get-env");
|
|
27
29
|
var import_wait_until = require("./wait-until");
|
|
28
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
31
|
0 && (module.exports = {
|
|
30
32
|
geolocation,
|
|
33
|
+
getEnv,
|
|
31
34
|
ipAddress,
|
|
32
35
|
waitUntil
|
|
33
36
|
});
|
|
@@ -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
|
+
* ```javascript
|
|
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,21 @@
|
|
|
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
|
+
* @async
|
|
9
|
+
* @function
|
|
10
|
+
* @returns {Promise<string>} A promise that resolves to the OIDC token.
|
|
11
|
+
* @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
|
+
*
|
|
13
|
+
* @example
|
|
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
|
+
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,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/dist/wait-until.d.ts
CHANGED
package/dist/wait-until.js
CHANGED
|
@@ -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
|
-
|
|
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
|
});
|
package/package.json
CHANGED
|
@@ -3,13 +3,20 @@
|
|
|
3
3
|
"description": "Runtime functions to be used with your Vercel Functions",
|
|
4
4
|
"homepage": "https://vercel.com",
|
|
5
5
|
"exports": {
|
|
6
|
-
".":
|
|
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
|
+
}
|
|
7
14
|
},
|
|
8
15
|
"files": [
|
|
9
16
|
"dist"
|
|
10
17
|
],
|
|
11
18
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"version": "1.
|
|
19
|
+
"version": "1.4.0",
|
|
13
20
|
"repository": {
|
|
14
21
|
"directory": "packages/functions",
|
|
15
22
|
"type": "git",
|
|
@@ -19,12 +26,23 @@
|
|
|
19
26
|
"url": "https://github.com/vercel/vercel/issues"
|
|
20
27
|
},
|
|
21
28
|
"devDependencies": {
|
|
29
|
+
"@aws-sdk/client-s3": "3.609.0",
|
|
30
|
+
"@aws-sdk/credential-provider-web-identity": "3.609.0",
|
|
31
|
+
"@smithy/types": "3.3.0",
|
|
22
32
|
"tinyspawn": "1.3.1",
|
|
23
33
|
"typedoc": "0.24.6",
|
|
24
|
-
"typedoc-plugin-markdown": "
|
|
25
|
-
"typedoc-plugin-mdn-links": "3.
|
|
34
|
+
"typedoc-plugin-markdown": "4.1.2",
|
|
35
|
+
"typedoc-plugin-mdn-links": "3.2.3",
|
|
26
36
|
"typescript": "4.9.5",
|
|
27
|
-
"vitest": "
|
|
37
|
+
"vitest": "2.0.1"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@aws-sdk/credential-provider-web-identity": "*"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"@aws-sdk/credential-provider-web-identity": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
28
46
|
},
|
|
29
47
|
"engines": {
|
|
30
48
|
"node": ">= 16"
|
|
@@ -34,9 +52,10 @@
|
|
|
34
52
|
"access": "public"
|
|
35
53
|
},
|
|
36
54
|
"scripts": {
|
|
37
|
-
"pretest": "pnpm run build",
|
|
55
|
+
"pretest": "pnpm run build:code",
|
|
38
56
|
"test": "vitest",
|
|
39
|
-
"build": "
|
|
57
|
+
"build": "pnpm run build:code && pnpm run build:docs",
|
|
58
|
+
"build:code": "node ../../utils/build.mjs",
|
|
40
59
|
"build:docs": "typedoc && prettier --write docs/**/*.md docs/*.md"
|
|
41
60
|
}
|
|
42
61
|
}
|