@vercel/functions 2.2.7 → 2.2.11
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 +27 -0
- package/db-connections/index.d.ts +6 -2
- package/db-connections/index.js +4 -1
- package/docs/modules/index.md +28 -3
- package/docs/modules/oidc.md +6 -33
- package/index.d.ts +1 -1
- package/index.js +2 -0
- package/oidc/aws-credentials-provider.d.ts +0 -37
- package/oidc/aws-credentials-provider.js +10 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @vercel/functions
|
|
2
2
|
|
|
3
|
+
## 2.2.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix dependency ([#13726](https://github.com/vercel/vercel/pull/13726))
|
|
8
|
+
|
|
9
|
+
## 2.2.10
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Update dependency ([#13722](https://github.com/vercel/vercel/pull/13722))
|
|
14
|
+
|
|
15
|
+
## 2.2.9
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Extract AWS dynamic import to async loader with error handling ([#13660](https://github.com/vercel/vercel/pull/13660))
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [[`a133e534e7dfd785beeeb0dcafed8d2c991e9f11`](https://github.com/vercel/vercel/commit/a133e534e7dfd785beeeb0dcafed8d2c991e9f11)]:
|
|
22
|
+
- @vercel/oidc@2.1.0
|
|
23
|
+
|
|
24
|
+
## 2.2.8
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- Declare attachDatabasePool stable ([#13673](https://github.com/vercel/vercel/pull/13673))
|
|
29
|
+
|
|
3
30
|
## 2.2.7
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
|
@@ -72,10 +72,14 @@ export type DbPool = PgPool | MySQLPool | MySQL2Pool | MariaDBPool | MongoDBPool
|
|
|
72
72
|
* const pgPool = new Pool({
|
|
73
73
|
* connectionString: process.env.DATABASE_URL,
|
|
74
74
|
* });
|
|
75
|
-
*
|
|
75
|
+
* attachDatabasePool(pgPool);
|
|
76
76
|
* ```
|
|
77
77
|
*
|
|
78
78
|
* @experimental
|
|
79
79
|
*/
|
|
80
|
-
export declare function
|
|
80
|
+
export declare function attachDatabasePool(dbPool: DbPool): void;
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Use attachDatabasePool instead.
|
|
83
|
+
*/
|
|
84
|
+
export declare const experimental_attachDatabasePool: typeof attachDatabasePool;
|
|
81
85
|
export {};
|
package/db-connections/index.js
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var db_connections_exports = {};
|
|
20
20
|
__export(db_connections_exports, {
|
|
21
|
+
attachDatabasePool: () => attachDatabasePool,
|
|
21
22
|
experimental_attachDatabasePool: () => experimental_attachDatabasePool
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(db_connections_exports);
|
|
@@ -87,7 +88,7 @@ function waitUntilIdleTimeout(dbPool) {
|
|
|
87
88
|
console.warn("Pool release event triggered outside of request scope.");
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
function
|
|
91
|
+
function attachDatabasePool(dbPool) {
|
|
91
92
|
if (idleTimeout) {
|
|
92
93
|
idleTimeoutResolve?.();
|
|
93
94
|
clearTimeout(idleTimeout);
|
|
@@ -142,7 +143,9 @@ function experimental_attachDatabasePool(dbPool) {
|
|
|
142
143
|
}
|
|
143
144
|
throw new Error("Unsupported database pool type");
|
|
144
145
|
}
|
|
146
|
+
const experimental_attachDatabasePool = attachDatabasePool;
|
|
145
147
|
// Annotate the CommonJS export names for ESM import in node:
|
|
146
148
|
0 && (module.exports = {
|
|
149
|
+
attachDatabasePool,
|
|
147
150
|
experimental_attachDatabasePool
|
|
148
151
|
});
|
package/docs/modules/index.md
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
### Functions
|
|
12
12
|
|
|
13
|
+
- [attachDatabasePool](index.md#attachdatabasepool)
|
|
13
14
|
- [experimental_attachDatabasePool](index.md#experimental_attachdatabasepool)
|
|
14
15
|
- [geolocation](index.md#geolocation)
|
|
15
16
|
- [getCache](index.md#getcache)
|
|
@@ -21,9 +22,9 @@
|
|
|
21
22
|
|
|
22
23
|
## Functions
|
|
23
24
|
|
|
24
|
-
###
|
|
25
|
+
### attachDatabasePool
|
|
25
26
|
|
|
26
|
-
▸ **
|
|
27
|
+
▸ **attachDatabasePool**(`dbPool`): `void`
|
|
27
28
|
|
|
28
29
|
Call this function right after creating a database pool with the database pool object
|
|
29
30
|
as argument.
|
|
@@ -36,7 +37,7 @@ idle database connections to be removed from the pool.
|
|
|
36
37
|
const pgPool = new Pool({
|
|
37
38
|
connectionString: process.env.DATABASE_URL,
|
|
38
39
|
});
|
|
39
|
-
|
|
40
|
+
attachDatabasePool(pgPool);
|
|
40
41
|
```
|
|
41
42
|
|
|
42
43
|
#### Parameters
|
|
@@ -55,6 +56,30 @@ experimental_attachDatabasePool(pgPool);
|
|
|
55
56
|
|
|
56
57
|
---
|
|
57
58
|
|
|
59
|
+
### experimental_attachDatabasePool
|
|
60
|
+
|
|
61
|
+
▸ **experimental_attachDatabasePool**(`dbPool`): `void`
|
|
62
|
+
|
|
63
|
+
**`Deprecated`**
|
|
64
|
+
|
|
65
|
+
Use attachDatabasePool instead.
|
|
66
|
+
|
|
67
|
+
#### Parameters
|
|
68
|
+
|
|
69
|
+
| Name | Type |
|
|
70
|
+
| :------- | :------- |
|
|
71
|
+
| `dbPool` | `DbPool` |
|
|
72
|
+
|
|
73
|
+
#### Returns
|
|
74
|
+
|
|
75
|
+
`void`
|
|
76
|
+
|
|
77
|
+
#### Defined in
|
|
78
|
+
|
|
79
|
+
[packages/functions/src/db-connections/index.ts:221](https://github.com/vercel/vercel/blob/main/packages/functions/src/db-connections/index.ts#L221)
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
58
83
|
### geolocation
|
|
59
84
|
|
|
60
85
|
▸ **geolocation**(`request`): [`Geo`](../interfaces/index.Geo.md)
|
package/docs/modules/oidc.md
CHANGED
|
@@ -18,46 +18,19 @@
|
|
|
18
18
|
|
|
19
19
|
▸ **awsCredentialsProvider**(`init`): `AwsCredentialIdentityProvider`
|
|
20
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
|
-
**`Example`**
|
|
25
|
-
|
|
26
|
-
```js
|
|
27
|
-
import * as s3 from '@aws-sdk/client-s3';
|
|
28
|
-
import { awsCredentialsProvider } from '@vercel/functions/oidc';
|
|
29
|
-
|
|
30
|
-
const s3Client = new s3.S3Client({
|
|
31
|
-
credentials: awsCredentialsProvider({
|
|
32
|
-
roleArn: 'arn:aws:iam::1234567890:role/RoleA',
|
|
33
|
-
clientConfig: { region: 'us-west-2' },
|
|
34
|
-
clientPlugins: [addFooHeadersPlugin],
|
|
35
|
-
roleAssumerWithWebIdentity: customRoleAssumer,
|
|
36
|
-
roleSessionName: 'session_123',
|
|
37
|
-
providerId: 'graph.facebook.com',
|
|
38
|
-
policyArns: [{ arn: 'arn:aws:iam::1234567890:policy/SomePolicy' }],
|
|
39
|
-
policy:
|
|
40
|
-
'{"Statement": [{"Effect": "Allow", "Action": "s3:ListBucket", "Resource": "*"}]}',
|
|
41
|
-
durationSeconds: 7200,
|
|
42
|
-
}),
|
|
43
|
-
});
|
|
44
|
-
```
|
|
45
|
-
|
|
46
21
|
#### Parameters
|
|
47
22
|
|
|
48
|
-
| Name | Type |
|
|
49
|
-
| :----- | :------------------------------------------------------------------------------- |
|
|
50
|
-
| `init` | [`AwsCredentialsProviderInit`](../interfaces/oidc.AwsCredentialsProviderInit.md) |
|
|
23
|
+
| Name | Type |
|
|
24
|
+
| :----- | :------------------------------------------------------------------------------- |
|
|
25
|
+
| `init` | [`AwsCredentialsProviderInit`](../interfaces/oidc.AwsCredentialsProviderInit.md) |
|
|
51
26
|
|
|
52
27
|
#### Returns
|
|
53
28
|
|
|
54
29
|
`AwsCredentialIdentityProvider`
|
|
55
30
|
|
|
56
|
-
A function that provides AWS credentials.
|
|
57
|
-
|
|
58
31
|
#### Defined in
|
|
59
32
|
|
|
60
|
-
[packages/functions/src/oidc/aws-credentials-provider.ts:
|
|
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)
|
|
61
34
|
|
|
62
35
|
---
|
|
63
36
|
|
|
@@ -97,7 +70,7 @@ A promise that resolves to the OIDC token.
|
|
|
97
70
|
|
|
98
71
|
#### Defined in
|
|
99
72
|
|
|
100
|
-
|
|
73
|
+
node_modules/.pnpm/@vercel+oidc@2.0.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.d.ts:23
|
|
101
74
|
|
|
102
75
|
---
|
|
103
76
|
|
|
@@ -132,4 +105,4 @@ The OIDC token.
|
|
|
132
105
|
|
|
133
106
|
#### Defined in
|
|
134
107
|
|
|
135
|
-
|
|
108
|
+
node_modules/.pnpm/@vercel+oidc@2.0.0/node_modules/@vercel/oidc/dist/get-vercel-oidc-token.d.ts:43
|
package/index.d.ts
CHANGED
|
@@ -4,5 +4,5 @@ export { getEnv } from './get-env';
|
|
|
4
4
|
export { waitUntil } from './wait-until';
|
|
5
5
|
export { rewrite, next } from './middleware';
|
|
6
6
|
export { getCache } from './cache';
|
|
7
|
-
export { experimental_attachDatabasePool } from './db-connections';
|
|
7
|
+
export { attachDatabasePool, experimental_attachDatabasePool, } from './db-connections';
|
|
8
8
|
export type { RuntimeCache } from './cache/types';
|
package/index.js
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var src_exports = {};
|
|
20
20
|
__export(src_exports, {
|
|
21
|
+
attachDatabasePool: () => import_db_connections.attachDatabasePool,
|
|
21
22
|
experimental_attachDatabasePool: () => import_db_connections.experimental_attachDatabasePool,
|
|
22
23
|
geolocation: () => import_headers.geolocation,
|
|
23
24
|
getCache: () => import_cache.getCache,
|
|
@@ -36,6 +37,7 @@ var import_cache = require("./cache");
|
|
|
36
37
|
var import_db_connections = require("./db-connections");
|
|
37
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
39
|
0 && (module.exports = {
|
|
40
|
+
attachDatabasePool,
|
|
39
41
|
experimental_attachDatabasePool,
|
|
40
42
|
geolocation,
|
|
41
43
|
getCache,
|
|
@@ -17,41 +17,4 @@ import type { FromWebTokenInit } from '@aws-sdk/credential-provider-web-identity
|
|
|
17
17
|
export interface AwsCredentialsProviderInit// eslint-disable-line @typescript-eslint/no-empty-interface
|
|
18
18
|
extends Omit<FromWebTokenInit, 'webIdentityToken'> {
|
|
19
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
20
|
export declare function awsCredentialsProvider(init: AwsCredentialsProviderInit): AwsCredentialIdentityProvider;
|
|
@@ -32,9 +32,18 @@ __export(aws_credentials_provider_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(aws_credentials_provider_exports);
|
|
34
34
|
var import_oidc = require("@vercel/oidc");
|
|
35
|
+
async function loadAwsCredentialProviderWebIdentity() {
|
|
36
|
+
try {
|
|
37
|
+
return await import("@aws-sdk/credential-provider-web-identity");
|
|
38
|
+
} catch (err) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"package '@aws-sdk/credential-provider-web-identity' not found"
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
35
44
|
function awsCredentialsProvider(init) {
|
|
36
45
|
return async () => {
|
|
37
|
-
const { fromWebToken } = await
|
|
46
|
+
const { fromWebToken } = await loadAwsCredentialProviderWebIdentity();
|
|
38
47
|
return fromWebToken({
|
|
39
48
|
...init,
|
|
40
49
|
webIdentityToken: (0, import_oidc.getVercelOidcTokenSync)()
|