@vercel/functions 2.0.2 → 2.1.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.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Change the load order of the OIDC token ([#13337](https://github.com/vercel/vercel/pull/13337))
8
+
9
+ ### Patch Changes
10
+
11
+ - Rename getRuntimeCache to getCache ([#13325](https://github.com/vercel/vercel/pull/13325))
12
+
13
+ ## 2.0.3
14
+
15
+ ### Patch Changes
16
+
17
+ - Rename FunctionCache / getFunctionCache to RuntimeCache / getRuntimeCache ([#13296](https://github.com/vercel/vercel/pull/13296))
18
+
3
19
  ## 2.0.2
4
20
 
5
21
  ### Patch Changes
@@ -1,5 +1,5 @@
1
- import { FunctionCache } from './types';
2
- export declare class InMemoryCache implements FunctionCache {
1
+ import { RuntimeCache } from './types';
2
+ export declare class InMemoryCache implements RuntimeCache {
3
3
  private cache;
4
4
  get(key: string, options?: {
5
5
  tags?: string[];
package/cache/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { CacheOptions, FunctionCache } from './types';
1
+ import { CacheOptions, RuntimeCache } from './types';
2
2
  /**
3
- * Retrieves the Vercel Function Cache.
3
+ * Retrieves the Vercel Runtime Cache.
4
4
  *
5
5
  * Keys are hashed to ensure they are unique and consistent. The hashing function can be overridden by providing a custom
6
6
  * `keyHashFunction` in the `cacheOptions` parameter.
@@ -10,7 +10,7 @@ import { CacheOptions, FunctionCache } from './types';
10
10
  * namespaceSeparator can also be customized using the `namespaceSeparator` option.
11
11
  *
12
12
  * @param cacheOptions - Optional configuration for the cache.
13
- * @returns An instance of the Vercel Function Cache.
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 getFunctionCache: (cacheOptions?: CacheOptions) => FunctionCache;
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
- getFunctionCache: () => getFunctionCache
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 getFunctionCache = (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 getFunctionCache = (cacheOptions) => {
68
68
  };
69
69
  // Annotate the CommonJS export names for ESM import in node:
70
70
  0 && (module.exports = {
71
- getFunctionCache
71
+ getCache
72
72
  });
package/cache/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Interface representing the function cache.
2
+ * Interface representing the runtime cache.
3
3
  */
4
- export interface FunctionCache {
4
+ export interface RuntimeCache {
5
5
  /**
6
6
  * Deletes a value from the cache.
7
7
  *
@@ -1,17 +1,17 @@
1
- # Interface: FunctionCache
1
+ # Interface: RuntimeCache
2
2
 
3
- [index](../modules/index.md).FunctionCache
3
+ [index](../modules/index.md).RuntimeCache
4
4
 
5
- Interface representing the function cache.
5
+ Interface representing the runtime cache.
6
6
 
7
7
  ## Table of contents
8
8
 
9
9
  ### Properties
10
10
 
11
- - [delete](index.FunctionCache.md#delete)
12
- - [expireTag](index.FunctionCache.md#expiretag)
13
- - [get](index.FunctionCache.md#get)
14
- - [set](index.FunctionCache.md#set)
11
+ - [delete](index.RuntimeCache.md#delete)
12
+ - [expireTag](index.RuntimeCache.md#expiretag)
13
+ - [get](index.RuntimeCache.md#get)
14
+ - [set](index.RuntimeCache.md#set)
15
15
 
16
16
  ## Properties
17
17
 
@@ -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
@@ -4,15 +4,15 @@
4
4
 
5
5
  ### Interfaces
6
6
 
7
- - [FunctionCache](../interfaces/index.FunctionCache.md)
8
7
  - [Geo](../interfaces/index.Geo.md)
9
8
  - [Request](../interfaces/index.Request.md)
9
+ - [RuntimeCache](../interfaces/index.RuntimeCache.md)
10
10
 
11
11
  ### Functions
12
12
 
13
13
  - [geolocation](index.md#geolocation)
14
+ - [getCache](index.md#getcache)
14
15
  - [getEnv](index.md#getenv)
15
- - [getFunctionCache](index.md#getfunctioncache)
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
- ### getFunctionCache
122
-
123
- ▸ **getFunctionCache**(`cacheOptions?`): [`FunctionCache`](../interfaces/index.FunctionCache.md)
124
-
125
- Retrieves the Vercel Function 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
- [`FunctionCache`](../interfaces/index.FunctionCache.md)
147
-
148
- An instance of the Vercel Function 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`
@@ -66,8 +66,9 @@ A function that provides AWS credentials.
66
66
 
67
67
  Returns the OIDC token from the request context or the environment variable.
68
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
69
+ This function is used to retrieve the OIDC token from the request context or the environment variable.
70
+ 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.
71
+
71
72
  context headers.
72
73
 
73
74
  **`Throws`**
@@ -95,4 +96,4 @@ A promise that resolves to the OIDC token.
95
96
 
96
97
  #### Defined in
97
98
 
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)
99
+ [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)
package/get-context.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { FunctionCache } from './cache/types';
1
+ import { RuntimeCache } from './cache/types';
2
2
  type Context = {
3
3
  waitUntil?: (promise: Promise<unknown>) => void;
4
- cache?: FunctionCache;
4
+ cache?: RuntimeCache;
5
5
  headers?: Record<string, string>;
6
6
  };
7
7
  export declare const SYMBOL_FOR_REQ_CONTEXT: unique symbol;
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 { getFunctionCache } from './cache';
7
- export type { FunctionCache } from './cache/types';
6
+ export { getCache } from './cache';
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
- getFunctionCache: () => import_cache.getFunctionCache,
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
- getFunctionCache,
40
40
  ipAddress,
41
41
  next,
42
42
  rewrite,
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Returns the 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
4
+ * This function is used to retrieve the OIDC token from the request context or the environment variable.
5
+ * 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.
6
+ *
6
7
  * context headers.
7
8
  *
8
9
  * @returns {Promise<string>} A promise that resolves to the OIDC token.
@@ -23,9 +23,7 @@ __export(get_vercel_oidc_token_exports, {
23
23
  module.exports = __toCommonJS(get_vercel_oidc_token_exports);
24
24
  var import_get_context = require("../get-context");
25
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"];
26
+ const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
29
27
  if (!token) {
30
28
  throw new Error(
31
29
  `The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "require": "./middleware.js"
27
27
  }
28
28
  },
29
- "version": "2.0.2",
29
+ "version": "2.1.0",
30
30
  "repository": {
31
31
  "directory": "packages/functions",
32
32
  "type": "git",