@vercel/functions 2.0.3 → 2.2.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @vercel/functions
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Introduce `getVercelOidcTokenSync` ([#13429](https://github.com/vercel/vercel/pull/13429))
8
+
9
+ ## 2.1.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Change the load order of the OIDC token ([#13337](https://github.com/vercel/vercel/pull/13337))
14
+
15
+ ### Patch Changes
16
+
17
+ - Rename getRuntimeCache to getCache ([#13325](https://github.com/vercel/vercel/pull/13325))
18
+
3
19
  ## 2.0.3
4
20
 
5
21
  ### Patch Changes
package/cache/index.d.ts CHANGED
@@ -13,4 +13,4 @@ import { CacheOptions, RuntimeCache } from './types';
13
13
  * @returns An instance of the Vercel Runtime Cache.
14
14
  * @throws {Error} If no cache is available in the context and `InMemoryCache` cannot be created.
15
15
  */
16
- export declare const getRuntimeCache: (cacheOptions?: CacheOptions) => RuntimeCache;
16
+ export declare const getCache: (cacheOptions?: CacheOptions) => RuntimeCache;
package/cache/index.js CHANGED
@@ -18,7 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var cache_exports = {};
20
20
  __export(cache_exports, {
21
- getRuntimeCache: () => getRuntimeCache
21
+ getCache: () => getCache
22
22
  });
23
23
  module.exports = __toCommonJS(cache_exports);
24
24
  var import_get_context = require("../get-context");
@@ -32,7 +32,7 @@ const defaultKeyHashFunction = (key) => {
32
32
  };
33
33
  const defaultNamespaceSeparator = "$";
34
34
  let inMemoryCacheInstance = null;
35
- const getRuntimeCache = (cacheOptions) => {
35
+ const getCache = (cacheOptions) => {
36
36
  let cache;
37
37
  if ((0, import_get_context.getContext)().cache) {
38
38
  cache = (0, import_get_context.getContext)().cache;
@@ -68,5 +68,5 @@ const getRuntimeCache = (cacheOptions) => {
68
68
  };
69
69
  // Annotate the CommonJS export names for ESM import in node:
70
70
  0 && (module.exports = {
71
- getRuntimeCache
71
+ getCache
72
72
  });
@@ -40,7 +40,7 @@ Omit.clientConfig
40
40
 
41
41
  #### Defined in
42
42
 
43
- node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.803.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:135
43
+ node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.806.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:135
44
44
 
45
45
  ---
46
46
 
@@ -56,7 +56,7 @@ Omit.clientPlugins
56
56
 
57
57
  #### Defined in
58
58
 
59
- node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.803.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:139
59
+ node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.806.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:139
60
60
 
61
61
  ---
62
62
 
@@ -202,7 +202,7 @@ Omit.roleAssumerWithWebIdentity
202
202
 
203
203
  #### Defined in
204
204
 
205
- node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.803.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:130
205
+ node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.806.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:130
206
206
 
207
207
  ---
208
208
 
@@ -218,4 +218,4 @@ Omit.roleSessionName
218
218
 
219
219
  #### Defined in
220
220
 
221
- node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.803.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:123
221
+ node*modules/.pnpm/@aws-sdk+credential-provider-web-identity@3.609.0*@aws-sdk+client-sts@3.806.0/node_modules/@aws-sdk/credential-provider-web-identity/dist-types/fromWebToken.d.ts:123
@@ -11,8 +11,8 @@
11
11
  ### Functions
12
12
 
13
13
  - [geolocation](index.md#geolocation)
14
+ - [getCache](index.md#getcache)
14
15
  - [getEnv](index.md#getenv)
15
- - [getRuntimeCache](index.md#getruntimecache)
16
16
  - [ipAddress](index.md#ipaddress)
17
17
  - [next](index.md#next)
18
18
  - [rewrite](index.md#rewrite)
@@ -68,6 +68,41 @@ The location information of the request, in this way:
68
68
 
69
69
  ---
70
70
 
71
+ ### getCache
72
+
73
+ ▸ **getCache**(`cacheOptions?`): [`RuntimeCache`](../interfaces/index.RuntimeCache.md)
74
+
75
+ Retrieves the Vercel Runtime Cache.
76
+
77
+ Keys are hashed to ensure they are unique and consistent. The hashing function can be overridden by providing a custom
78
+ `keyHashFunction` in the `cacheOptions` parameter.
79
+
80
+ To specify a namespace for the cache keys, you can pass a `namespace` option in the `cacheOptions` parameter. If
81
+ a namespace is provided, the cache keys will be prefixed with the namespace followed by a separator (default is `$`). The
82
+ namespaceSeparator can also be customized using the `namespaceSeparator` option.
83
+
84
+ **`Throws`**
85
+
86
+ If no cache is available in the context and `InMemoryCache` cannot be created.
87
+
88
+ #### Parameters
89
+
90
+ | Name | Type | Description |
91
+ | :-------------- | :------------- | :------------------------------------ |
92
+ | `cacheOptions?` | `CacheOptions` | Optional configuration for the cache. |
93
+
94
+ #### Returns
95
+
96
+ [`RuntimeCache`](../interfaces/index.RuntimeCache.md)
97
+
98
+ An instance of the Vercel Runtime Cache.
99
+
100
+ #### Defined in
101
+
102
+ [packages/functions/src/cache/index.ts:32](https://github.com/vercel/vercel/blob/main/packages/functions/src/cache/index.ts#L32)
103
+
104
+ ---
105
+
71
106
  ### getEnv
72
107
 
73
108
  ▸ **getEnv**(`env?`): `Object`
@@ -118,41 +153,6 @@ https://vercel.com/docs/projects/environment-variables/system-environment-variab
118
153
 
119
154
  ---
120
155
 
121
- ### getRuntimeCache
122
-
123
- ▸ **getRuntimeCache**(`cacheOptions?`): [`RuntimeCache`](../interfaces/index.RuntimeCache.md)
124
-
125
- Retrieves the Vercel Runtime Cache.
126
-
127
- Keys are hashed to ensure they are unique and consistent. The hashing function can be overridden by providing a custom
128
- `keyHashFunction` in the `cacheOptions` parameter.
129
-
130
- To specify a namespace for the cache keys, you can pass a `namespace` option in the `cacheOptions` parameter. If
131
- a namespace is provided, the cache keys will be prefixed with the namespace followed by a separator (default is `$`). The
132
- namespaceSeparator can also be customized using the `namespaceSeparator` option.
133
-
134
- **`Throws`**
135
-
136
- If no cache is available in the context and `InMemoryCache` cannot be created.
137
-
138
- #### Parameters
139
-
140
- | Name | Type | Description |
141
- | :-------------- | :------------- | :------------------------------------ |
142
- | `cacheOptions?` | `CacheOptions` | Optional configuration for the cache. |
143
-
144
- #### Returns
145
-
146
- [`RuntimeCache`](../interfaces/index.RuntimeCache.md)
147
-
148
- An instance of the Vercel Runtime Cache.
149
-
150
- #### Defined in
151
-
152
- [packages/functions/src/cache/index.ts:32](https://github.com/vercel/vercel/blob/main/packages/functions/src/cache/index.ts#L32)
153
-
154
- ---
155
-
156
156
  ### ipAddress
157
157
 
158
158
  ▸ **ipAddress**(`input`): `string` \| `undefined`
@@ -10,6 +10,7 @@
10
10
 
11
11
  - [awsCredentialsProvider](oidc.md#awscredentialsprovider)
12
12
  - [getVercelOidcToken](oidc.md#getverceloidctoken)
13
+ - [getVercelOidcTokenSync](oidc.md#getverceloidctokensync)
13
14
 
14
15
  ## Functions
15
16
 
@@ -64,11 +65,12 @@ A function that provides AWS credentials.
64
65
 
65
66
  ▸ **getVercelOidcToken**(): [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<`string`\>
66
67
 
67
- Returns the OIDC token from the request context or the environment variable.
68
+ Gets the current OIDC token from the request context or the environment variable.
68
69
 
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.
70
+ Do not cache this value, as it is subject to change in production!
71
+
72
+ This function is used to retrieve the OIDC token from the request context or the environment variable.
73
+ It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
72
74
 
73
75
  **`Throws`**
74
76
 
@@ -95,4 +97,39 @@ A promise that resolves to the OIDC token.
95
97
 
96
98
  #### Defined in
97
99
 
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)
100
+ [packages/functions/src/oidc/get-vercel-oidc-token.ts:25](https://github.com/vercel/vercel/blob/main/packages/functions/src/oidc/get-vercel-oidc-token.ts#L25)
101
+
102
+ ---
103
+
104
+ ### getVercelOidcTokenSync
105
+
106
+ ▸ **getVercelOidcTokenSync**(): `string`
107
+
108
+ Gets the current OIDC token from the request context or the environment variable.
109
+
110
+ Do not cache this value, as it is subject to change in production!
111
+
112
+ This function is used to retrieve the OIDC token from the request context or the environment variable.
113
+ It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
114
+
115
+ **`Throws`**
116
+
117
+ If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set.
118
+
119
+ **`Example`**
120
+
121
+ ```js
122
+ // Using the OIDC token
123
+ const token = getVercelOidcTokenSync();
124
+ console.log('OIDC Token:', token);
125
+ ```
126
+
127
+ #### Returns
128
+
129
+ `string`
130
+
131
+ The OIDC token.
132
+
133
+ #### Defined in
134
+
135
+ [packages/functions/src/oidc/get-vercel-oidc-token.ts:48](https://github.com/vercel/vercel/blob/main/packages/functions/src/oidc/get-vercel-oidc-token.ts#L48)
package/index.d.ts CHANGED
@@ -3,5 +3,5 @@ export { geolocation, ipAddress } from './headers';
3
3
  export { getEnv } from './get-env';
4
4
  export { waitUntil } from './wait-until';
5
5
  export { rewrite, next } from './middleware';
6
- export { getRuntimeCache } from './cache';
6
+ export { getCache } from './cache';
7
7
  export type { RuntimeCache } from './cache/types';
package/index.js CHANGED
@@ -19,8 +19,8 @@ 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
+ getCache: () => import_cache.getCache,
22
23
  getEnv: () => import_get_env.getEnv,
23
- getRuntimeCache: () => import_cache.getRuntimeCache,
24
24
  ipAddress: () => import_headers.ipAddress,
25
25
  next: () => import_middleware.next,
26
26
  rewrite: () => import_middleware.rewrite,
@@ -35,8 +35,8 @@ var import_cache = require("./cache");
35
35
  // Annotate the CommonJS export names for ESM import in node:
36
36
  0 && (module.exports = {
37
37
  geolocation,
38
+ getCache,
38
39
  getEnv,
39
- getRuntimeCache,
40
40
  ipAddress,
41
41
  next,
42
42
  rewrite,
@@ -37,7 +37,7 @@ function awsCredentialsProvider(init) {
37
37
  const { fromWebToken } = await import("@aws-sdk/credential-provider-web-identity");
38
38
  return fromWebToken({
39
39
  ...init,
40
- webIdentityToken: await (0, import_get_vercel_oidc_token.getVercelOidcToken)()
40
+ webIdentityToken: (0, import_get_vercel_oidc_token.getVercelOidcTokenSync)()
41
41
  })();
42
42
  };
43
43
  }
@@ -1,9 +1,10 @@
1
1
  /**
2
- * Returns the OIDC token from the request context or the environment variable.
2
+ * Gets the current OIDC token from the request context or the environment variable.
3
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.
4
+ * Do not cache this value, as it is subject to change in production!
5
+ *
6
+ * This function is used to retrieve the OIDC token from the request context or the environment variable.
7
+ * It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
7
8
  *
8
9
  * @returns {Promise<string>} A promise that resolves to the OIDC token.
9
10
  * @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.
@@ -20,3 +21,23 @@
20
21
  * ```
21
22
  */
22
23
  export declare function getVercelOidcToken(): Promise<string>;
24
+ /**
25
+ * Gets the current OIDC token from the request context or the environment variable.
26
+ *
27
+ * Do not cache this value, as it is subject to change in production!
28
+ *
29
+ * This function is used to retrieve the OIDC token from the request context or the environment variable.
30
+ * It checks for the `x-vercel-oidc-token` header in the request context and falls back to the `VERCEL_OIDC_TOKEN` environment variable if the header is not present.
31
+ *
32
+ * @returns {string} The OIDC token.
33
+ * @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.
34
+ *
35
+ * @example
36
+ *
37
+ * ```js
38
+ * // Using the OIDC token
39
+ * const token = getVercelOidcTokenSync();
40
+ * console.log('OIDC Token:', token);
41
+ * ```
42
+ */
43
+ export declare function getVercelOidcTokenSync(): string;
@@ -18,14 +18,16 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var get_vercel_oidc_token_exports = {};
20
20
  __export(get_vercel_oidc_token_exports, {
21
- getVercelOidcToken: () => getVercelOidcToken
21
+ getVercelOidcToken: () => getVercelOidcToken,
22
+ getVercelOidcTokenSync: () => getVercelOidcTokenSync
22
23
  });
23
24
  module.exports = __toCommonJS(get_vercel_oidc_token_exports);
24
25
  var import_get_context = require("../get-context");
25
26
  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"];
27
+ return getVercelOidcTokenSync();
28
+ }
29
+ function getVercelOidcTokenSync() {
30
+ const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
29
31
  if (!token) {
30
32
  throw new Error(
31
33
  `The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
@@ -35,5 +37,6 @@ async function getVercelOidcToken() {
35
37
  }
36
38
  // Annotate the CommonJS export names for ESM import in node:
37
39
  0 && (module.exports = {
38
- getVercelOidcToken
40
+ getVercelOidcToken,
41
+ getVercelOidcTokenSync
39
42
  });
package/oidc/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export type { AwsCredentialsProviderInit } from './aws-credentials-provider';
2
2
  export { awsCredentialsProvider } from './aws-credentials-provider';
3
- export { getVercelOidcToken } from './get-vercel-oidc-token';
3
+ export { getVercelOidcToken, getVercelOidcTokenSync, } from './get-vercel-oidc-token';
package/oidc/index.js CHANGED
@@ -19,7 +19,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  var oidc_exports = {};
20
20
  __export(oidc_exports, {
21
21
  awsCredentialsProvider: () => import_aws_credentials_provider.awsCredentialsProvider,
22
- getVercelOidcToken: () => import_get_vercel_oidc_token.getVercelOidcToken
22
+ getVercelOidcToken: () => import_get_vercel_oidc_token.getVercelOidcToken,
23
+ getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync
23
24
  });
24
25
  module.exports = __toCommonJS(oidc_exports);
25
26
  var import_aws_credentials_provider = require("./aws-credentials-provider");
@@ -27,5 +28,6 @@ var import_get_vercel_oidc_token = require("./get-vercel-oidc-token");
27
28
  // Annotate the CommonJS export names for ESM import in node:
28
29
  0 && (module.exports = {
29
30
  awsCredentialsProvider,
30
- getVercelOidcToken
31
+ getVercelOidcToken,
32
+ getVercelOidcTokenSync
31
33
  });
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "require": "./middleware.js"
27
27
  }
28
28
  },
29
- "version": "2.0.3",
29
+ "version": "2.2.0",
30
30
  "repository": {
31
31
  "directory": "packages/functions",
32
32
  "type": "git",