@vercel/connect 2.3.6 → 2.4.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.
@@ -1,6 +1,6 @@
1
1
  import { getVercelOidcToken } from '@vercel/oidc';
2
2
  import { isDetachedInteractiveAuth, validateCallbackUrl, validateWebhookUrl, } from './internal/url-validation.js';
3
- import { withDefaultScopes } from './internal/default-scopes.js';
3
+ import { normalizeTokenParams } from './internal/normalize-token-params.js';
4
4
  import { resolveBaseUrl } from './internal/base-url.js';
5
5
  import { createConnectErrorFromResponse, } from './token.js';
6
6
  export async function startAuthorization(connector, params, options) {
@@ -22,7 +22,7 @@ export async function startAuthorization(connector, params, options) {
22
22
  ? { returnUrl: options.callbackUrl }
23
23
  : {};
24
24
  const body = {
25
- ...withDefaultScopes(params),
25
+ ...normalizeTokenParams(params),
26
26
  ...returnUrl,
27
27
  ...(options?.webhook !== undefined && { webhook: options.webhook }),
28
28
  ...(deviceCode !== undefined && {
@@ -0,0 +1,3 @@
1
+ import type { ConnectTokenParams, ConnectTokenSubject } from '../token.js';
2
+ export declare function normalizeTokenSubject(subject: ConnectTokenSubject): ConnectTokenSubject;
3
+ export declare function normalizeTokenParams(params: ConnectTokenParams): ConnectTokenParams;
@@ -0,0 +1,14 @@
1
+ export function normalizeTokenSubject(subject) {
2
+ if ((subject.type === undefined || subject.type === 'token') &&
3
+ typeof subject.token === 'string') {
4
+ return { type: 'token', token: subject.token };
5
+ }
6
+ return subject;
7
+ }
8
+ export function normalizeTokenParams(params) {
9
+ return {
10
+ ...params,
11
+ subject: normalizeTokenSubject(params.subject),
12
+ scopes: params.scopes === undefined ? ['*'] : params.scopes,
13
+ };
14
+ }
package/dist/token.d.ts CHANGED
@@ -28,7 +28,8 @@ export interface ConnectJwtBearerTokenSubject {
28
28
  additionalClaims?: Record<string, unknown>;
29
29
  }
30
30
  export interface ConnectTokenExchangeSubject {
31
- type: 'token';
31
+ /** Inferred as `'token'` when omitted. */
32
+ type?: 'token';
32
33
  token: string;
33
34
  }
34
35
  export interface ConnectTokenParams {
package/dist/token.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { getVercelOidcToken } from '@vercel/oidc';
2
2
  import { resolveBaseUrl } from './internal/base-url.js';
3
- import { withDefaultScopes } from './internal/default-scopes.js';
3
+ import { normalizeTokenParams, normalizeTokenSubject, } from './internal/normalize-token-params.js';
4
4
  export class ConnectError extends Error {
5
5
  code;
6
6
  status;
@@ -38,7 +38,7 @@ export async function getToken(connector, params, options) {
38
38
  return token;
39
39
  }
40
40
  export async function getTokenResponse(connector, params, options) {
41
- const requestParams = withDefaultScopes(params);
41
+ const requestParams = normalizeTokenParams(params);
42
42
  const bufferMs = requestParams.validityBufferMs ?? DEFAULT_VALIDITY_BUFFER_MS;
43
43
  const cacheKey = tokenCacheKey(connector, requestParams);
44
44
  if (options?.forceRefresh) {
@@ -88,7 +88,10 @@ export async function revokeToken(connector, params, options) {
88
88
  'Content-Type': 'application/json',
89
89
  Authorization: `Bearer ${vercelToken}`,
90
90
  },
91
- body: JSON.stringify(params),
91
+ body: JSON.stringify({
92
+ ...params,
93
+ subject: normalizeTokenSubject(params.subject),
94
+ }),
92
95
  });
93
96
  if (!response.ok) {
94
97
  throw await createConnectErrorFromResponse(response, 'Failed to revoke token');
@@ -113,7 +116,7 @@ export async function revokeToken(connector, params, options) {
113
116
  * call. No-op when no matching entry exists.
114
117
  */
115
118
  export function deleteTokenCacheEntry(connector, params) {
116
- cache.delete(tokenCacheKey(connector, withDefaultScopes(params)));
119
+ cache.delete(tokenCacheKey(connector, normalizeTokenParams(params)));
117
120
  }
118
121
  const DEFAULT_VALIDITY_BUFFER_MS = 30_000;
119
122
  const MAX_CACHE_SIZE = 100;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/connect",
3
- "version": "2.3.6",
3
+ "version": "2.4.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "repository": {
@@ -50,11 +50,11 @@
50
50
  "dist"
51
51
  ],
52
52
  "dependencies": {
53
- "@vercel/oidc": "3.8.10"
53
+ "@vercel/oidc": "4.0.0"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@ai-sdk/mcp": "^1 || ^2",
57
- "@auth/core": ">=0.37.0",
57
+ "@auth/core": ">=0.41.3",
58
58
  "@chat-adapter/slack": "^4.0.0",
59
59
  "@modelcontextprotocol/sdk": "^1.29.0",
60
60
  "ai": "^6 || ^7.0.0-beta.0",
@@ -86,7 +86,7 @@
86
86
  },
87
87
  "devDependencies": {
88
88
  "@ai-sdk/mcp": "2.0.0-beta.37",
89
- "@auth/core": "0.37.4",
89
+ "@auth/core": "0.41.3",
90
90
  "@chat-adapter/slack": "4.31.0",
91
91
  "@modelcontextprotocol/sdk": "1.29.0",
92
92
  "@tanstack/ai-mcp": "0.3.10",
@@ -1,2 +0,0 @@
1
- import type { ConnectTokenParams } from '../token.js';
2
- export declare function withDefaultScopes(params: ConnectTokenParams): ConnectTokenParams;
@@ -1,3 +0,0 @@
1
- export function withDefaultScopes(params) {
2
- return params.scopes === undefined ? { ...params, scopes: ['*'] } : params;
3
- }