@vercel/connect 2.9.2 → 2.9.3-snapshot-579f9b2619d8

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 CHANGED
@@ -32,6 +32,19 @@ const token = await getToken(process.env.CONNECTOR_LINEAR!, {
32
32
  });
33
33
  ```
34
34
 
35
+ Connect API options also accept `teamId?: string` and `orgId?: string`,
36
+ including token, authorization, installation, connector metadata, and MCP APIs.
37
+ Each supplied value is sent as a query parameter; when both are supplied, both
38
+ are sent. Token caches are isolated by these values.
39
+
40
+ ```ts
41
+ const token = await getToken(
42
+ 'oauth/linear',
43
+ { subject: { type: 'app' } },
44
+ { vercelToken: process.env.VERCEL_TOKEN, teamId: 'team_123' }
45
+ );
46
+ ```
47
+
35
48
  For a Passport-authenticated user, you can pass the identity returned by
36
49
  `requireIdentity` from `@vercel/passport` as the subject:
37
50
 
@@ -1,5 +1,6 @@
1
+ import { type ConnectRequestScope } from './internal/request-scope.js';
1
2
  import { type ConnectTokenParams } from './token.js';
2
- export interface ConnectAuthorizationOptions {
3
+ export interface ConnectAuthorizationOptions extends ConnectRequestScope {
3
4
  vercelToken?: string;
4
5
  callbackUrl?: string;
5
6
  webhook?: string;
@@ -1,3 +1,4 @@
1
+ import { withRequestScope, } from './internal/request-scope.js';
1
2
  import { getVercelOidcToken } from '@vercel/oidc';
2
3
  import { isDetachedInteractiveAuth, validateCallbackUrl, validateWebhookUrl, } from './internal/url-validation.js';
3
4
  import { normalizeTokenParams } from './internal/normalize-token-params.js';
@@ -33,7 +34,7 @@ export async function startAuthorization(connector, params, options) {
33
34
  }),
34
35
  ...(options?.prompt !== undefined && { prompt: options.prompt }),
35
36
  };
36
- const response = await fetch(endpoint, {
37
+ const response = await fetch(withRequestScope(endpoint, options), {
37
38
  method: 'POST',
38
39
  headers: {
39
40
  Accept: 'application/json',
package/dist/connector.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { withRequestScope } from './internal/request-scope.js';
1
2
  import { getVercelOidcToken } from '@vercel/oidc';
2
3
  import { createConnectErrorFromResponse, } from './token.js';
3
4
  import { resolveBaseUrl } from './internal/base-url.js';
@@ -14,7 +15,7 @@ export async function getConnectorMetadata(connector, options) {
14
15
  const vercelToken = options?.vercelToken ?? (await getVercelOidcToken());
15
16
  const baseUrl = resolveBaseUrl(options);
16
17
  const endpoint = `${baseUrl}/v1/connect/connectors/${encodeURIComponent(connector)}`;
17
- const response = await fetch(endpoint, {
18
+ const response = await fetch(withRequestScope(endpoint, options), {
18
19
  method: 'GET',
19
20
  headers: {
20
21
  Accept: 'application/json',
@@ -97,9 +97,9 @@ function makeEvict(options) {
97
97
  // Tokens fetched shortly after provisioning are cached under the
98
98
  // provisioned connector id, possibly by another `connect()` definition
99
99
  // for the same connector, so drop those entries too.
100
- deleteTokenCacheEntry(options.connector, params);
100
+ deleteTokenCacheEntry(options.connector, params, options.connectOptions);
101
101
  for (const id of getProvisionedConnectorIds(options.connector)) {
102
- deleteTokenCacheEntry(id, params);
102
+ deleteTokenCacheEntry(id, params, options.connectOptions);
103
103
  }
104
104
  };
105
105
  }
@@ -1,3 +1,4 @@
1
+ import { withRequestScope } from '../internal/request-scope.js';
1
2
  import { getVercelOidcToken } from '@vercel/oidc';
2
3
  import { ConnectError, createConnectErrorFromResponse } from '../token.js';
3
4
  import { resolveBaseUrl } from '../internal/base-url.js';
@@ -63,7 +64,7 @@ export function resolveProvisionScope(connector, connection, connectOptions) {
63
64
  if (serverUrl === undefined || !isProvisionableConnectorUid(connector)) {
64
65
  return undefined;
65
66
  }
66
- const endpoint = `${resolveBaseUrl(connectOptions)}${MANAGED_OAUTH_CONNECTOR_PATH}`;
67
+ const endpoint = withRequestScope(`${resolveBaseUrl(connectOptions)}${MANAGED_OAUTH_CONNECTOR_PATH}`, connectOptions);
67
68
  const key = JSON.stringify({
68
69
  connector,
69
70
  serverUrl,
@@ -101,7 +102,7 @@ export function getProvisionedConnector(scope) {
101
102
  * back to the UID rather than guessing.
102
103
  */
103
104
  export function findProvisionedConnector(connector, connectOptions) {
104
- const endpoint = `${resolveBaseUrl(connectOptions)}${MANAGED_OAUTH_CONNECTOR_PATH}`;
105
+ const endpoint = withRequestScope(`${resolveBaseUrl(connectOptions)}${MANAGED_OAUTH_CONNECTOR_PATH}`, connectOptions);
105
106
  const vercelToken = connectOptions?.vercelToken;
106
107
  const now = Date.now();
107
108
  const ids = new Set();
@@ -1,6 +1,7 @@
1
+ import { type ConnectRequestScope } from './internal/request-scope.js';
1
2
  import type { ConnectTokenParams } from './token.js';
2
3
  export type ConnectInstallationParams = Omit<ConnectTokenParams, 'subject'>;
3
- export interface ConnectInstallationOptions {
4
+ export interface ConnectInstallationOptions extends ConnectRequestScope {
4
5
  vercelToken?: string;
5
6
  returnUrl?: string;
6
7
  webhook?: string;
@@ -1,3 +1,4 @@
1
+ import { withRequestScope, } from './internal/request-scope.js';
1
2
  import { getVercelOidcToken } from '@vercel/oidc';
2
3
  import { isDetachedInteractiveAuth, validateCallbackUrl, validateWebhookUrl, } from './internal/url-validation.js';
3
4
  import { createConnectErrorFromResponse } from './token.js';
@@ -26,7 +27,7 @@ export async function experimental_startInstallation(connector, params = {}, opt
26
27
  const returnUrl = !detachedInteractiveAuth && options?.returnUrl !== undefined
27
28
  ? { returnUrl: options.returnUrl }
28
29
  : {};
29
- const response = await fetch(endpoint, {
30
+ const response = await fetch(withRequestScope(endpoint, options), {
30
31
  method: 'POST',
31
32
  headers: {
32
33
  Accept: 'application/json',
@@ -0,0 +1,6 @@
1
+ /** Optional team or organization scope for Vercel API requests. */
2
+ export interface ConnectRequestScope {
3
+ teamId?: string;
4
+ orgId?: string;
5
+ }
6
+ export declare function withRequestScope(endpoint: string, options?: ConnectRequestScope): string;
@@ -0,0 +1,10 @@
1
+ export function withRequestScope(endpoint, options) {
2
+ const url = new URL(endpoint);
3
+ if (options?.teamId !== undefined) {
4
+ url.searchParams.set('teamId', options.teamId);
5
+ }
6
+ if (options?.orgId !== undefined) {
7
+ url.searchParams.set('orgId', options.orgId);
8
+ }
9
+ return url.toString();
10
+ }
@@ -1,3 +1,4 @@
1
+ import type { ConnectRequestScope } from '../internal/request-scope.js';
1
2
  import { type ConnectTokenParams } from '../token.js';
2
3
  /**
3
4
  * OAuth token set as consumed by MCP client transports (RFC 6749 §5.1).
@@ -113,7 +114,7 @@ export interface ConnectOAuthClientProvider {
113
114
  */
114
115
  export type ConnectConsentMode = 'transport' | 'eager';
115
116
  /** Options accepted by {@link connectAuthProvider}. */
116
- export interface ConnectAuthProviderOptions {
117
+ export interface ConnectAuthProviderOptions extends ConnectRequestScope {
117
118
  /**
118
119
  * Override the Vercel OIDC token used to authenticate against the
119
120
  * Connect API. Defaults to the `@vercel/oidc` resolver used by the
@@ -193,6 +193,8 @@ export function connectAuthProvider(connector, params, options) {
193
193
  const vercelToken = await resolveVercelToken();
194
194
  const response = await startAuthorization(connector, params, {
195
195
  ...(vercelToken !== undefined && { vercelToken }),
196
+ ...(options?.teamId !== undefined && { teamId: options.teamId }),
197
+ ...(options?.orgId !== undefined && { orgId: options.orgId }),
196
198
  // Forward the post-consent return URL so the user lands back
197
199
  // in the app. Omitted => Connect uses the connector's
198
200
  // registered redirect.
@@ -213,7 +215,11 @@ export function connectAuthProvider(connector, params, options) {
213
215
  async tokens() {
214
216
  try {
215
217
  const vercelToken = await resolveVercelToken();
216
- const response = await getTokenResponse(connector, params, vercelToken !== undefined ? { vercelToken } : undefined);
218
+ const response = await getTokenResponse(connector, params, vercelToken !== undefined ||
219
+ options?.teamId !== undefined ||
220
+ options?.orgId !== undefined
221
+ ? { vercelToken, teamId: options?.teamId, orgId: options?.orgId }
222
+ : undefined);
217
223
  const expiresInSeconds = Math.max(1, Math.floor((response.expiresAt - Date.now()) / 1000));
218
224
  return {
219
225
  access_token: response.token,
@@ -62,7 +62,7 @@ export interface McpSubscriptionLookupInput {
62
62
  */
63
63
  expectedSubject?: ConnectTokenParams['subject'];
64
64
  }
65
- export type McpEventOptions = Pick<ConnectOptions, 'vercelToken' | 'region'> & EventRequestOptions;
65
+ export type McpEventOptions = Pick<ConnectOptions, 'vercelToken' | 'region' | 'teamId' | 'orgId'> & EventRequestOptions;
66
66
  export declare function discoverEvents(connector: string, params: McpEventSourceInput, options?: McpEventOptions): Promise<{
67
67
  status: "supported" | "unsupported" | "unavailable" | "needs_auth";
68
68
  }>;
@@ -1,3 +1,4 @@
1
+ import { withRequestScope } from '../internal/request-scope.js';
1
2
  import { getVercelOidcToken } from '@vercel/oidc';
2
3
  import { eventRequest, } from '../internal/event-request.js';
3
4
  import { resolveBaseUrl } from '../internal/base-url.js';
@@ -56,7 +57,7 @@ function send(url, init, options) {
56
57
  signal?.throwIfAborted();
57
58
  const token = vercelToken ?? (await getVercelOidcToken());
58
59
  signal?.throwIfAborted();
59
- const response = await fetch(url.toString(), {
60
+ const response = await fetch(withRequestScope(url.toString(), options), {
60
61
  ...init,
61
62
  redirect: 'error',
62
63
  headers: {
package/dist/token.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type ConnectRequestScope } from './internal/request-scope.js';
1
2
  import type { ConnectAuthorizationDetail } from './authorization-details.js';
2
3
  export type ConnectSubjectType = 'app' | 'user' | 'jwt-bearer' | 'token';
3
4
  export type ConnectTokenSubject = ConnectAppTokenSubject | ConnectUserTokenSubject | ConnectJwtBearerTokenSubject | ConnectTokenExchangeSubject;
@@ -99,7 +100,7 @@ export declare class UserAuthorizationRequiredError extends ConnectError {
99
100
  export declare class ConnectorInstallationRequiredError extends ConnectError {
100
101
  constructor(message: string, options?: ConnectErrorOptions);
101
102
  }
102
- export interface ConnectOptions {
103
+ export interface ConnectOptions extends ConnectRequestScope {
103
104
  vercelToken?: string;
104
105
  /**
105
106
  * Bypass the in-process token cache and re-fetch from Vercel Connect.
@@ -139,9 +140,9 @@ export declare function revokeToken(connector: string, params: {
139
140
  * round trip on every call the way {@link ConnectOptions.forceRefresh}
140
141
  * does.
141
142
  *
142
- * The cache key is derived from `connector` plus every field of `params`,
143
- * so pass the same `params` used for the original {@link getTokenResponse}
144
- * call. No-op when no matching entry exists.
143
+ * The cache key includes `connector`, every field of `params`, and the
144
+ * team/org scope. Pass the same `params` and scope options used for the
145
+ * original {@link getTokenResponse} call. No-op when no matching entry exists.
145
146
  */
146
- export declare function deleteTokenCacheEntry(connector: string, params: ConnectTokenParams): void;
147
+ export declare function deleteTokenCacheEntry(connector: string, params: ConnectTokenParams, options?: ConnectRequestScope): void;
147
148
  export declare function createConnectErrorFromResponse(response: Response, fallbackMessage: string): Promise<ConnectError>;
package/dist/token.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { withRequestScope, } from './internal/request-scope.js';
1
2
  import { getVercelOidcToken } from '@vercel/oidc';
2
3
  import { resolveBaseUrl } from './internal/base-url.js';
3
4
  import { normalizeTokenParams, normalizeTokenSubject, } from './internal/normalize-token-params.js';
@@ -40,7 +41,7 @@ export async function getToken(connector, params, options) {
40
41
  export async function getTokenResponse(connector, params, options) {
41
42
  const requestParams = normalizeTokenParams(params);
42
43
  const bufferMs = requestParams.validityBufferMs ?? DEFAULT_VALIDITY_BUFFER_MS;
43
- const cacheKey = tokenCacheKey(connector, requestParams);
44
+ const cacheKey = tokenCacheKey(connector, requestParams, options);
44
45
  if (options?.forceRefresh) {
45
46
  cache.delete(cacheKey);
46
47
  }
@@ -58,7 +59,7 @@ export async function getTokenResponse(connector, params, options) {
58
59
  const vercelToken = options?.vercelToken ?? (await getVercelOidcToken());
59
60
  const baseUrl = resolveBaseUrl(options);
60
61
  const endpoint = `${baseUrl}/v1/connect/token/${encodeURIComponent(connector)}`;
61
- const response = await fetch(endpoint, {
62
+ const response = await fetch(withRequestScope(endpoint, options), {
62
63
  method: 'POST',
63
64
  headers: {
64
65
  Accept: 'application/json',
@@ -81,7 +82,7 @@ export async function revokeToken(connector, params, options) {
81
82
  const vercelToken = options?.vercelToken ?? (await getVercelOidcToken());
82
83
  const baseUrl = resolveBaseUrl(options);
83
84
  const endpoint = `${baseUrl}/v1/connect/connectors/${encodeURIComponent(connector)}/tokens`;
84
- const response = await fetch(endpoint, {
85
+ const response = await fetch(withRequestScope(endpoint, options), {
85
86
  method: 'DELETE',
86
87
  headers: {
87
88
  Accept: 'application/json',
@@ -111,12 +112,12 @@ export async function revokeToken(connector, params, options) {
111
112
  * round trip on every call the way {@link ConnectOptions.forceRefresh}
112
113
  * does.
113
114
  *
114
- * The cache key is derived from `connector` plus every field of `params`,
115
- * so pass the same `params` used for the original {@link getTokenResponse}
116
- * call. No-op when no matching entry exists.
115
+ * The cache key includes `connector`, every field of `params`, and the
116
+ * team/org scope. Pass the same `params` and scope options used for the
117
+ * original {@link getTokenResponse} call. No-op when no matching entry exists.
117
118
  */
118
- export function deleteTokenCacheEntry(connector, params) {
119
- cache.delete(tokenCacheKey(connector, normalizeTokenParams(params)));
119
+ export function deleteTokenCacheEntry(connector, params, options) {
120
+ cache.delete(tokenCacheKey(connector, normalizeTokenParams(params), options));
120
121
  }
121
122
  const DEFAULT_VALIDITY_BUFFER_MS = 30_000;
122
123
  const MAX_CACHE_SIZE = 100;
@@ -126,8 +127,13 @@ const cache = new Map();
126
127
  * equal arguments so {@link getTokenResponse} and
127
128
  * {@link deleteTokenCacheEntry} address the same entry.
128
129
  */
129
- function tokenCacheKey(connector, params) {
130
- return JSON.stringify({ connector, ...params });
130
+ function tokenCacheKey(connector, params, options) {
131
+ return JSON.stringify({
132
+ connector,
133
+ ...params,
134
+ teamId: options?.teamId,
135
+ orgId: options?.orgId,
136
+ });
131
137
  }
132
138
  function evictLru() {
133
139
  let oldestKey;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/connect",
3
- "version": "2.9.2",
3
+ "version": "2.9.3-snapshot-579f9b2619d8",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "repository": {