@vercel/functions 3.10.6 → 3.11.0-snapshot-d1023ee75c2c
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 +10 -0
- package/affinity.d.ts +66 -0
- package/affinity.js +48 -0
- package/docs/index/README.md +3 -0
- package/docs/index/functions/unstable_getAffinityHeaders.md +55 -0
- package/docs/index/functions/unstable_getAffinityId.md +28 -0
- package/docs/index/type-aliases/GetAffinityHeadersOptions.md +39 -0
- package/index.d.ts +2 -0
- package/index.js +5 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @vercel/functions
|
|
2
2
|
|
|
3
|
+
## 3.11.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 727e5bd: Add experimental APIs `unstable_getAffinityId()` to read the current invocation's affinity ID and `unstable_getAffinityHeaders()` to construct affinity request headers for any HTTP client, with optional project OIDC authentication via `oidc: true`. These APIs may change without notice.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- @vercel/oidc@4.0.7
|
|
12
|
+
|
|
3
13
|
## 3.10.6
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/affinity.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the experimental affinity header API.
|
|
3
|
+
*/
|
|
4
|
+
export type GetAffinityHeadersOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* The affinity ID to route this request to. Must contain 1 to 256 visible
|
|
7
|
+
* ASCII characters, without spaces.
|
|
8
|
+
*/
|
|
9
|
+
affinityId: string;
|
|
10
|
+
/**
|
|
11
|
+
* Whether to attach the current project's OIDC token. Enable only for a
|
|
12
|
+
* trusted destination. Service-binding URLs do not require this option.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
oidc?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Returns the affinity ID from the current invocation's
|
|
19
|
+
* `x-vercel-affinity-id` header, or `undefined` when it is unavailable.
|
|
20
|
+
*
|
|
21
|
+
* This is an experimental API and may change without notice.
|
|
22
|
+
*
|
|
23
|
+
* @experimental
|
|
24
|
+
* @example
|
|
25
|
+
* ```js
|
|
26
|
+
* import { unstable_getAffinityId } from '@vercel/functions';
|
|
27
|
+
*
|
|
28
|
+
* const affinityId = unstable_getAffinityId();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function unstable_getAffinityId(): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Returns request headers for invoking a Vercel Function with an explicit
|
|
34
|
+
* affinity ID. Set `oidc: true` to include the current project's OIDC token;
|
|
35
|
+
* service-binding URLs authenticate independently.
|
|
36
|
+
*
|
|
37
|
+
* This is an experimental API and may change without notice.
|
|
38
|
+
*
|
|
39
|
+
* The returned object can be passed to `fetch` or another HTTP client, or
|
|
40
|
+
* combined with other headers. Enable OIDC only for functions you intend to
|
|
41
|
+
* receive the project's token, and avoid forwarding it through redirects to
|
|
42
|
+
* untrusted destinations.
|
|
43
|
+
*
|
|
44
|
+
* @param options The required affinity ID and optional OIDC setting.
|
|
45
|
+
* @returns A plain object containing `x-vercel-affinity-id` and, when enabled,
|
|
46
|
+
* `x-vercel-trusted-oidc-idp-token`.
|
|
47
|
+
*
|
|
48
|
+
* @experimental
|
|
49
|
+
* @example
|
|
50
|
+
* ```js
|
|
51
|
+
* import { unstable_getAffinityHeaders } from '@vercel/functions';
|
|
52
|
+
*
|
|
53
|
+
* const headers = await unstable_getAffinityHeaders({
|
|
54
|
+
* affinityId: 'room:123',
|
|
55
|
+
* oidc: true,
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* const response = await fetch('https://my-project.vercel.app/api/actor', {
|
|
59
|
+
* method: 'POST',
|
|
60
|
+
* headers: { ...headers, 'content-type': 'application/json' },
|
|
61
|
+
* body: JSON.stringify({ action: 'join' }),
|
|
62
|
+
* redirect: 'error',
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function unstable_getAffinityHeaders(options: GetAffinityHeadersOptions): Promise<Record<string, string>>;
|
package/affinity.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
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 affinity_exports = {};
|
|
20
|
+
__export(affinity_exports, {
|
|
21
|
+
unstable_getAffinityHeaders: () => unstable_getAffinityHeaders,
|
|
22
|
+
unstable_getAffinityId: () => unstable_getAffinityId
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(affinity_exports);
|
|
25
|
+
var import_oidc = require("@vercel/oidc");
|
|
26
|
+
var import_get_context = require("./get-context");
|
|
27
|
+
const AFFINITY_ID_HEADER = "x-vercel-affinity-id";
|
|
28
|
+
function unstable_getAffinityId() {
|
|
29
|
+
return (0, import_get_context.getContext)().headers?.[AFFINITY_ID_HEADER];
|
|
30
|
+
}
|
|
31
|
+
async function unstable_getAffinityHeaders(options) {
|
|
32
|
+
const { affinityId, oidc } = options;
|
|
33
|
+
if (typeof affinityId !== "string" || affinityId.length === 0 || affinityId.length > 256 || /[^\x21-\x7e]/.test(affinityId)) {
|
|
34
|
+
throw new TypeError(
|
|
35
|
+
"affinityId must contain 1 to 256 visible ASCII characters, without spaces"
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
const headers = { [AFFINITY_ID_HEADER]: affinityId };
|
|
39
|
+
if (oidc === true) {
|
|
40
|
+
headers["x-vercel-trusted-oidc-idp-token"] = await (0, import_oidc.getVercelOidcToken)();
|
|
41
|
+
}
|
|
42
|
+
return headers;
|
|
43
|
+
}
|
|
44
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
45
|
+
0 && (module.exports = {
|
|
46
|
+
unstable_getAffinityHeaders,
|
|
47
|
+
unstable_getAffinityId
|
|
48
|
+
});
|
package/docs/index/README.md
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
## Type Aliases
|
|
18
18
|
|
|
19
19
|
- [AddCacheTagApi](type-aliases/AddCacheTagApi.md)
|
|
20
|
+
- [GetAffinityHeadersOptions](type-aliases/GetAffinityHeadersOptions.md)
|
|
20
21
|
- [WebSocket](type-aliases/WebSocket.md)
|
|
21
22
|
- [WebSocketData](type-aliases/WebSocketData.md)
|
|
22
23
|
|
|
@@ -41,5 +42,7 @@
|
|
|
41
42
|
- [metric](functions/metric.md)
|
|
42
43
|
- [next](functions/next.md)
|
|
43
44
|
- [rewrite](functions/rewrite.md)
|
|
45
|
+
- [unstable_getAffinityHeaders](functions/unstable_getAffinityHeaders.md)
|
|
46
|
+
- [unstable_getAffinityId](functions/unstable_getAffinityId.md)
|
|
44
47
|
- [upgradeWebSocket](functions/upgradeWebSocket.md)
|
|
45
48
|
- [waitUntil](functions/waitUntil.md)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[**@vercel/functions**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# Function: unstable\_getAffinityHeaders()
|
|
6
|
+
|
|
7
|
+
> **unstable\_getAffinityHeaders**(`options`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)\<`string`, `string`\>\>
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/functions/src/affinity.ts:75](https://github.com/vercel/vercel/blob/main/packages/functions/src/affinity.ts#L75)
|
|
10
|
+
|
|
11
|
+
**`Experimental`**
|
|
12
|
+
|
|
13
|
+
Returns request headers for invoking a Vercel Function with an explicit
|
|
14
|
+
affinity ID. Set `oidc: true` to include the current project's OIDC token;
|
|
15
|
+
service-binding URLs authenticate independently.
|
|
16
|
+
|
|
17
|
+
This is an experimental API and may change without notice.
|
|
18
|
+
|
|
19
|
+
The returned object can be passed to `fetch` or another HTTP client, or
|
|
20
|
+
combined with other headers. Enable OIDC only for functions you intend to
|
|
21
|
+
receive the project's token, and avoid forwarding it through redirects to
|
|
22
|
+
untrusted destinations.
|
|
23
|
+
|
|
24
|
+
## Parameters
|
|
25
|
+
|
|
26
|
+
### options
|
|
27
|
+
|
|
28
|
+
[`GetAffinityHeadersOptions`](../type-aliases/GetAffinityHeadersOptions.md)
|
|
29
|
+
|
|
30
|
+
The required affinity ID and optional OIDC setting.
|
|
31
|
+
|
|
32
|
+
## Returns
|
|
33
|
+
|
|
34
|
+
[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<[`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)\<`string`, `string`\>\>
|
|
35
|
+
|
|
36
|
+
A plain object containing `x-vercel-affinity-id` and, when enabled,
|
|
37
|
+
`x-vercel-trusted-oidc-idp-token`.
|
|
38
|
+
|
|
39
|
+
## Example
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import { unstable_getAffinityHeaders } from '@vercel/functions';
|
|
43
|
+
|
|
44
|
+
const headers = await unstable_getAffinityHeaders({
|
|
45
|
+
affinityId: 'room:123',
|
|
46
|
+
oidc: true,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const response = await fetch('https://my-project.vercel.app/api/actor', {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers: { ...headers, 'content-type': 'application/json' },
|
|
52
|
+
body: JSON.stringify({ action: 'join' }),
|
|
53
|
+
redirect: 'error',
|
|
54
|
+
});
|
|
55
|
+
```
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[**@vercel/functions**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# Function: unstable\_getAffinityId()
|
|
6
|
+
|
|
7
|
+
> **unstable\_getAffinityId**(): `string` \| `undefined`
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/functions/src/affinity.ts:37](https://github.com/vercel/vercel/blob/main/packages/functions/src/affinity.ts#L37)
|
|
10
|
+
|
|
11
|
+
**`Experimental`**
|
|
12
|
+
|
|
13
|
+
Returns the affinity ID from the current invocation's
|
|
14
|
+
`x-vercel-affinity-id` header, or `undefined` when it is unavailable.
|
|
15
|
+
|
|
16
|
+
This is an experimental API and may change without notice.
|
|
17
|
+
|
|
18
|
+
## Returns
|
|
19
|
+
|
|
20
|
+
`string` \| `undefined`
|
|
21
|
+
|
|
22
|
+
## Example
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { unstable_getAffinityId } from '@vercel/functions';
|
|
26
|
+
|
|
27
|
+
const affinityId = unstable_getAffinityId();
|
|
28
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[**@vercel/functions**](../../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# Type Alias: GetAffinityHeadersOptions
|
|
6
|
+
|
|
7
|
+
> **GetAffinityHeadersOptions** = `object`
|
|
8
|
+
|
|
9
|
+
Defined in: [packages/functions/src/affinity.ts:9](https://github.com/vercel/vercel/blob/main/packages/functions/src/affinity.ts#L9)
|
|
10
|
+
|
|
11
|
+
Options for the experimental affinity header API.
|
|
12
|
+
|
|
13
|
+
## Properties
|
|
14
|
+
|
|
15
|
+
### affinityId
|
|
16
|
+
|
|
17
|
+
> **affinityId**: `string`
|
|
18
|
+
|
|
19
|
+
Defined in: [packages/functions/src/affinity.ts:14](https://github.com/vercel/vercel/blob/main/packages/functions/src/affinity.ts#L14)
|
|
20
|
+
|
|
21
|
+
The affinity ID to route this request to. Must contain 1 to 256 visible
|
|
22
|
+
ASCII characters, without spaces.
|
|
23
|
+
|
|
24
|
+
***
|
|
25
|
+
|
|
26
|
+
### oidc?
|
|
27
|
+
|
|
28
|
+
> `optional` **oidc?**: `boolean`
|
|
29
|
+
|
|
30
|
+
Defined in: [packages/functions/src/affinity.ts:20](https://github.com/vercel/vercel/blob/main/packages/functions/src/affinity.ts#L20)
|
|
31
|
+
|
|
32
|
+
Whether to attach the current project's OIDC token. Enable only for a
|
|
33
|
+
trusted destination. Service-binding URLs do not require this option.
|
|
34
|
+
|
|
35
|
+
#### Default
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
false
|
|
39
|
+
```
|
package/index.d.ts
CHANGED
|
@@ -15,3 +15,5 @@ export type { AddCacheTagApi } from './addcachetag/types';
|
|
|
15
15
|
export { upgradeWebSocket, experimental_upgradeWebSocket } from './websocket';
|
|
16
16
|
export type { UpgradeWebSocketOptions } from './websocket';
|
|
17
17
|
export type { WebSocket, RawData as WebSocketData } from 'ws';
|
|
18
|
+
export { unstable_getAffinityId, unstable_getAffinityHeaders, } from './affinity';
|
|
19
|
+
export type { GetAffinityHeadersOptions } from './affinity';
|
package/index.js
CHANGED
|
@@ -34,6 +34,8 @@ __export(src_exports, {
|
|
|
34
34
|
metric: () => import_metric.metric,
|
|
35
35
|
next: () => import_middleware.next,
|
|
36
36
|
rewrite: () => import_middleware.rewrite,
|
|
37
|
+
unstable_getAffinityHeaders: () => import_affinity.unstable_getAffinityHeaders,
|
|
38
|
+
unstable_getAffinityId: () => import_affinity.unstable_getAffinityId,
|
|
37
39
|
upgradeWebSocket: () => import_websocket.upgradeWebSocket,
|
|
38
40
|
waitUntil: () => import_wait_until.waitUntil
|
|
39
41
|
});
|
|
@@ -49,6 +51,7 @@ var import_db_connections = require("./db-connections");
|
|
|
49
51
|
var import_purge = require("./purge");
|
|
50
52
|
var import_addcachetag = require("./addcachetag");
|
|
51
53
|
var import_websocket = require("./websocket");
|
|
54
|
+
var import_affinity = require("./affinity");
|
|
52
55
|
// Annotate the CommonJS export names for ESM import in node:
|
|
53
56
|
0 && (module.exports = {
|
|
54
57
|
addCacheTag,
|
|
@@ -67,6 +70,8 @@ var import_websocket = require("./websocket");
|
|
|
67
70
|
metric,
|
|
68
71
|
next,
|
|
69
72
|
rewrite,
|
|
73
|
+
unstable_getAffinityHeaders,
|
|
74
|
+
unstable_getAffinityId,
|
|
70
75
|
upgradeWebSocket,
|
|
71
76
|
waitUntil
|
|
72
77
|
});
|
package/package.json
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"require": "./middleware.js"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
"version": "3.
|
|
33
|
+
"version": "3.11.0-snapshot-d1023ee75c2c",
|
|
34
34
|
"repository": {
|
|
35
35
|
"directory": "packages/functions",
|
|
36
36
|
"type": "git",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"access": "public"
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
|
-
"@vercel/oidc": "4.0.
|
|
80
|
+
"@vercel/oidc": "4.0.7-snapshot-d1023ee75c2c"
|
|
81
81
|
},
|
|
82
82
|
"scripts": {
|
|
83
83
|
"pretest": "pnpm run build:code",
|