@vercel/functions 2.2.4 → 2.2.6

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,26 @@
1
1
  # @vercel/functions
2
2
 
3
+ ## 2.2.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Introduce attachDatabasePool function ([#13632](https://github.com/vercel/vercel/pull/13632))
8
+
9
+ ## 2.2.5
10
+
11
+ ### Patch Changes
12
+
13
+ - extract oidc and aws oidc credential helpers from @vercel/functions into @vercel/oidc and @vercel/oidc-aws-credentials-provider. @vercel/functions re-exports the new functions as deprecated to maintain backwards compatibility. ([#13548](https://github.com/vercel/vercel/pull/13548))
14
+
15
+ - Updated dependencies [[`fa8d4c76ea50c4844031f56209b21845818212fc`](https://github.com/vercel/vercel/commit/fa8d4c76ea50c4844031f56209b21845818212fc)]:
16
+ - @vercel/oidc@2.0.0
17
+
18
+ ## 2.2.5
19
+
20
+ ### Patch Changes
21
+
22
+ - Extract oidc behavior into separate packages ([#13548](https://github.com/vercel/vercel/pull/13548))
23
+
3
24
  ## 2.2.4
4
25
 
5
26
  ### Patch Changes
@@ -0,0 +1,81 @@
1
+ interface PgPool {
2
+ options?: {
3
+ idleTimeoutMillis?: number | null;
4
+ };
5
+ on?: (event: 'release', listener: (...args: any[]) => void) => void;
6
+ }
7
+ interface MySQLPool {
8
+ config?: {
9
+ connectionConfig?: {
10
+ idleTimeout?: number;
11
+ };
12
+ };
13
+ on?: (event: 'release', listener: (...args: any[]) => void) => void;
14
+ }
15
+ interface MySQL2Pool {
16
+ config?: {
17
+ idleTimeout?: number;
18
+ };
19
+ on?: (event: 'release', listener: (...args: any[]) => void) => void;
20
+ }
21
+ interface MariaDBPool {
22
+ config?: {
23
+ idleTimeout?: number;
24
+ };
25
+ on?: (event: 'release', listener: (...args: any[]) => void) => void;
26
+ }
27
+ interface MongoDBPool {
28
+ options?: {
29
+ maxIdleTimeMS?: number;
30
+ };
31
+ on?: (event: 'connectionCheckedOut' | 'connectionCheckedIn' | 'connectionPoolCreated' | 'connectionPoolClosed' | 'connectionCreated' | 'connectionReady' | 'connectionClosed', listener: (...args: any[]) => void) => void;
32
+ }
33
+ interface RedisPool {
34
+ options?: any;
35
+ on?: (event: 'ready' | 'end' | 'error' | 'connect', listener: (...args: any[]) => void) => void;
36
+ status?: string;
37
+ }
38
+ interface CassandraPool {
39
+ connect?: (callback?: (err?: Error) => void) => Promise<void>;
40
+ execute?: (query: string, params?: any[], options?: any) => Promise<any>;
41
+ }
42
+ /**
43
+ * The database pool object. The supported pool types are:
44
+ * - PostgreSQL (pg)
45
+ * - MySQL2
46
+ * - MariaDB
47
+ * - MongoDB
48
+ * - Redis (ioredis)
49
+ * - Cassandra (cassandra-driver)
50
+ * - OTHER: This method uses duck-typing to detect the pool type. Respectively you can
51
+ * pass in any object with a compatible interface.
52
+ */
53
+ export type DbPool = PgPool | MySQLPool | MySQL2Pool | MariaDBPool | MongoDBPool | RedisPool | CassandraPool;
54
+ /**
55
+ * Call this function right after creating a database pool with the database pool object
56
+ * as argument.
57
+ * This ensures that the current function instance stays alive long enough for
58
+ * idle database connections to be removed from the pool.
59
+ *
60
+ * @param dbPool - The database pool object. The supported pool types are:
61
+ * - PostgreSQL (pg)
62
+ * - MySQL2
63
+ * - MariaDB
64
+ * - MongoDB
65
+ * - Redis (ioredis)
66
+ * - Cassandra (cassandra-driver)
67
+ * - OTHER: This method uses duck-typing to detect the pool type. Respectively you can
68
+ * pass in any object with a compatible interface.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * const pgPool = new Pool({
73
+ * connectionString: process.env.DATABASE_URL,
74
+ * });
75
+ * experimental_attachDatabasePool(pgPool);
76
+ * ```
77
+ *
78
+ * @experimental
79
+ */
80
+ export declare function experimental_attachDatabasePool(dbPool: DbPool): void;
81
+ export {};
@@ -0,0 +1,145 @@
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 db_connections_exports = {};
20
+ __export(db_connections_exports, {
21
+ experimental_attachDatabasePool: () => experimental_attachDatabasePool
22
+ });
23
+ module.exports = __toCommonJS(db_connections_exports);
24
+ var import_get_context = require("../get-context");
25
+ const DEBUG = !!process.env.DEBUG;
26
+ function getIdleTimeout(dbPool) {
27
+ if ("options" in dbPool && dbPool.options) {
28
+ if ("idleTimeoutMillis" in dbPool.options) {
29
+ return typeof dbPool.options.idleTimeoutMillis === "number" ? dbPool.options.idleTimeoutMillis : 1e4;
30
+ }
31
+ if ("maxIdleTimeMS" in dbPool.options) {
32
+ return typeof dbPool.options.maxIdleTimeMS === "number" ? dbPool.options.maxIdleTimeMS : 0;
33
+ }
34
+ if ("status" in dbPool) {
35
+ return 5e3;
36
+ }
37
+ if ("connect" in dbPool && "execute" in dbPool) {
38
+ return 3e4;
39
+ }
40
+ }
41
+ if ("config" in dbPool && dbPool.config) {
42
+ if ("connectionConfig" in dbPool.config && dbPool.config.connectionConfig) {
43
+ return dbPool.config.connectionConfig.idleTimeout || 6e4;
44
+ }
45
+ if ("idleTimeout" in dbPool.config) {
46
+ return typeof dbPool.config.idleTimeout === "number" ? dbPool.config.idleTimeout : 6e4;
47
+ }
48
+ }
49
+ if ("poolTimeout" in dbPool) {
50
+ return typeof dbPool.poolTimeout === "number" ? dbPool.poolTimeout : 6e4;
51
+ }
52
+ if ("idleTimeout" in dbPool) {
53
+ return typeof dbPool.idleTimeout === "number" ? dbPool.idleTimeout : 0;
54
+ }
55
+ return 1e4;
56
+ }
57
+ let idleTimeout = null;
58
+ let idleTimeoutResolve = () => {
59
+ };
60
+ const bootTime = Date.now();
61
+ const maximumDuration = 15 * 60 * 1e3 - 1e3;
62
+ function waitUntilIdleTimeout(dbPool) {
63
+ if (idleTimeout) {
64
+ clearTimeout(idleTimeout);
65
+ idleTimeoutResolve();
66
+ }
67
+ const promise = new Promise((resolve) => {
68
+ idleTimeoutResolve = resolve;
69
+ });
70
+ const waitTime = Math.min(
71
+ getIdleTimeout(dbPool) + 100,
72
+ maximumDuration - (Date.now() - bootTime)
73
+ );
74
+ idleTimeout = setTimeout(() => {
75
+ idleTimeoutResolve?.();
76
+ if (DEBUG) {
77
+ console.log("Database pool idle timeout reached. Releasing connections.");
78
+ }
79
+ }, waitTime);
80
+ const requestContext = (0, import_get_context.getContext)();
81
+ if (requestContext?.waitUntil) {
82
+ requestContext.waitUntil(promise);
83
+ } else {
84
+ console.warn("Pool release event triggered outside of request scope.");
85
+ }
86
+ }
87
+ function experimental_attachDatabasePool(dbPool) {
88
+ if (idleTimeout) {
89
+ idleTimeoutResolve?.();
90
+ clearTimeout(idleTimeout);
91
+ }
92
+ if ("on" in dbPool && dbPool.on && "options" in dbPool && "idleTimeoutMillis" in dbPool.options) {
93
+ const pgPool = dbPool;
94
+ pgPool.on("release", () => {
95
+ if (DEBUG) {
96
+ console.log("Client released from pool");
97
+ }
98
+ waitUntilIdleTimeout(dbPool);
99
+ });
100
+ return;
101
+ } else if ("on" in dbPool && dbPool.on && "config" in dbPool && dbPool.config && "connectionConfig" in dbPool.config) {
102
+ const mysqlPool = dbPool;
103
+ mysqlPool.on("release", () => {
104
+ if (DEBUG) {
105
+ console.log("MySQL client released from pool");
106
+ }
107
+ waitUntilIdleTimeout(dbPool);
108
+ });
109
+ return;
110
+ } else if ("on" in dbPool && dbPool.on && "config" in dbPool && dbPool.config && "idleTimeout" in dbPool.config) {
111
+ const mysql2Pool = dbPool;
112
+ mysql2Pool.on("release", () => {
113
+ if (DEBUG) {
114
+ console.log("MySQL2/MariaDB client released from pool");
115
+ }
116
+ waitUntilIdleTimeout(dbPool);
117
+ });
118
+ return;
119
+ }
120
+ if ("on" in dbPool && dbPool.on && "options" in dbPool && dbPool.options && "maxIdleTimeMS" in dbPool.options) {
121
+ const mongoPool = dbPool;
122
+ mongoPool.on("connectionCheckedOut", () => {
123
+ if (DEBUG) {
124
+ console.log("MongoDB connection checked out");
125
+ }
126
+ waitUntilIdleTimeout(dbPool);
127
+ });
128
+ return;
129
+ }
130
+ if ("on" in dbPool && dbPool.on && "options" in dbPool && dbPool.options && "socket" in dbPool.options) {
131
+ const redisPool = dbPool;
132
+ redisPool.on("end", () => {
133
+ if (DEBUG) {
134
+ console.log("Redis connection ended");
135
+ }
136
+ waitUntilIdleTimeout(dbPool);
137
+ });
138
+ return;
139
+ }
140
+ throw new Error("Unsupported database pool type");
141
+ }
142
+ // Annotate the CommonJS export names for ESM import in node:
143
+ 0 && (module.exports = {
144
+ experimental_attachDatabasePool
145
+ });
@@ -0,0 +1,13 @@
1
+ import type { Pool as PgPoolType } from 'pg';
2
+ import type { Pool as MySQL2PoolType } from 'mysql2/promise';
3
+ import type { Pool as MariaDBPoolType } from 'mariadb';
4
+ import type { MongoClient as MongoDBClientType } from 'mongodb';
5
+ import type { Redis as IoRedisType } from 'ioredis';
6
+ import type { Client as CassandraClientType } from 'cassandra-driver';
7
+ import type { DbPool } from '.';
8
+ export declare const pgSubtypeCheck: (pool: PgPoolType) => DbPool;
9
+ export declare const mysql2SubtypeCheck: (pool: MySQL2PoolType) => DbPool;
10
+ export declare const mariadbSubtypeCheck: (pool: MariaDBPoolType) => DbPool;
11
+ export declare const mongoSubtypeCheck: (client: MongoDBClientType) => DbPool;
12
+ export declare const ioredisSubtypeCheck: (redis: IoRedisType) => DbPool;
13
+ export declare const cassandraSubtypeCheck: (client: CassandraClientType) => DbPool;
@@ -16,27 +16,29 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
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
- getVercelOidcTokenSync: () => getVercelOidcTokenSync
19
+ var type_assertion_exports = {};
20
+ __export(type_assertion_exports, {
21
+ cassandraSubtypeCheck: () => cassandraSubtypeCheck,
22
+ ioredisSubtypeCheck: () => ioredisSubtypeCheck,
23
+ mariadbSubtypeCheck: () => mariadbSubtypeCheck,
24
+ mongoSubtypeCheck: () => mongoSubtypeCheck,
25
+ mysql2SubtypeCheck: () => mysql2SubtypeCheck,
26
+ pgSubtypeCheck: () => pgSubtypeCheck
23
27
  });
24
- module.exports = __toCommonJS(get_vercel_oidc_token_exports);
25
- var import_get_context = require("../get-context");
26
- async function getVercelOidcToken() {
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;
31
- if (!token) {
32
- throw new Error(
33
- `The 'x-vercel-oidc-token' header is missing from the request. Do you have the OIDC option enabled in the Vercel project settings?`
34
- );
35
- }
36
- return token;
37
- }
28
+ module.exports = __toCommonJS(type_assertion_exports);
29
+ const pgSubtypeCheck = (pool) => pool;
30
+ const mysql2SubtypeCheck = (pool) => pool;
31
+ const mariadbSubtypeCheck = (pool) => pool;
32
+ const mongoSubtypeCheck = (client) => client;
33
+ const ioredisSubtypeCheck = (redis) => redis;
34
+ const cassandraSubtypeCheck = (client) => client;
35
+ throw new Error("This file is not used in the codebase.");
38
36
  // Annotate the CommonJS export names for ESM import in node:
39
37
  0 && (module.exports = {
40
- getVercelOidcToken,
41
- getVercelOidcTokenSync
38
+ cassandraSubtypeCheck,
39
+ ioredisSubtypeCheck,
40
+ mariadbSubtypeCheck,
41
+ mongoSubtypeCheck,
42
+ mysql2SubtypeCheck,
43
+ pgSubtypeCheck
42
44
  });
@@ -10,6 +10,7 @@
10
10
 
11
11
  ### Functions
12
12
 
13
+ - [experimental_attachDatabasePool](index.md#experimental_attachdatabasepool)
13
14
  - [geolocation](index.md#geolocation)
14
15
  - [getCache](index.md#getcache)
15
16
  - [getEnv](index.md#getenv)
@@ -20,6 +21,40 @@
20
21
 
21
22
  ## Functions
22
23
 
24
+ ### experimental_attachDatabasePool
25
+
26
+ ▸ **experimental_attachDatabasePool**(`dbPool`): `void`
27
+
28
+ Call this function right after creating a database pool with the database pool object
29
+ as argument.
30
+ This ensures that the current function instance stays alive long enough for
31
+ idle database connections to be removed from the pool.
32
+
33
+ **`Example`**
34
+
35
+ ```ts
36
+ const pgPool = new Pool({
37
+ connectionString: process.env.DATABASE_URL,
38
+ });
39
+ experimental_attachDatabasePool(pgPool);
40
+ ```
41
+
42
+ #### Parameters
43
+
44
+ | Name | Type | Description |
45
+ | :------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
46
+ | `dbPool` | `DbPool` | The database pool object. The supported pool types are: - PostgreSQL (pg) - MySQL2 - MariaDB - MongoDB - Redis (ioredis) - Cassandra (cassandra-driver) - OTHER: This method uses duck-typing to detect the pool type. Respectively you can pass in any object with a compatible interface. |
47
+
48
+ #### Returns
49
+
50
+ `void`
51
+
52
+ #### Defined in
53
+
54
+ [packages/functions/src/db-connections/index.ts:217](https://github.com/vercel/vercel/blob/main/packages/functions/src/db-connections/index.ts#L217)
55
+
56
+ ---
57
+
23
58
  ### geolocation
24
59
 
25
60
  ▸ **geolocation**(`request`): [`Geo`](../interfaces/index.Geo.md)
@@ -97,7 +97,7 @@ A promise that resolves to the OIDC token.
97
97
 
98
98
  #### Defined in
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)
100
+ packages/oidc/dist/get-vercel-oidc-token.d.ts:23
101
101
 
102
102
  ---
103
103
 
@@ -132,4 +132,4 @@ The OIDC token.
132
132
 
133
133
  #### Defined in
134
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)
135
+ packages/oidc/dist/get-vercel-oidc-token.d.ts:43
package/index.d.ts CHANGED
@@ -4,4 +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
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
+ experimental_attachDatabasePool: () => import_db_connections.experimental_attachDatabasePool,
21
22
  geolocation: () => import_headers.geolocation,
22
23
  getCache: () => import_cache.getCache,
23
24
  getEnv: () => import_get_env.getEnv,
@@ -32,8 +33,10 @@ var import_get_env = require("./get-env");
32
33
  var import_wait_until = require("./wait-until");
33
34
  var import_middleware = require("./middleware");
34
35
  var import_cache = require("./cache");
36
+ var import_db_connections = require("./db-connections");
35
37
  // Annotate the CommonJS export names for ESM import in node:
36
38
  0 && (module.exports = {
39
+ experimental_attachDatabasePool,
37
40
  geolocation,
38
41
  getCache,
39
42
  getEnv,
@@ -31,13 +31,13 @@ __export(aws_credentials_provider_exports, {
31
31
  awsCredentialsProvider: () => awsCredentialsProvider
32
32
  });
33
33
  module.exports = __toCommonJS(aws_credentials_provider_exports);
34
- var import_get_vercel_oidc_token = require("./get-vercel-oidc-token");
34
+ var import_oidc = require("@vercel/oidc");
35
35
  function awsCredentialsProvider(init) {
36
36
  return async () => {
37
37
  const { fromWebToken } = await import("@aws-sdk/credential-provider-web-identity");
38
38
  return fromWebToken({
39
39
  ...init,
40
- webIdentityToken: (0, import_get_vercel_oidc_token.getVercelOidcTokenSync)()
40
+ webIdentityToken: (0, import_oidc.getVercelOidcTokenSync)()
41
41
  })();
42
42
  };
43
43
  }
package/oidc/index.d.ts CHANGED
@@ -1,3 +1,15 @@
1
+ /**
2
+ * @deprecated Use @vercel/oidc-aws-credentials-provider instead
3
+ * AWS authentication for Vercel Functions
4
+ */
1
5
  export type { AwsCredentialsProviderInit } from './aws-credentials-provider';
6
+ /**
7
+ * @deprecated Use @vercel/oidc-aws-credentials-provider instead
8
+ * AWS authentication for Vercel Functions
9
+ */
2
10
  export { awsCredentialsProvider } from './aws-credentials-provider';
3
- export { getVercelOidcToken, getVercelOidcTokenSync, } from './get-vercel-oidc-token';
11
+ /**
12
+ * @deprecated Use @vercel/oidc instead
13
+ * OIDC authentication for Vercel Functions
14
+ */
15
+ export { getVercelOidcToken, getVercelOidcTokenSync } from '@vercel/oidc';
package/oidc/index.js CHANGED
@@ -19,12 +19,12 @@ 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,
23
- getVercelOidcTokenSync: () => import_get_vercel_oidc_token.getVercelOidcTokenSync
22
+ getVercelOidcToken: () => import_oidc.getVercelOidcToken,
23
+ getVercelOidcTokenSync: () => import_oidc.getVercelOidcTokenSync
24
24
  });
25
25
  module.exports = __toCommonJS(oidc_exports);
26
26
  var import_aws_credentials_provider = require("./aws-credentials-provider");
27
- var import_get_vercel_oidc_token = require("./get-vercel-oidc-token");
27
+ var import_oidc = require("@vercel/oidc");
28
28
  // Annotate the CommonJS export names for ESM import in node:
29
29
  0 && (module.exports = {
30
30
  awsCredentialsProvider,
package/package.json CHANGED
@@ -21,12 +21,16 @@
21
21
  "import": "./oidc/index.js",
22
22
  "require": "./oidc/index.js"
23
23
  },
24
+ "./db-connections": {
25
+ "import": "./db-connections/index.js",
26
+ "require": "./db-connections/index.js"
27
+ },
24
28
  "./middleware": {
25
29
  "import": "./middleware.js",
26
30
  "require": "./middleware.js"
27
31
  }
28
32
  },
29
- "version": "2.2.4",
33
+ "version": "2.2.6",
30
34
  "repository": {
31
35
  "directory": "packages/functions",
32
36
  "type": "git",
@@ -39,6 +43,12 @@
39
43
  "@aws-sdk/client-s3": "3.609.0",
40
44
  "@aws-sdk/credential-provider-web-identity": "3.609.0",
41
45
  "@smithy/types": "3.3.0",
46
+ "@types/pg": "8.15.5",
47
+ "cassandra-driver": "4.8.0",
48
+ "ioredis": "5.6.1",
49
+ "mariadb": "3.4.5",
50
+ "mongodb": "6.18.0",
51
+ "mysql2": "3.14.2",
42
52
  "tinyspawn": "1.3.1",
43
53
  "typedoc": "0.24.6",
44
54
  "typedoc-plugin-markdown": "4.1.2",
@@ -61,6 +71,9 @@
61
71
  "publishConfig": {
62
72
  "access": "public"
63
73
  },
74
+ "dependencies": {
75
+ "@vercel/oidc": "2.0.0"
76
+ },
64
77
  "scripts": {
65
78
  "pretest": "pnpm run build:code",
66
79
  "test": "vitest",
@@ -1,43 +0,0 @@
1
- /**
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!
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.
8
- *
9
- * @returns {Promise<string>} A promise that resolves to the OIDC token.
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
- *
12
- * @example
13
- *
14
- * ```js
15
- * // Using the OIDC token
16
- * getVercelOidcToken().then((token) => {
17
- * console.log('OIDC Token:', token);
18
- * }).catch((error) => {
19
- * console.error('Error:', error.message);
20
- * });
21
- * ```
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;