@vercel/connect 0.2.10 → 0.3.1
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/README.md +23 -1
- package/dist/chat/github-adapter.d.ts +43 -0
- package/dist/chat/github-adapter.js +39 -0
- package/dist/chat/index.d.ts +27 -0
- package/dist/chat/index.js +26 -0
- package/dist/chat/linear-adapter.d.ts +40 -0
- package/dist/chat/linear-adapter.js +37 -0
- package/dist/chat/slack-adapter.d.ts +52 -0
- package/dist/chat/slack-adapter.js +39 -0
- package/dist/chat/types.d.ts +28 -0
- package/dist/chat/types.js +1 -0
- package/dist/chat/webhook-verifier.d.ts +51 -0
- package/dist/chat/webhook-verifier.js +47 -0
- package/package.json +11 -2
package/README.md
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
SDK for obtaining scoped tokens for third-party services on behalf of apps or users. Authenticates the calling Vercel project via [`@vercel/oidc`](https://www.npmjs.com/package/@vercel/oidc) and exchanges the OIDC token for a Vercel Connect-issued credential.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Seven entrypoints, all ESM:
|
|
6
6
|
|
|
7
7
|
- `@vercel/connect` — core token / authorization SDK
|
|
8
|
+
- `@vercel/connect/chat` — adapter helpers for the [Chat SDK](https://chat-sdk.dev) (`chat`): `connectSlackAdapter`, `connectGitHubAdapter`, `connectLinearAdapter` (no Chat SDK dependency — returns structural config)
|
|
8
9
|
- `@vercel/connect/ai-sdk` — [Vercel AI SDK](https://ai-sdk.dev) glue: re-exports `connectAuthProvider` for MCP transports (optional peers: `ai`, `@ai-sdk/mcp`)
|
|
9
10
|
- `@vercel/connect/mcp` — canonical MCP-spec `OAuthClientProvider` for any MCP client (optional peer: `@ai-sdk/mcp`)
|
|
10
11
|
- `@vercel/connect/eve` — adapter helpers for [Eve](https://github.com/vercel/eve) connections (optional peer: `eve`)
|
|
@@ -29,6 +30,27 @@ const token = await getToken(process.env.CONNECTOR_LINEAR!, {
|
|
|
29
30
|
});
|
|
30
31
|
```
|
|
31
32
|
|
|
33
|
+
### Chat SDK
|
|
34
|
+
|
|
35
|
+
Spread the helper into the matching `create*Adapter` factory. Each helper
|
|
36
|
+
wires both outbound app-scoped tokens and inbound Connect trigger-forwarded
|
|
37
|
+
webhook verification (Vercel OIDC), so no provider secret lives in your env.
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { createSlackAdapter } from '@chat-adapter/slack';
|
|
41
|
+
import { connectSlackAdapter } from '@vercel/connect/chat';
|
|
42
|
+
|
|
43
|
+
createSlackAdapter({
|
|
44
|
+
...connectSlackAdapter('slack/acme-slack'),
|
|
45
|
+
userName: 'my-bot',
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`connectGitHubAdapter` (`installationToken`) and `connectLinearAdapter`
|
|
50
|
+
(`accessToken`) follow the same shape. See the
|
|
51
|
+
[Chat SDK integration guide](https://github.com/vercel/vercel/blob/main/packages/connect/docs/chat-integration.md)
|
|
52
|
+
for connector setup, trigger forwarding, and per-platform examples.
|
|
53
|
+
|
|
32
54
|
### Vercel AI SDK + MCP
|
|
33
55
|
|
|
34
56
|
```ts
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type ConnectOptions, type ConnectTokenParams } from '../index.js';
|
|
2
|
+
import type { ConnectGitHubAdapterConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Token parameters accepted by {@link connectGitHubAdapter}.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors {@link ConnectTokenParams} from `@vercel/connect`, minus
|
|
7
|
+
* `subject` — the helper acts as the application itself, so `subject`
|
|
8
|
+
* is pinned to `{ type: "app" }` and cannot be overridden. (The issued
|
|
9
|
+
* GitHub credential is an installation-scoped access token.)
|
|
10
|
+
*/
|
|
11
|
+
export type ConnectGitHubAdapterParams = Omit<ConnectTokenParams, 'subject'>;
|
|
12
|
+
/**
|
|
13
|
+
* Build a GitHub adapter config fragment backed by a Vercel Connect
|
|
14
|
+
* connector that stores a GitHub installation access token.
|
|
15
|
+
*
|
|
16
|
+
* Spread the result into `createGitHubAdapter` from
|
|
17
|
+
* `@chat-adapter/github`:
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { createGitHubAdapter } from "@chat-adapter/github";
|
|
21
|
+
* import { connectGitHubAdapter } from "@vercel/connect/chat";
|
|
22
|
+
*
|
|
23
|
+
* createGitHubAdapter({
|
|
24
|
+
* ...connectGitHubAdapter("github/acme-github"),
|
|
25
|
+
* userName: "my-bot[bot]",
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* The returned `installationToken` is the installation access token a
|
|
30
|
+
* GitHub App would normally mint via its private-key JWT exchange — the
|
|
31
|
+
* adapter uses it directly and skips that exchange. The token is a
|
|
32
|
+
* function form so rotation, refresh, and installation tenancy stay
|
|
33
|
+
* delegated to Vercel Connect.
|
|
34
|
+
*
|
|
35
|
+
* `webhookVerifier` validates Connect trigger-forwarded webhooks via the
|
|
36
|
+
* Vercel OIDC token Connect attaches, replacing GitHub's webhook-secret
|
|
37
|
+
* check.
|
|
38
|
+
*
|
|
39
|
+
* The optional `params` and `options` arguments mirror the signature of
|
|
40
|
+
* {@link getToken}, allowing callers to pass through fields like
|
|
41
|
+
* `installationId`, `scopes`, or `validityBufferMs`.
|
|
42
|
+
*/
|
|
43
|
+
export declare function connectGitHubAdapter(connector: string, params?: ConnectGitHubAdapterParams, options?: ConnectOptions): ConnectGitHubAdapterConfig;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getToken, } from '../index.js';
|
|
2
|
+
import { createConnectWebhookVerifier } from './webhook-verifier.js';
|
|
3
|
+
/**
|
|
4
|
+
* Build a GitHub adapter config fragment backed by a Vercel Connect
|
|
5
|
+
* connector that stores a GitHub installation access token.
|
|
6
|
+
*
|
|
7
|
+
* Spread the result into `createGitHubAdapter` from
|
|
8
|
+
* `@chat-adapter/github`:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createGitHubAdapter } from "@chat-adapter/github";
|
|
12
|
+
* import { connectGitHubAdapter } from "@vercel/connect/chat";
|
|
13
|
+
*
|
|
14
|
+
* createGitHubAdapter({
|
|
15
|
+
* ...connectGitHubAdapter("github/acme-github"),
|
|
16
|
+
* userName: "my-bot[bot]",
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The returned `installationToken` is the installation access token a
|
|
21
|
+
* GitHub App would normally mint via its private-key JWT exchange — the
|
|
22
|
+
* adapter uses it directly and skips that exchange. The token is a
|
|
23
|
+
* function form so rotation, refresh, and installation tenancy stay
|
|
24
|
+
* delegated to Vercel Connect.
|
|
25
|
+
*
|
|
26
|
+
* `webhookVerifier` validates Connect trigger-forwarded webhooks via the
|
|
27
|
+
* Vercel OIDC token Connect attaches, replacing GitHub's webhook-secret
|
|
28
|
+
* check.
|
|
29
|
+
*
|
|
30
|
+
* The optional `params` and `options` arguments mirror the signature of
|
|
31
|
+
* {@link getToken}, allowing callers to pass through fields like
|
|
32
|
+
* `installationId`, `scopes`, or `validityBufferMs`.
|
|
33
|
+
*/
|
|
34
|
+
export function connectGitHubAdapter(connector, params = {}, options) {
|
|
35
|
+
return {
|
|
36
|
+
installationToken: () => getToken(connector, { ...params, subject: { type: 'app' } }, options),
|
|
37
|
+
webhookVerifier: createConnectWebhookVerifier(),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of the `@vercel/connect/chat` subpath.
|
|
3
|
+
*
|
|
4
|
+
* Holds helpers that adapt the Vercel Connect SDK to the Chat SDK
|
|
5
|
+
* (`chat`) platform adapters. Each helper returns a config fragment you
|
|
6
|
+
* spread into the matching `create*Adapter` factory, wiring a Connect
|
|
7
|
+
* connector for both outbound tokens (`getToken`) and inbound
|
|
8
|
+
* trigger-forwarded webhooks (Vercel OIDC verification).
|
|
9
|
+
*
|
|
10
|
+
* The helpers stay decoupled from `@chat-adapter/*`: they return
|
|
11
|
+
* structural config types rather than importing the adapter packages,
|
|
12
|
+
* so this subpath has no Chat SDK dependency.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { createSlackAdapter } from "@chat-adapter/slack";
|
|
16
|
+
* import { connectSlackAdapter } from "@vercel/connect/chat";
|
|
17
|
+
*
|
|
18
|
+
* createSlackAdapter({
|
|
19
|
+
* ...connectSlackAdapter("slack/acme-slack"),
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export { createConnectWebhookVerifier, type ConnectWebhookVerifier, type ConnectWebhookVerifierOptions, } from './webhook-verifier.js';
|
|
24
|
+
export type { ConnectGitHubAdapterConfig, ConnectLinearAdapterConfig, ConnectTokenResolver, } from './types.js';
|
|
25
|
+
export { connectSlackAdapter, type ConnectSlackAdapterConfig, type ConnectSlackAdapterParams, } from './slack-adapter.js';
|
|
26
|
+
export { connectGitHubAdapter, type ConnectGitHubAdapterParams, } from './github-adapter.js';
|
|
27
|
+
export { connectLinearAdapter, type ConnectLinearAdapterParams, } from './linear-adapter.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of the `@vercel/connect/chat` subpath.
|
|
3
|
+
*
|
|
4
|
+
* Holds helpers that adapt the Vercel Connect SDK to the Chat SDK
|
|
5
|
+
* (`chat`) platform adapters. Each helper returns a config fragment you
|
|
6
|
+
* spread into the matching `create*Adapter` factory, wiring a Connect
|
|
7
|
+
* connector for both outbound tokens (`getToken`) and inbound
|
|
8
|
+
* trigger-forwarded webhooks (Vercel OIDC verification).
|
|
9
|
+
*
|
|
10
|
+
* The helpers stay decoupled from `@chat-adapter/*`: they return
|
|
11
|
+
* structural config types rather than importing the adapter packages,
|
|
12
|
+
* so this subpath has no Chat SDK dependency.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { createSlackAdapter } from "@chat-adapter/slack";
|
|
16
|
+
* import { connectSlackAdapter } from "@vercel/connect/chat";
|
|
17
|
+
*
|
|
18
|
+
* createSlackAdapter({
|
|
19
|
+
* ...connectSlackAdapter("slack/acme-slack"),
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export { createConnectWebhookVerifier, } from './webhook-verifier.js';
|
|
24
|
+
export { connectSlackAdapter, } from './slack-adapter.js';
|
|
25
|
+
export { connectGitHubAdapter, } from './github-adapter.js';
|
|
26
|
+
export { connectLinearAdapter, } from './linear-adapter.js';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type ConnectOptions, type ConnectTokenParams } from '../index.js';
|
|
2
|
+
import type { ConnectLinearAdapterConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Token parameters accepted by {@link connectLinearAdapter}.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors {@link ConnectTokenParams} from `@vercel/connect`, minus
|
|
7
|
+
* `subject` — Linear app tokens are app-scoped, so `subject` is pinned
|
|
8
|
+
* to `{ type: "app" }` by this helper and cannot be overridden.
|
|
9
|
+
*/
|
|
10
|
+
export type ConnectLinearAdapterParams = Omit<ConnectTokenParams, 'subject'>;
|
|
11
|
+
/**
|
|
12
|
+
* Build a Linear adapter config fragment backed by a Vercel Connect
|
|
13
|
+
* connector that stores a Linear app access token.
|
|
14
|
+
*
|
|
15
|
+
* Spread the result into `createLinearAdapter` from
|
|
16
|
+
* `@chat-adapter/linear`:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { createLinearAdapter } from "@chat-adapter/linear";
|
|
20
|
+
* import { connectLinearAdapter } from "@vercel/connect/chat";
|
|
21
|
+
*
|
|
22
|
+
* createLinearAdapter({
|
|
23
|
+
* ...connectLinearAdapter("linear/acme-linear"),
|
|
24
|
+
* mode: "agent-sessions",
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The returned `accessToken` is the token the adapter uses for Linear
|
|
29
|
+
* GraphQL calls. It is a function form so rotation, refresh, and
|
|
30
|
+
* multi-workspace tenancy stay delegated to Vercel Connect.
|
|
31
|
+
*
|
|
32
|
+
* `webhookVerifier` validates Connect trigger-forwarded webhooks via the
|
|
33
|
+
* Vercel OIDC token Connect attaches, replacing Linear's
|
|
34
|
+
* webhook-secret check.
|
|
35
|
+
*
|
|
36
|
+
* The optional `params` and `options` arguments mirror the signature of
|
|
37
|
+
* {@link getToken}, allowing callers to pass through fields like
|
|
38
|
+
* `installationId`, `scopes`, or `validityBufferMs`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function connectLinearAdapter(connector: string, params?: ConnectLinearAdapterParams, options?: ConnectOptions): ConnectLinearAdapterConfig;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getToken, } from '../index.js';
|
|
2
|
+
import { createConnectWebhookVerifier } from './webhook-verifier.js';
|
|
3
|
+
/**
|
|
4
|
+
* Build a Linear adapter config fragment backed by a Vercel Connect
|
|
5
|
+
* connector that stores a Linear app access token.
|
|
6
|
+
*
|
|
7
|
+
* Spread the result into `createLinearAdapter` from
|
|
8
|
+
* `@chat-adapter/linear`:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createLinearAdapter } from "@chat-adapter/linear";
|
|
12
|
+
* import { connectLinearAdapter } from "@vercel/connect/chat";
|
|
13
|
+
*
|
|
14
|
+
* createLinearAdapter({
|
|
15
|
+
* ...connectLinearAdapter("linear/acme-linear"),
|
|
16
|
+
* mode: "agent-sessions",
|
|
17
|
+
* });
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The returned `accessToken` is the token the adapter uses for Linear
|
|
21
|
+
* GraphQL calls. It is a function form so rotation, refresh, and
|
|
22
|
+
* multi-workspace tenancy stay delegated to Vercel Connect.
|
|
23
|
+
*
|
|
24
|
+
* `webhookVerifier` validates Connect trigger-forwarded webhooks via the
|
|
25
|
+
* Vercel OIDC token Connect attaches, replacing Linear's
|
|
26
|
+
* webhook-secret check.
|
|
27
|
+
*
|
|
28
|
+
* The optional `params` and `options` arguments mirror the signature of
|
|
29
|
+
* {@link getToken}, allowing callers to pass through fields like
|
|
30
|
+
* `installationId`, `scopes`, or `validityBufferMs`.
|
|
31
|
+
*/
|
|
32
|
+
export function connectLinearAdapter(connector, params = {}, options) {
|
|
33
|
+
return {
|
|
34
|
+
accessToken: () => getToken(connector, { ...params, subject: { type: 'app' } }, options),
|
|
35
|
+
webhookVerifier: createConnectWebhookVerifier(),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { SlackAdapterConfig } from '@chat-adapter/slack';
|
|
2
|
+
import { type ConnectOptions, type ConnectTokenParams } from '../index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Token parameters accepted by {@link connectSlackAdapter}.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors {@link ConnectTokenParams} from `@vercel/connect`, minus
|
|
7
|
+
* `subject` — Slack bot tokens are always app-scoped, so `subject`
|
|
8
|
+
* is pinned to `{ type: "app" }` by this helper and cannot be
|
|
9
|
+
* overridden.
|
|
10
|
+
*/
|
|
11
|
+
export type ConnectSlackAdapterParams = Omit<ConnectTokenParams, 'subject'>;
|
|
12
|
+
/**
|
|
13
|
+
* Slack adapter config fragment produced by {@link connectSlackAdapter}.
|
|
14
|
+
*
|
|
15
|
+
* Derived from `@chat-adapter/slack`'s `SlackAdapterConfig` so the helper's
|
|
16
|
+
* output is type-checked against the real adapter config at compile time.
|
|
17
|
+
* `@chat-adapter/slack` is an optional peer dependency used for types only —
|
|
18
|
+
* there is no runtime dependency on the Chat SDK.
|
|
19
|
+
*/
|
|
20
|
+
export type ConnectSlackAdapterConfig = Required<Pick<SlackAdapterConfig, 'botToken' | 'webhookVerifier'>>;
|
|
21
|
+
/**
|
|
22
|
+
* Build a Slack adapter config fragment backed by a Vercel Connect
|
|
23
|
+
* connector that stores a Slack workspace's bot token.
|
|
24
|
+
*
|
|
25
|
+
* Spread the result into `createSlackAdapter` from `@chat-adapter/slack`:
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { createSlackAdapter } from "@chat-adapter/slack";
|
|
29
|
+
* import { connectSlackAdapter } from "@vercel/connect/chat";
|
|
30
|
+
*
|
|
31
|
+
* createSlackAdapter({
|
|
32
|
+
* ...connectSlackAdapter("slack/acme-slack"),
|
|
33
|
+
* userName: "my-bot",
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* The returned `botToken` is a function form, invoked once per Slack
|
|
38
|
+
* API call so the adapter always picks up a fresh token from Vercel
|
|
39
|
+
* Connect (rotation, refresh, and multi-workspace tenancy are handled
|
|
40
|
+
* server-side). Slack bot tokens are app-scoped — one token per
|
|
41
|
+
* workspace install — so this helper calls Vercel Connect with
|
|
42
|
+
* `subject: { type: "app" }`.
|
|
43
|
+
*
|
|
44
|
+
* `webhookVerifier` validates Connect trigger-forwarded webhooks via the
|
|
45
|
+
* Vercel OIDC token Connect attaches, replacing Slack's signing-secret
|
|
46
|
+
* check. Omit `signingSecret` / `SLACK_SIGNING_SECRET` when using this.
|
|
47
|
+
*
|
|
48
|
+
* The optional `params` and `options` arguments mirror the signature of
|
|
49
|
+
* {@link getToken}, allowing callers to pass through fields like
|
|
50
|
+
* `installationId`, `scopes`, or `validityBufferMs`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function connectSlackAdapter(connector: string, params?: ConnectSlackAdapterParams, options?: ConnectOptions): ConnectSlackAdapterConfig;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getToken, } from '../index.js';
|
|
2
|
+
import { createConnectWebhookVerifier } from './webhook-verifier.js';
|
|
3
|
+
/**
|
|
4
|
+
* Build a Slack adapter config fragment backed by a Vercel Connect
|
|
5
|
+
* connector that stores a Slack workspace's bot token.
|
|
6
|
+
*
|
|
7
|
+
* Spread the result into `createSlackAdapter` from `@chat-adapter/slack`:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createSlackAdapter } from "@chat-adapter/slack";
|
|
11
|
+
* import { connectSlackAdapter } from "@vercel/connect/chat";
|
|
12
|
+
*
|
|
13
|
+
* createSlackAdapter({
|
|
14
|
+
* ...connectSlackAdapter("slack/acme-slack"),
|
|
15
|
+
* userName: "my-bot",
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* The returned `botToken` is a function form, invoked once per Slack
|
|
20
|
+
* API call so the adapter always picks up a fresh token from Vercel
|
|
21
|
+
* Connect (rotation, refresh, and multi-workspace tenancy are handled
|
|
22
|
+
* server-side). Slack bot tokens are app-scoped — one token per
|
|
23
|
+
* workspace install — so this helper calls Vercel Connect with
|
|
24
|
+
* `subject: { type: "app" }`.
|
|
25
|
+
*
|
|
26
|
+
* `webhookVerifier` validates Connect trigger-forwarded webhooks via the
|
|
27
|
+
* Vercel OIDC token Connect attaches, replacing Slack's signing-secret
|
|
28
|
+
* check. Omit `signingSecret` / `SLACK_SIGNING_SECRET` when using this.
|
|
29
|
+
*
|
|
30
|
+
* The optional `params` and `options` arguments mirror the signature of
|
|
31
|
+
* {@link getToken}, allowing callers to pass through fields like
|
|
32
|
+
* `installationId`, `scopes`, or `validityBufferMs`.
|
|
33
|
+
*/
|
|
34
|
+
export function connectSlackAdapter(connector, params = {}, options) {
|
|
35
|
+
return {
|
|
36
|
+
botToken: () => getToken(connector, { ...params, subject: { type: 'app' } }, options),
|
|
37
|
+
webhookVerifier: createConnectWebhookVerifier(),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ConnectWebhookVerifier } from './webhook-verifier.js';
|
|
2
|
+
/**
|
|
3
|
+
* Function form of a Chat SDK adapter token field. The adapter invokes
|
|
4
|
+
* it per API call, so it composes naturally with Vercel Connect's
|
|
5
|
+
* short-lived tokens — each call returns a fresh token (the
|
|
6
|
+
* `@vercel/connect` SDK caches and refreshes server-side).
|
|
7
|
+
*/
|
|
8
|
+
export type ConnectTokenResolver = () => Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Partial GitHub adapter config backed by Vercel Connect.
|
|
11
|
+
*
|
|
12
|
+
* Structurally matches the `installationToken` and `webhookVerifier`
|
|
13
|
+
* options of `createGitHubAdapter` from `@chat-adapter/github`.
|
|
14
|
+
*/
|
|
15
|
+
export interface ConnectGitHubAdapterConfig {
|
|
16
|
+
installationToken: ConnectTokenResolver;
|
|
17
|
+
webhookVerifier: ConnectWebhookVerifier;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Partial Linear adapter config backed by Vercel Connect.
|
|
21
|
+
*
|
|
22
|
+
* Structurally matches the `accessToken` and `webhookVerifier` options
|
|
23
|
+
* of `createLinearAdapter` from `@chat-adapter/linear`.
|
|
24
|
+
*/
|
|
25
|
+
export interface ConnectLinearAdapterConfig {
|
|
26
|
+
accessToken: ConnectTokenResolver;
|
|
27
|
+
webhookVerifier: ConnectWebhookVerifier;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { verifyVercelOidcToken } from '@vercel/oidc';
|
|
2
|
+
/**
|
|
3
|
+
* Webhook verifier signature used by Chat SDK adapters. Returning a
|
|
4
|
+
* truthy value marks the request as verified; throwing (or returning a
|
|
5
|
+
* falsy value) makes the adapter respond `401`.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the `webhookVerifier` option accepted by the Slack, GitHub,
|
|
8
|
+
* and Linear adapters from the `chat` package, so the helpers in this
|
|
9
|
+
* subpath stay decoupled from `@chat-adapter/*` while remaining
|
|
10
|
+
* structurally compatible.
|
|
11
|
+
*/
|
|
12
|
+
export type ConnectWebhookVerifier = (request: Request, body: string) => Promise<unknown> | unknown;
|
|
13
|
+
/**
|
|
14
|
+
* Options forwarded to {@link verifyVercelOidcToken}. Defaults to
|
|
15
|
+
* matching `project_id` / `environment` against the current Vercel
|
|
16
|
+
* deployment's `VERCEL_PROJECT_ID` and `VERCEL_TARGET_ENV` / `VERCEL_ENV`.
|
|
17
|
+
*/
|
|
18
|
+
export type ConnectWebhookVerifierOptions = Parameters<typeof verifyVercelOidcToken>[1];
|
|
19
|
+
/**
|
|
20
|
+
* Build a webhook verifier for Vercel Connect trigger-forwarded
|
|
21
|
+
* webhooks.
|
|
22
|
+
*
|
|
23
|
+
* When Vercel Connect forwards a verified provider webhook to your
|
|
24
|
+
* project, it attaches a Vercel OIDC token as a `Bearer` credential in
|
|
25
|
+
* the `Authorization` header. This verifier extracts that token and
|
|
26
|
+
* validates it against Vercel's JWKS via
|
|
27
|
+
* {@link verifyVercelOidcToken}, replacing the provider's native
|
|
28
|
+
* signature check (Slack signing secret, GitHub webhook secret, Linear
|
|
29
|
+
* webhook secret).
|
|
30
|
+
*
|
|
31
|
+
* Trust boundary: by default the token must be issued by
|
|
32
|
+
* `https://oidc.vercel.com` (issuer is hard-pinned) and match the
|
|
33
|
+
* current deployment's project and environment (`projectId` defaults to
|
|
34
|
+
* `VERCEL_PROJECT_ID`, `environment` to `VERCEL_TARGET_ENV` then
|
|
35
|
+
* `VERCEL_ENV`). Verification fails closed — if those values are absent
|
|
36
|
+
* and not supplied via `options`, every request is rejected. The
|
|
37
|
+
* accepted set is therefore "any Vercel OIDC token for this
|
|
38
|
+
* project + environment"; it is not pinned to a specific Connect
|
|
39
|
+
* connector or to a single deployment. To tighten or broaden it (extra
|
|
40
|
+
* audiences, multiple environments, an explicit project id), pass
|
|
41
|
+
* `options` through to {@link verifyVercelOidcToken}.
|
|
42
|
+
*
|
|
43
|
+
* Pass it as the `webhookVerifier` option to a Chat SDK adapter:
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* createSlackAdapter({
|
|
47
|
+
* webhookVerifier: createConnectWebhookVerifier(),
|
|
48
|
+
* });
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function createConnectWebhookVerifier(options?: ConnectWebhookVerifierOptions): ConnectWebhookVerifier;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { verifyVercelOidcToken } from '@vercel/oidc';
|
|
2
|
+
const BEARER_TOKEN_PATTERN = /^Bearer\s+(.+)$/i;
|
|
3
|
+
/**
|
|
4
|
+
* Build a webhook verifier for Vercel Connect trigger-forwarded
|
|
5
|
+
* webhooks.
|
|
6
|
+
*
|
|
7
|
+
* When Vercel Connect forwards a verified provider webhook to your
|
|
8
|
+
* project, it attaches a Vercel OIDC token as a `Bearer` credential in
|
|
9
|
+
* the `Authorization` header. This verifier extracts that token and
|
|
10
|
+
* validates it against Vercel's JWKS via
|
|
11
|
+
* {@link verifyVercelOidcToken}, replacing the provider's native
|
|
12
|
+
* signature check (Slack signing secret, GitHub webhook secret, Linear
|
|
13
|
+
* webhook secret).
|
|
14
|
+
*
|
|
15
|
+
* Trust boundary: by default the token must be issued by
|
|
16
|
+
* `https://oidc.vercel.com` (issuer is hard-pinned) and match the
|
|
17
|
+
* current deployment's project and environment (`projectId` defaults to
|
|
18
|
+
* `VERCEL_PROJECT_ID`, `environment` to `VERCEL_TARGET_ENV` then
|
|
19
|
+
* `VERCEL_ENV`). Verification fails closed — if those values are absent
|
|
20
|
+
* and not supplied via `options`, every request is rejected. The
|
|
21
|
+
* accepted set is therefore "any Vercel OIDC token for this
|
|
22
|
+
* project + environment"; it is not pinned to a specific Connect
|
|
23
|
+
* connector or to a single deployment. To tighten or broaden it (extra
|
|
24
|
+
* audiences, multiple environments, an explicit project id), pass
|
|
25
|
+
* `options` through to {@link verifyVercelOidcToken}.
|
|
26
|
+
*
|
|
27
|
+
* Pass it as the `webhookVerifier` option to a Chat SDK adapter:
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* createSlackAdapter({
|
|
31
|
+
* webhookVerifier: createConnectWebhookVerifier(),
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function createConnectWebhookVerifier(options) {
|
|
36
|
+
return async (request, _body) => {
|
|
37
|
+
const token = request.headers
|
|
38
|
+
.get('authorization')
|
|
39
|
+
?.match(BEARER_TOKEN_PATTERN)?.[1]
|
|
40
|
+
?.trim();
|
|
41
|
+
if (!token) {
|
|
42
|
+
throw new Error('Missing Authorization bearer token');
|
|
43
|
+
}
|
|
44
|
+
await verifyVercelOidcToken(token, options);
|
|
45
|
+
return true;
|
|
46
|
+
};
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/connect",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
14
|
"default": "./dist/index.js"
|
|
15
15
|
},
|
|
16
|
+
"./chat": {
|
|
17
|
+
"types": "./dist/chat/index.d.ts",
|
|
18
|
+
"default": "./dist/chat/index.js"
|
|
19
|
+
},
|
|
16
20
|
"./eve": {
|
|
17
21
|
"types": "./dist/eve/index.d.ts",
|
|
18
22
|
"default": "./dist/eve/index.js"
|
|
@@ -38,11 +42,12 @@
|
|
|
38
42
|
"dist"
|
|
39
43
|
],
|
|
40
44
|
"dependencies": {
|
|
41
|
-
"@vercel/oidc": "3.
|
|
45
|
+
"@vercel/oidc": "3.8.0"
|
|
42
46
|
},
|
|
43
47
|
"peerDependencies": {
|
|
44
48
|
"@ai-sdk/mcp": "^1 || ^2",
|
|
45
49
|
"@auth/core": ">=0.37.0",
|
|
50
|
+
"@chat-adapter/slack": "^4.0.0",
|
|
46
51
|
"ai": "^6 || ^7.0.0-beta.0",
|
|
47
52
|
"better-auth": ">=1.5.0",
|
|
48
53
|
"eve": ">=0.13.7"
|
|
@@ -54,6 +59,9 @@
|
|
|
54
59
|
"@auth/core": {
|
|
55
60
|
"optional": true
|
|
56
61
|
},
|
|
62
|
+
"@chat-adapter/slack": {
|
|
63
|
+
"optional": true
|
|
64
|
+
},
|
|
57
65
|
"ai": {
|
|
58
66
|
"optional": true
|
|
59
67
|
},
|
|
@@ -67,6 +75,7 @@
|
|
|
67
75
|
"devDependencies": {
|
|
68
76
|
"@ai-sdk/mcp": "2.0.0-beta.37",
|
|
69
77
|
"@auth/core": "0.37.4",
|
|
78
|
+
"@chat-adapter/slack": "4.31.0",
|
|
70
79
|
"ai": "7.0.0-beta.116",
|
|
71
80
|
"better-auth": "1.5.5",
|
|
72
81
|
"eve": "0.6.0-beta.1",
|