@vercel/functions 2.1.0 → 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,11 @@
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
+
3
9
  ## 2.1.0
4
10
 
5
11
  ### Minor Changes
@@ -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,13 +65,13 @@ 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.
69
+
70
+ Do not cache this value, as it is subject to change in production!
68
71
 
69
72
  This function is used to retrieve the OIDC token from the request context or the environment variable.
70
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.
71
74
 
72
- context headers.
73
-
74
75
  **`Throws`**
75
76
 
76
77
  If the `x-vercel-oidc-token` header is missing from the request context and the environment variable `VERCEL_OIDC_TOKEN` is not set.
@@ -97,3 +98,38 @@ A promise that resolves to the OIDC token.
97
98
  #### Defined in
98
99
 
99
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)
@@ -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,11 +1,11 @@
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
+ *
4
+ * Do not cache this value, as it is subject to change in production!
3
5
  *
4
6
  * This function is used to retrieve the OIDC token from the request context or the environment variable.
5
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.
6
8
  *
7
- * context headers.
8
- *
9
9
  * @returns {Promise<string>} A promise that resolves to the OIDC token.
10
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.
11
11
  *
@@ -21,3 +21,23 @@
21
21
  * ```
22
22
  */
23
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,11 +18,15 @@ 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() {
27
+ return getVercelOidcTokenSync();
28
+ }
29
+ function getVercelOidcTokenSync() {
26
30
  const token = (0, import_get_context.getContext)().headers?.["x-vercel-oidc-token"] ?? process.env.VERCEL_OIDC_TOKEN;
27
31
  if (!token) {
28
32
  throw new Error(
@@ -33,5 +37,6 @@ async function getVercelOidcToken() {
33
37
  }
34
38
  // Annotate the CommonJS export names for ESM import in node:
35
39
  0 && (module.exports = {
36
- getVercelOidcToken
40
+ getVercelOidcToken,
41
+ getVercelOidcTokenSync
37
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.1.0",
29
+ "version": "2.2.0",
30
30
  "repository": {
31
31
  "directory": "packages/functions",
32
32
  "type": "git",