@vercel/connect 2.3.6 → 2.4.0
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/dist/authorization.js +2 -2
- package/dist/internal/normalize-token-params.d.ts +3 -0
- package/dist/internal/normalize-token-params.js +14 -0
- package/dist/token.d.ts +2 -1
- package/dist/token.js +7 -4
- package/package.json +2 -2
- package/dist/internal/default-scopes.d.ts +0 -2
- package/dist/internal/default-scopes.js +0 -3
package/dist/authorization.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getVercelOidcToken } from '@vercel/oidc';
|
|
2
2
|
import { isDetachedInteractiveAuth, validateCallbackUrl, validateWebhookUrl, } from './internal/url-validation.js';
|
|
3
|
-
import {
|
|
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
|
-
...
|
|
25
|
+
...normalizeTokenParams(params),
|
|
26
26
|
...returnUrl,
|
|
27
27
|
...(options?.webhook !== undefined && { webhook: options.webhook }),
|
|
28
28
|
...(deviceCode !== undefined && {
|
|
@@ -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
|
-
|
|
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 {
|
|
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 =
|
|
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(
|
|
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,
|
|
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
|
+
"version": "2.4.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"dist"
|
|
51
51
|
],
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@vercel/oidc": "
|
|
53
|
+
"@vercel/oidc": "4.0.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@ai-sdk/mcp": "^1 || ^2",
|