integrate-sdk 0.8.23 → 0.8.27
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/adapters/auto-routes.js +52 -49
- package/dist/adapters/base-handler.d.ts +5 -0
- package/dist/adapters/base-handler.d.ts.map +1 -1
- package/dist/adapters/index.js +52 -49
- package/dist/adapters/nextjs.d.ts.map +1 -1
- package/dist/adapters/nextjs.js +52 -49
- package/dist/adapters/node.js +52 -49
- package/dist/adapters/svelte-kit.js +52 -49
- package/dist/adapters/tanstack-start.js +52 -49
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -51
- package/dist/oauth.js +52 -49
- package/dist/server.js +52 -49
- package/dist/src/adapters/base-handler.d.ts +5 -0
- package/dist/src/adapters/base-handler.d.ts.map +1 -1
- package/dist/src/adapters/nextjs.d.ts.map +1 -1
- package/dist/src/client.d.ts +1 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config/types.d.ts +0 -19
- package/dist/src/config/types.d.ts.map +1 -1
- package/dist/src/oauth/manager.d.ts +13 -5
- package/dist/src/oauth/manager.d.ts.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/index.ts +2 -6
- package/package.json +1 -1
|
@@ -651,7 +651,7 @@ class OAuthManager {
|
|
|
651
651
|
this.getTokenCallback = tokenCallbacks?.getProviderToken;
|
|
652
652
|
this.setTokenCallback = tokenCallbacks?.setProviderToken;
|
|
653
653
|
this.removeTokenCallback = tokenCallbacks?.removeProviderToken;
|
|
654
|
-
this.skipLocalStorage = tokenCallbacks?.
|
|
654
|
+
this.skipLocalStorage = !!(tokenCallbacks?.getProviderToken || tokenCallbacks?.setProviderToken);
|
|
655
655
|
this.cleanupExpiredPendingAuths();
|
|
656
656
|
}
|
|
657
657
|
async initiateFlow(provider, config, returnUrl) {
|
|
@@ -669,13 +669,10 @@ class OAuthManager {
|
|
|
669
669
|
};
|
|
670
670
|
this.pendingAuths.set(state, pendingAuth);
|
|
671
671
|
this.savePendingAuthToStorage(state, pendingAuth);
|
|
672
|
-
console.log("[OAuth] Requesting authorization URL, flow mode:", this.flowConfig.mode);
|
|
673
672
|
const authUrl = await this.getAuthorizationUrl(provider, state, codeChallenge, config.redirectUri, codeVerifier);
|
|
674
|
-
console.log("[OAuth] Received authorization URL, length:", authUrl?.length);
|
|
675
673
|
if (!authUrl || authUrl.trim() === "") {
|
|
676
674
|
throw new Error("Received empty authorization URL from server");
|
|
677
675
|
}
|
|
678
|
-
console.log("[OAuth] Opening authorization URL, mode:", this.flowConfig.mode);
|
|
679
676
|
if (this.flowConfig.mode === "popup") {
|
|
680
677
|
this.windowManager.openPopup(authUrl, this.flowConfig.popupOptions);
|
|
681
678
|
try {
|
|
@@ -686,7 +683,6 @@ class OAuthManager {
|
|
|
686
683
|
throw error;
|
|
687
684
|
}
|
|
688
685
|
} else {
|
|
689
|
-
console.log("[OAuth] Redirecting to authorization URL:", authUrl.substring(0, 100) + (authUrl.length > 100 ? "..." : ""));
|
|
690
686
|
this.windowManager.openRedirect(authUrl);
|
|
691
687
|
}
|
|
692
688
|
}
|
|
@@ -881,7 +877,6 @@ class OAuthManager {
|
|
|
881
877
|
return;
|
|
882
878
|
}
|
|
883
879
|
if (this.skipLocalStorage) {
|
|
884
|
-
console.log(`[OAuth] Token for ${provider} stored in memory only (skipLocalStorage: true). Configure setProviderToken/getProviderToken callbacks for persistence.`);
|
|
885
880
|
return;
|
|
886
881
|
}
|
|
887
882
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
@@ -930,6 +925,9 @@ class OAuthManager {
|
|
|
930
925
|
if (this.getTokenCallback) {
|
|
931
926
|
return;
|
|
932
927
|
}
|
|
928
|
+
if (this.skipLocalStorage) {
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
933
931
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
934
932
|
try {
|
|
935
933
|
const key = `integrate_token_${provider}`;
|
|
@@ -955,9 +953,6 @@ class OAuthManager {
|
|
|
955
953
|
}
|
|
956
954
|
}
|
|
957
955
|
savePendingAuthToStorage(state, pendingAuth) {
|
|
958
|
-
if (this.skipLocalStorage) {
|
|
959
|
-
return;
|
|
960
|
-
}
|
|
961
956
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
962
957
|
try {
|
|
963
958
|
const key = `integrate_oauth_pending_${state}`;
|
|
@@ -968,9 +963,6 @@ class OAuthManager {
|
|
|
968
963
|
}
|
|
969
964
|
}
|
|
970
965
|
loadPendingAuthFromStorage(state) {
|
|
971
|
-
if (this.skipLocalStorage) {
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
966
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
975
967
|
try {
|
|
976
968
|
const key = `integrate_oauth_pending_${state}`;
|
|
@@ -985,9 +977,6 @@ class OAuthManager {
|
|
|
985
977
|
return;
|
|
986
978
|
}
|
|
987
979
|
removePendingAuthFromStorage(state) {
|
|
988
|
-
if (this.skipLocalStorage) {
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
980
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
992
981
|
try {
|
|
993
982
|
const key = `integrate_oauth_pending_${state}`;
|
|
@@ -998,9 +987,6 @@ class OAuthManager {
|
|
|
998
987
|
}
|
|
999
988
|
}
|
|
1000
989
|
cleanupExpiredPendingAuths() {
|
|
1001
|
-
if (this.skipLocalStorage) {
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
990
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
1005
991
|
try {
|
|
1006
992
|
const prefix = "integrate_oauth_pending_";
|
|
@@ -1046,21 +1032,20 @@ class OAuthManager {
|
|
|
1046
1032
|
frontendOrigin: this.apiBaseUrl && this.flowConfig.mode === "redirect" && typeof window !== "undefined" ? window.location.origin : undefined
|
|
1047
1033
|
})
|
|
1048
1034
|
});
|
|
1035
|
+
if (response.headers.get("X-Integrate-Use-Database") === "true") {
|
|
1036
|
+
this.skipLocalStorage = true;
|
|
1037
|
+
}
|
|
1049
1038
|
if (!response.ok) {
|
|
1050
1039
|
const error = await response.text();
|
|
1051
1040
|
throw new Error(`Failed to get authorization URL: ${error}`);
|
|
1052
1041
|
}
|
|
1053
1042
|
const data = await response.json();
|
|
1054
1043
|
if (!data.authorizationUrl) {
|
|
1055
|
-
console.error("[OAuth] Authorization URL is missing from response:", data);
|
|
1056
1044
|
throw new Error("Authorization URL is missing from server response");
|
|
1057
1045
|
}
|
|
1058
1046
|
if (typeof data.authorizationUrl !== "string" || data.authorizationUrl.trim() === "") {
|
|
1059
|
-
console.error("[OAuth] Invalid authorization URL received:", data.authorizationUrl);
|
|
1060
1047
|
throw new Error("Invalid authorization URL received from server");
|
|
1061
1048
|
}
|
|
1062
|
-
const urlPreview = data.authorizationUrl.length > 100 ? data.authorizationUrl.substring(0, 100) + "..." : data.authorizationUrl;
|
|
1063
|
-
console.log("[OAuth] Received authorization URL from API route:", urlPreview);
|
|
1064
1049
|
return data.authorizationUrl;
|
|
1065
1050
|
}
|
|
1066
1051
|
async exchangeCodeForToken(provider, code, codeVerifier, state) {
|
|
@@ -1077,6 +1062,9 @@ class OAuthManager {
|
|
|
1077
1062
|
state
|
|
1078
1063
|
})
|
|
1079
1064
|
});
|
|
1065
|
+
if (response.headers.get("X-Integrate-Use-Database") === "true") {
|
|
1066
|
+
this.skipLocalStorage = true;
|
|
1067
|
+
}
|
|
1080
1068
|
if (!response.ok) {
|
|
1081
1069
|
const error = await response.text();
|
|
1082
1070
|
throw new Error(`Failed to exchange code for token: ${error}`);
|
|
@@ -1084,6 +1072,9 @@ class OAuthManager {
|
|
|
1084
1072
|
const data = await response.json();
|
|
1085
1073
|
return data;
|
|
1086
1074
|
}
|
|
1075
|
+
setSkipLocalStorage(value) {
|
|
1076
|
+
this.skipLocalStorage = value;
|
|
1077
|
+
}
|
|
1087
1078
|
close() {
|
|
1088
1079
|
this.windowManager.close();
|
|
1089
1080
|
}
|
|
@@ -1140,6 +1131,7 @@ class MCPClientBase {
|
|
|
1140
1131
|
eventEmitter = new SimpleEventEmitter;
|
|
1141
1132
|
apiRouteBase;
|
|
1142
1133
|
apiBaseUrl;
|
|
1134
|
+
databaseDetected = false;
|
|
1143
1135
|
oauthCallbackPromise;
|
|
1144
1136
|
server;
|
|
1145
1137
|
constructor(config) {
|
|
@@ -1173,8 +1165,7 @@ class MCPClientBase {
|
|
|
1173
1165
|
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow, this.apiBaseUrl, {
|
|
1174
1166
|
getProviderToken: config.getProviderToken,
|
|
1175
1167
|
setProviderToken: config.setProviderToken,
|
|
1176
|
-
removeProviderToken: config.removeProviderToken
|
|
1177
|
-
skipLocalStorage: config.skipLocalStorage
|
|
1168
|
+
removeProviderToken: config.removeProviderToken
|
|
1178
1169
|
});
|
|
1179
1170
|
for (const integration of this.integrations) {
|
|
1180
1171
|
for (const toolName of integration.tools) {
|
|
@@ -1384,6 +1375,10 @@ class MCPClientBase {
|
|
|
1384
1375
|
arguments: args
|
|
1385
1376
|
})
|
|
1386
1377
|
});
|
|
1378
|
+
if (!this.databaseDetected && response.headers.get("X-Integrate-Use-Database") === "true") {
|
|
1379
|
+
this.oauthManager.setSkipLocalStorage(true);
|
|
1380
|
+
this.databaseDetected = true;
|
|
1381
|
+
}
|
|
1387
1382
|
if (!response.ok) {
|
|
1388
1383
|
let errorMessage = `Request failed: ${response.statusText}`;
|
|
1389
1384
|
const error = new Error(errorMessage);
|
|
@@ -6556,10 +6551,17 @@ function createMCPServer(config) {
|
|
|
6556
6551
|
const oauthHandler = new OAuthHandler({
|
|
6557
6552
|
providers,
|
|
6558
6553
|
serverUrl: config.serverUrl,
|
|
6559
|
-
apiKey: config.apiKey
|
|
6554
|
+
apiKey: config.apiKey,
|
|
6555
|
+
setProviderToken: config.setProviderToken,
|
|
6556
|
+
removeProviderToken: config.removeProviderToken,
|
|
6557
|
+
getSessionContext: config.getSessionContext
|
|
6560
6558
|
});
|
|
6561
6559
|
const result = await oauthHandler.handleToolCall(body, authHeader);
|
|
6562
|
-
|
|
6560
|
+
const response2 = Response.json(result);
|
|
6561
|
+
if (oauthHandler.hasDatabaseCallbacks()) {
|
|
6562
|
+
response2.headers.set("X-Integrate-Use-Database", "true");
|
|
6563
|
+
}
|
|
6564
|
+
return response2;
|
|
6563
6565
|
} catch (error) {
|
|
6564
6566
|
console.error("[MCP Tool Call] Error:", error);
|
|
6565
6567
|
return Response.json({ error: error.message || "Failed to execute tool call" }, { status: error.statusCode || 500 });
|
|
@@ -6685,7 +6687,6 @@ function createMCPServer(config) {
|
|
|
6685
6687
|
}
|
|
6686
6688
|
}
|
|
6687
6689
|
if (!targetOrigin) {
|
|
6688
|
-
console.warn("[OAuth] Could not determine frontend origin for redirect. Using request origin as fallback.");
|
|
6689
6690
|
targetOrigin = new URL(webRequest.url).origin;
|
|
6690
6691
|
}
|
|
6691
6692
|
const targetUrl = new URL(returnUrl, targetOrigin);
|
|
@@ -7215,6 +7216,9 @@ class OAuthHandler {
|
|
|
7215
7216
|
}
|
|
7216
7217
|
return headers;
|
|
7217
7218
|
}
|
|
7219
|
+
hasDatabaseCallbacks() {
|
|
7220
|
+
return !!this.config.setProviderToken;
|
|
7221
|
+
}
|
|
7218
7222
|
async handleAuthorize(request) {
|
|
7219
7223
|
let webRequest;
|
|
7220
7224
|
let authorizeRequest;
|
|
@@ -7226,7 +7230,6 @@ class OAuthHandler {
|
|
|
7226
7230
|
} else {
|
|
7227
7231
|
authorizeRequest = request;
|
|
7228
7232
|
}
|
|
7229
|
-
console.log("[handleAuthorize] Received request for provider:", authorizeRequest.provider, "has codeVerifier:", !!authorizeRequest.codeVerifier, "has frontendOrigin:", !!authorizeRequest.frontendOrigin);
|
|
7230
7233
|
const providerConfig = this.config.providers[authorizeRequest.provider];
|
|
7231
7234
|
if (!providerConfig) {
|
|
7232
7235
|
throw new Error(`Provider ${authorizeRequest.provider} not configured. Add OAuth credentials to your API route configuration.`);
|
|
@@ -7267,22 +7270,14 @@ class OAuthHandler {
|
|
|
7267
7270
|
const data = await response.json();
|
|
7268
7271
|
const result = data;
|
|
7269
7272
|
if (!result.authorizationUrl) {
|
|
7270
|
-
console.error("[OAuth] MCP server did not return authorizationUrl:", data);
|
|
7271
7273
|
throw new Error("MCP server failed to return authorization URL");
|
|
7272
7274
|
}
|
|
7273
|
-
const urlPreview = result.authorizationUrl.length > 100 ? result.authorizationUrl.substring(0, 100) + "..." : result.authorizationUrl;
|
|
7274
|
-
console.log("[OAuth] Generated authorization URL:", urlPreview);
|
|
7275
7275
|
if (authorizeRequest.codeVerifier) {
|
|
7276
7276
|
try {
|
|
7277
7277
|
const { storeCodeVerifier: storeCodeVerifier2 } = await Promise.resolve().then(() => (init_server(), exports_server));
|
|
7278
7278
|
storeCodeVerifier2(authorizeRequest.state, authorizeRequest.codeVerifier, authorizeRequest.provider, authorizeRequest.frontendOrigin);
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
console.warn("[OAuth] Failed to store codeVerifier:", error);
|
|
7282
|
-
}
|
|
7283
|
-
} else {
|
|
7284
|
-
console.log("[OAuth] No codeVerifier provided in authorize request");
|
|
7285
|
-
}
|
|
7279
|
+
} catch (error) {}
|
|
7280
|
+
} else {}
|
|
7286
7281
|
if (webRequest) {
|
|
7287
7282
|
try {
|
|
7288
7283
|
const { detectSessionContext: detectSessionContext2 } = await Promise.resolve().then(() => exports_session_detector);
|
|
@@ -7299,9 +7294,7 @@ class OAuthHandler {
|
|
|
7299
7294
|
const cookieValue = await createContextCookie2(context, authorizeRequest.provider, secret);
|
|
7300
7295
|
result.setCookie = getSetCookieHeader2(cookieValue);
|
|
7301
7296
|
}
|
|
7302
|
-
} catch (error) {
|
|
7303
|
-
console.warn("[OAuth] Failed to capture user context:", error);
|
|
7304
|
-
}
|
|
7297
|
+
} catch (error) {}
|
|
7305
7298
|
}
|
|
7306
7299
|
return result;
|
|
7307
7300
|
}
|
|
@@ -7335,9 +7328,7 @@ class OAuthHandler {
|
|
|
7335
7328
|
context = contextData.context;
|
|
7336
7329
|
}
|
|
7337
7330
|
}
|
|
7338
|
-
} catch (error) {
|
|
7339
|
-
console.warn("[OAuth] Failed to restore user context:", error);
|
|
7340
|
-
}
|
|
7331
|
+
} catch (error) {}
|
|
7341
7332
|
}
|
|
7342
7333
|
const url = new URL("/oauth/callback", this.serverUrl);
|
|
7343
7334
|
const response = await fetch(url.toString(), {
|
|
@@ -7372,9 +7363,7 @@ class OAuthHandler {
|
|
|
7372
7363
|
scopes: result.scopes
|
|
7373
7364
|
};
|
|
7374
7365
|
await this.config.setProviderToken(callbackRequest.provider, tokenData, context);
|
|
7375
|
-
} catch (error) {
|
|
7376
|
-
console.error("[OAuth] Failed to save provider token:", error);
|
|
7377
|
-
}
|
|
7366
|
+
} catch (error) {}
|
|
7378
7367
|
}
|
|
7379
7368
|
if (webRequest) {
|
|
7380
7369
|
const { getClearCookieHeader: getClearCookieHeader2 } = await Promise.resolve().then(() => exports_context_cookie);
|
|
@@ -7495,6 +7484,9 @@ function createNextOAuthHandler(config) {
|
|
|
7495
7484
|
if (result.setCookie) {
|
|
7496
7485
|
response.headers.set("Set-Cookie", result.setCookie);
|
|
7497
7486
|
}
|
|
7487
|
+
if (handler.hasDatabaseCallbacks()) {
|
|
7488
|
+
response.headers.set("X-Integrate-Use-Database", "true");
|
|
7489
|
+
}
|
|
7498
7490
|
return response;
|
|
7499
7491
|
} catch (error) {
|
|
7500
7492
|
console.error("[OAuth Authorize] Error:", error);
|
|
@@ -7508,6 +7500,9 @@ function createNextOAuthHandler(config) {
|
|
|
7508
7500
|
if (result.clearCookie) {
|
|
7509
7501
|
response.headers.set("Set-Cookie", result.clearCookie);
|
|
7510
7502
|
}
|
|
7503
|
+
if (handler.hasDatabaseCallbacks()) {
|
|
7504
|
+
response.headers.set("X-Integrate-Use-Database", "true");
|
|
7505
|
+
}
|
|
7511
7506
|
return response;
|
|
7512
7507
|
} catch (error) {
|
|
7513
7508
|
console.error("[OAuth Callback] Error:", error);
|
|
@@ -7526,7 +7521,11 @@ function createNextOAuthHandler(config) {
|
|
|
7526
7521
|
}
|
|
7527
7522
|
const accessToken = authHeader.substring(7);
|
|
7528
7523
|
const result = await handler.handleStatus(provider, accessToken);
|
|
7529
|
-
|
|
7524
|
+
const response = Response.json(result);
|
|
7525
|
+
if (handler.hasDatabaseCallbacks()) {
|
|
7526
|
+
response.headers.set("X-Integrate-Use-Database", "true");
|
|
7527
|
+
}
|
|
7528
|
+
return response;
|
|
7530
7529
|
} catch (error) {
|
|
7531
7530
|
console.error("[OAuth Status] Error:", error);
|
|
7532
7531
|
return Response.json({ error: error.message || "Failed to check authorization status" }, { status: 500 });
|
|
@@ -7545,7 +7544,11 @@ function createNextOAuthHandler(config) {
|
|
|
7545
7544
|
return Response.json({ error: "Missing provider in request body" }, { status: 400 });
|
|
7546
7545
|
}
|
|
7547
7546
|
const result = await handler.handleDisconnect({ provider }, accessToken, req);
|
|
7548
|
-
|
|
7547
|
+
const response = Response.json(result);
|
|
7548
|
+
if (handler.hasDatabaseCallbacks()) {
|
|
7549
|
+
response.headers.set("X-Integrate-Use-Database", "true");
|
|
7550
|
+
}
|
|
7551
|
+
return response;
|
|
7549
7552
|
} catch (error) {
|
|
7550
7553
|
console.error("[OAuth Disconnect] Error:", error);
|
|
7551
7554
|
return Response.json({ error: error.message || "Failed to disconnect provider" }, { status: 500 });
|
|
@@ -192,6 +192,11 @@ export declare class OAuthHandler {
|
|
|
192
192
|
* Get headers with API key if configured
|
|
193
193
|
*/
|
|
194
194
|
private getHeaders;
|
|
195
|
+
/**
|
|
196
|
+
* Check if database callbacks are configured
|
|
197
|
+
* Used to determine if we should set X-Integrate-Use-Database header
|
|
198
|
+
*/
|
|
199
|
+
hasDatabaseCallbacks(): boolean;
|
|
195
200
|
/**
|
|
196
201
|
* Handle authorization URL request
|
|
197
202
|
* Gets authorization URL from MCP server with full OAuth credentials
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-handler.d.ts","sour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 class OAuthManager {
|
|
|
651
651
|
this.getTokenCallback = tokenCallbacks?.getProviderToken;
|
|
652
652
|
this.setTokenCallback = tokenCallbacks?.setProviderToken;
|
|
653
653
|
this.removeTokenCallback = tokenCallbacks?.removeProviderToken;
|
|
654
|
-
this.skipLocalStorage = tokenCallbacks?.
|
|
654
|
+
this.skipLocalStorage = !!(tokenCallbacks?.getProviderToken || tokenCallbacks?.setProviderToken);
|
|
655
655
|
this.cleanupExpiredPendingAuths();
|
|
656
656
|
}
|
|
657
657
|
async initiateFlow(provider, config, returnUrl) {
|
|
@@ -669,13 +669,10 @@ class OAuthManager {
|
|
|
669
669
|
};
|
|
670
670
|
this.pendingAuths.set(state, pendingAuth);
|
|
671
671
|
this.savePendingAuthToStorage(state, pendingAuth);
|
|
672
|
-
console.log("[OAuth] Requesting authorization URL, flow mode:", this.flowConfig.mode);
|
|
673
672
|
const authUrl = await this.getAuthorizationUrl(provider, state, codeChallenge, config.redirectUri, codeVerifier);
|
|
674
|
-
console.log("[OAuth] Received authorization URL, length:", authUrl?.length);
|
|
675
673
|
if (!authUrl || authUrl.trim() === "") {
|
|
676
674
|
throw new Error("Received empty authorization URL from server");
|
|
677
675
|
}
|
|
678
|
-
console.log("[OAuth] Opening authorization URL, mode:", this.flowConfig.mode);
|
|
679
676
|
if (this.flowConfig.mode === "popup") {
|
|
680
677
|
this.windowManager.openPopup(authUrl, this.flowConfig.popupOptions);
|
|
681
678
|
try {
|
|
@@ -686,7 +683,6 @@ class OAuthManager {
|
|
|
686
683
|
throw error;
|
|
687
684
|
}
|
|
688
685
|
} else {
|
|
689
|
-
console.log("[OAuth] Redirecting to authorization URL:", authUrl.substring(0, 100) + (authUrl.length > 100 ? "..." : ""));
|
|
690
686
|
this.windowManager.openRedirect(authUrl);
|
|
691
687
|
}
|
|
692
688
|
}
|
|
@@ -881,7 +877,6 @@ class OAuthManager {
|
|
|
881
877
|
return;
|
|
882
878
|
}
|
|
883
879
|
if (this.skipLocalStorage) {
|
|
884
|
-
console.log(`[OAuth] Token for ${provider} stored in memory only (skipLocalStorage: true). Configure setProviderToken/getProviderToken callbacks for persistence.`);
|
|
885
880
|
return;
|
|
886
881
|
}
|
|
887
882
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
@@ -930,6 +925,9 @@ class OAuthManager {
|
|
|
930
925
|
if (this.getTokenCallback) {
|
|
931
926
|
return;
|
|
932
927
|
}
|
|
928
|
+
if (this.skipLocalStorage) {
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
933
931
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
934
932
|
try {
|
|
935
933
|
const key = `integrate_token_${provider}`;
|
|
@@ -955,9 +953,6 @@ class OAuthManager {
|
|
|
955
953
|
}
|
|
956
954
|
}
|
|
957
955
|
savePendingAuthToStorage(state, pendingAuth) {
|
|
958
|
-
if (this.skipLocalStorage) {
|
|
959
|
-
return;
|
|
960
|
-
}
|
|
961
956
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
962
957
|
try {
|
|
963
958
|
const key = `integrate_oauth_pending_${state}`;
|
|
@@ -968,9 +963,6 @@ class OAuthManager {
|
|
|
968
963
|
}
|
|
969
964
|
}
|
|
970
965
|
loadPendingAuthFromStorage(state) {
|
|
971
|
-
if (this.skipLocalStorage) {
|
|
972
|
-
return;
|
|
973
|
-
}
|
|
974
966
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
975
967
|
try {
|
|
976
968
|
const key = `integrate_oauth_pending_${state}`;
|
|
@@ -985,9 +977,6 @@ class OAuthManager {
|
|
|
985
977
|
return;
|
|
986
978
|
}
|
|
987
979
|
removePendingAuthFromStorage(state) {
|
|
988
|
-
if (this.skipLocalStorage) {
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
980
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
992
981
|
try {
|
|
993
982
|
const key = `integrate_oauth_pending_${state}`;
|
|
@@ -998,9 +987,6 @@ class OAuthManager {
|
|
|
998
987
|
}
|
|
999
988
|
}
|
|
1000
989
|
cleanupExpiredPendingAuths() {
|
|
1001
|
-
if (this.skipLocalStorage) {
|
|
1002
|
-
return;
|
|
1003
|
-
}
|
|
1004
990
|
if (typeof window !== "undefined" && window.localStorage) {
|
|
1005
991
|
try {
|
|
1006
992
|
const prefix = "integrate_oauth_pending_";
|
|
@@ -1046,21 +1032,20 @@ class OAuthManager {
|
|
|
1046
1032
|
frontendOrigin: this.apiBaseUrl && this.flowConfig.mode === "redirect" && typeof window !== "undefined" ? window.location.origin : undefined
|
|
1047
1033
|
})
|
|
1048
1034
|
});
|
|
1035
|
+
if (response.headers.get("X-Integrate-Use-Database") === "true") {
|
|
1036
|
+
this.skipLocalStorage = true;
|
|
1037
|
+
}
|
|
1049
1038
|
if (!response.ok) {
|
|
1050
1039
|
const error = await response.text();
|
|
1051
1040
|
throw new Error(`Failed to get authorization URL: ${error}`);
|
|
1052
1041
|
}
|
|
1053
1042
|
const data = await response.json();
|
|
1054
1043
|
if (!data.authorizationUrl) {
|
|
1055
|
-
console.error("[OAuth] Authorization URL is missing from response:", data);
|
|
1056
1044
|
throw new Error("Authorization URL is missing from server response");
|
|
1057
1045
|
}
|
|
1058
1046
|
if (typeof data.authorizationUrl !== "string" || data.authorizationUrl.trim() === "") {
|
|
1059
|
-
console.error("[OAuth] Invalid authorization URL received:", data.authorizationUrl);
|
|
1060
1047
|
throw new Error("Invalid authorization URL received from server");
|
|
1061
1048
|
}
|
|
1062
|
-
const urlPreview = data.authorizationUrl.length > 100 ? data.authorizationUrl.substring(0, 100) + "..." : data.authorizationUrl;
|
|
1063
|
-
console.log("[OAuth] Received authorization URL from API route:", urlPreview);
|
|
1064
1049
|
return data.authorizationUrl;
|
|
1065
1050
|
}
|
|
1066
1051
|
async exchangeCodeForToken(provider, code, codeVerifier, state) {
|
|
@@ -1077,6 +1062,9 @@ class OAuthManager {
|
|
|
1077
1062
|
state
|
|
1078
1063
|
})
|
|
1079
1064
|
});
|
|
1065
|
+
if (response.headers.get("X-Integrate-Use-Database") === "true") {
|
|
1066
|
+
this.skipLocalStorage = true;
|
|
1067
|
+
}
|
|
1080
1068
|
if (!response.ok) {
|
|
1081
1069
|
const error = await response.text();
|
|
1082
1070
|
throw new Error(`Failed to exchange code for token: ${error}`);
|
|
@@ -1084,6 +1072,9 @@ class OAuthManager {
|
|
|
1084
1072
|
const data = await response.json();
|
|
1085
1073
|
return data;
|
|
1086
1074
|
}
|
|
1075
|
+
setSkipLocalStorage(value) {
|
|
1076
|
+
this.skipLocalStorage = value;
|
|
1077
|
+
}
|
|
1087
1078
|
close() {
|
|
1088
1079
|
this.windowManager.close();
|
|
1089
1080
|
}
|
|
@@ -1140,6 +1131,7 @@ class MCPClientBase {
|
|
|
1140
1131
|
eventEmitter = new SimpleEventEmitter;
|
|
1141
1132
|
apiRouteBase;
|
|
1142
1133
|
apiBaseUrl;
|
|
1134
|
+
databaseDetected = false;
|
|
1143
1135
|
oauthCallbackPromise;
|
|
1144
1136
|
server;
|
|
1145
1137
|
constructor(config) {
|
|
@@ -1173,8 +1165,7 @@ class MCPClientBase {
|
|
|
1173
1165
|
this.oauthManager = new OAuthManager(oauthApiBase, config.oauthFlow, this.apiBaseUrl, {
|
|
1174
1166
|
getProviderToken: config.getProviderToken,
|
|
1175
1167
|
setProviderToken: config.setProviderToken,
|
|
1176
|
-
removeProviderToken: config.removeProviderToken
|
|
1177
|
-
skipLocalStorage: config.skipLocalStorage
|
|
1168
|
+
removeProviderToken: config.removeProviderToken
|
|
1178
1169
|
});
|
|
1179
1170
|
for (const integration of this.integrations) {
|
|
1180
1171
|
for (const toolName of integration.tools) {
|
|
@@ -1384,6 +1375,10 @@ class MCPClientBase {
|
|
|
1384
1375
|
arguments: args
|
|
1385
1376
|
})
|
|
1386
1377
|
});
|
|
1378
|
+
if (!this.databaseDetected && response.headers.get("X-Integrate-Use-Database") === "true") {
|
|
1379
|
+
this.oauthManager.setSkipLocalStorage(true);
|
|
1380
|
+
this.databaseDetected = true;
|
|
1381
|
+
}
|
|
1387
1382
|
if (!response.ok) {
|
|
1388
1383
|
let errorMessage = `Request failed: ${response.statusText}`;
|
|
1389
1384
|
const error = new Error(errorMessage);
|
|
@@ -6556,10 +6551,17 @@ function createMCPServer(config) {
|
|
|
6556
6551
|
const oauthHandler = new OAuthHandler({
|
|
6557
6552
|
providers,
|
|
6558
6553
|
serverUrl: config.serverUrl,
|
|
6559
|
-
apiKey: config.apiKey
|
|
6554
|
+
apiKey: config.apiKey,
|
|
6555
|
+
setProviderToken: config.setProviderToken,
|
|
6556
|
+
removeProviderToken: config.removeProviderToken,
|
|
6557
|
+
getSessionContext: config.getSessionContext
|
|
6560
6558
|
});
|
|
6561
6559
|
const result = await oauthHandler.handleToolCall(body, authHeader);
|
|
6562
|
-
|
|
6560
|
+
const response2 = Response.json(result);
|
|
6561
|
+
if (oauthHandler.hasDatabaseCallbacks()) {
|
|
6562
|
+
response2.headers.set("X-Integrate-Use-Database", "true");
|
|
6563
|
+
}
|
|
6564
|
+
return response2;
|
|
6563
6565
|
} catch (error) {
|
|
6564
6566
|
console.error("[MCP Tool Call] Error:", error);
|
|
6565
6567
|
return Response.json({ error: error.message || "Failed to execute tool call" }, { status: error.statusCode || 500 });
|
|
@@ -6685,7 +6687,6 @@ function createMCPServer(config) {
|
|
|
6685
6687
|
}
|
|
6686
6688
|
}
|
|
6687
6689
|
if (!targetOrigin) {
|
|
6688
|
-
console.warn("[OAuth] Could not determine frontend origin for redirect. Using request origin as fallback.");
|
|
6689
6690
|
targetOrigin = new URL(webRequest.url).origin;
|
|
6690
6691
|
}
|
|
6691
6692
|
const targetUrl = new URL(returnUrl, targetOrigin);
|
|
@@ -7215,6 +7216,9 @@ class OAuthHandler {
|
|
|
7215
7216
|
}
|
|
7216
7217
|
return headers;
|
|
7217
7218
|
}
|
|
7219
|
+
hasDatabaseCallbacks() {
|
|
7220
|
+
return !!this.config.setProviderToken;
|
|
7221
|
+
}
|
|
7218
7222
|
async handleAuthorize(request) {
|
|
7219
7223
|
let webRequest;
|
|
7220
7224
|
let authorizeRequest;
|
|
@@ -7226,7 +7230,6 @@ class OAuthHandler {
|
|
|
7226
7230
|
} else {
|
|
7227
7231
|
authorizeRequest = request;
|
|
7228
7232
|
}
|
|
7229
|
-
console.log("[handleAuthorize] Received request for provider:", authorizeRequest.provider, "has codeVerifier:", !!authorizeRequest.codeVerifier, "has frontendOrigin:", !!authorizeRequest.frontendOrigin);
|
|
7230
7233
|
const providerConfig = this.config.providers[authorizeRequest.provider];
|
|
7231
7234
|
if (!providerConfig) {
|
|
7232
7235
|
throw new Error(`Provider ${authorizeRequest.provider} not configured. Add OAuth credentials to your API route configuration.`);
|
|
@@ -7267,22 +7270,14 @@ class OAuthHandler {
|
|
|
7267
7270
|
const data = await response.json();
|
|
7268
7271
|
const result = data;
|
|
7269
7272
|
if (!result.authorizationUrl) {
|
|
7270
|
-
console.error("[OAuth] MCP server did not return authorizationUrl:", data);
|
|
7271
7273
|
throw new Error("MCP server failed to return authorization URL");
|
|
7272
7274
|
}
|
|
7273
|
-
const urlPreview = result.authorizationUrl.length > 100 ? result.authorizationUrl.substring(0, 100) + "..." : result.authorizationUrl;
|
|
7274
|
-
console.log("[OAuth] Generated authorization URL:", urlPreview);
|
|
7275
7275
|
if (authorizeRequest.codeVerifier) {
|
|
7276
7276
|
try {
|
|
7277
7277
|
const { storeCodeVerifier: storeCodeVerifier2 } = await Promise.resolve().then(() => (init_server(), exports_server));
|
|
7278
7278
|
storeCodeVerifier2(authorizeRequest.state, authorizeRequest.codeVerifier, authorizeRequest.provider, authorizeRequest.frontendOrigin);
|
|
7279
|
-
|
|
7280
|
-
|
|
7281
|
-
console.warn("[OAuth] Failed to store codeVerifier:", error);
|
|
7282
|
-
}
|
|
7283
|
-
} else {
|
|
7284
|
-
console.log("[OAuth] No codeVerifier provided in authorize request");
|
|
7285
|
-
}
|
|
7279
|
+
} catch (error) {}
|
|
7280
|
+
} else {}
|
|
7286
7281
|
if (webRequest) {
|
|
7287
7282
|
try {
|
|
7288
7283
|
const { detectSessionContext: detectSessionContext2 } = await Promise.resolve().then(() => exports_session_detector);
|
|
@@ -7299,9 +7294,7 @@ class OAuthHandler {
|
|
|
7299
7294
|
const cookieValue = await createContextCookie2(context, authorizeRequest.provider, secret);
|
|
7300
7295
|
result.setCookie = getSetCookieHeader2(cookieValue);
|
|
7301
7296
|
}
|
|
7302
|
-
} catch (error) {
|
|
7303
|
-
console.warn("[OAuth] Failed to capture user context:", error);
|
|
7304
|
-
}
|
|
7297
|
+
} catch (error) {}
|
|
7305
7298
|
}
|
|
7306
7299
|
return result;
|
|
7307
7300
|
}
|
|
@@ -7335,9 +7328,7 @@ class OAuthHandler {
|
|
|
7335
7328
|
context = contextData.context;
|
|
7336
7329
|
}
|
|
7337
7330
|
}
|
|
7338
|
-
} catch (error) {
|
|
7339
|
-
console.warn("[OAuth] Failed to restore user context:", error);
|
|
7340
|
-
}
|
|
7331
|
+
} catch (error) {}
|
|
7341
7332
|
}
|
|
7342
7333
|
const url = new URL("/oauth/callback", this.serverUrl);
|
|
7343
7334
|
const response = await fetch(url.toString(), {
|
|
@@ -7372,9 +7363,7 @@ class OAuthHandler {
|
|
|
7372
7363
|
scopes: result.scopes
|
|
7373
7364
|
};
|
|
7374
7365
|
await this.config.setProviderToken(callbackRequest.provider, tokenData, context);
|
|
7375
|
-
} catch (error) {
|
|
7376
|
-
console.error("[OAuth] Failed to save provider token:", error);
|
|
7377
|
-
}
|
|
7366
|
+
} catch (error) {}
|
|
7378
7367
|
}
|
|
7379
7368
|
if (webRequest) {
|
|
7380
7369
|
const { getClearCookieHeader: getClearCookieHeader2 } = await Promise.resolve().then(() => exports_context_cookie);
|
|
@@ -7495,6 +7484,9 @@ function createNextOAuthHandler(config) {
|
|
|
7495
7484
|
if (result.setCookie) {
|
|
7496
7485
|
response.headers.set("Set-Cookie", result.setCookie);
|
|
7497
7486
|
}
|
|
7487
|
+
if (handler.hasDatabaseCallbacks()) {
|
|
7488
|
+
response.headers.set("X-Integrate-Use-Database", "true");
|
|
7489
|
+
}
|
|
7498
7490
|
return response;
|
|
7499
7491
|
} catch (error) {
|
|
7500
7492
|
console.error("[OAuth Authorize] Error:", error);
|
|
@@ -7508,6 +7500,9 @@ function createNextOAuthHandler(config) {
|
|
|
7508
7500
|
if (result.clearCookie) {
|
|
7509
7501
|
response.headers.set("Set-Cookie", result.clearCookie);
|
|
7510
7502
|
}
|
|
7503
|
+
if (handler.hasDatabaseCallbacks()) {
|
|
7504
|
+
response.headers.set("X-Integrate-Use-Database", "true");
|
|
7505
|
+
}
|
|
7511
7506
|
return response;
|
|
7512
7507
|
} catch (error) {
|
|
7513
7508
|
console.error("[OAuth Callback] Error:", error);
|
|
@@ -7526,7 +7521,11 @@ function createNextOAuthHandler(config) {
|
|
|
7526
7521
|
}
|
|
7527
7522
|
const accessToken = authHeader.substring(7);
|
|
7528
7523
|
const result = await handler.handleStatus(provider, accessToken);
|
|
7529
|
-
|
|
7524
|
+
const response = Response.json(result);
|
|
7525
|
+
if (handler.hasDatabaseCallbacks()) {
|
|
7526
|
+
response.headers.set("X-Integrate-Use-Database", "true");
|
|
7527
|
+
}
|
|
7528
|
+
return response;
|
|
7530
7529
|
} catch (error) {
|
|
7531
7530
|
console.error("[OAuth Status] Error:", error);
|
|
7532
7531
|
return Response.json({ error: error.message || "Failed to check authorization status" }, { status: 500 });
|
|
@@ -7545,7 +7544,11 @@ function createNextOAuthHandler(config) {
|
|
|
7545
7544
|
return Response.json({ error: "Missing provider in request body" }, { status: 400 });
|
|
7546
7545
|
}
|
|
7547
7546
|
const result = await handler.handleDisconnect({ provider }, accessToken, req);
|
|
7548
|
-
|
|
7547
|
+
const response = Response.json(result);
|
|
7548
|
+
if (handler.hasDatabaseCallbacks()) {
|
|
7549
|
+
response.headers.set("X-Integrate-Use-Database", "true");
|
|
7550
|
+
}
|
|
7551
|
+
return response;
|
|
7549
7552
|
} catch (error) {
|
|
7550
7553
|
console.error("[OAuth Disconnect] Error:", error);
|
|
7551
7554
|
return Response.json({ error: error.message || "Failed to disconnect provider" }, { status: 500 });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nextjs.d.ts","sourceRoot":"","sources":["../../../src/adapters/nextjs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG1E,KAAK,WAAW,GAAG,GAAG,CAAC;AACvB,KAAK,YAAY,GAAG,GAAG,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,kBAAkB;IAI7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;mBACkB,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"nextjs.d.ts","sourceRoot":"","sources":["../../../src/adapters/nextjs.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgB,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG1E,KAAK,WAAW,GAAG,GAAG,CAAC;AACvB,KAAK,YAAY,GAAG,GAAG,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,kBAAkB;IAI7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAwCG;mBACkB,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IA4BxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAyCG;kBACiB,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IA4BvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;gBACe,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAsCrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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