integrate-sdk 0.7.26 → 0.7.28
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/ai/anthropic.js +1 -1
- package/dist/ai/cloudflare.js +1 -1
- package/dist/ai/google.js +1 -1
- package/dist/ai/index.js +1 -1
- package/dist/ai/langchain.js +1 -1
- package/dist/ai/llamaindex.js +1 -1
- package/dist/ai/mastra.js +1 -1
- package/dist/ai/openai-agents.js +1 -1
- package/dist/ai/openai.js +1 -1
- package/dist/ai/utils.js +1 -1
- package/dist/ai/vercel-ai.js +1 -1
- package/dist/index.js +0 -281
- package/dist/react.js +0 -17
- package/dist/server.js +1 -158
- package/dist/src/utils/request-tokens.d.ts.map +1 -1
- package/package.json +4 -2
package/dist/ai/anthropic.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/ai/cloudflare.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/ai/google.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/ai/index.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/ai/langchain.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/ai/llamaindex.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/ai/mastra.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/ai/openai-agents.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/ai/openai.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/ai/utils.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/ai/vercel-ai.js
CHANGED
|
@@ -4009,7 +4009,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
4009
4009
|
try {
|
|
4010
4010
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
4011
4011
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
4012
|
-
const headersList = nextHeaders.headers();
|
|
4012
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
4013
4013
|
tokensString = headersList.get("x-integrate-tokens");
|
|
4014
4014
|
}
|
|
4015
4015
|
} catch {}
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
1
|
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
2
|
var __export = (target, all) => {
|
|
19
3
|
for (var name in all)
|
|
20
4
|
__defProp(target, name, {
|
|
@@ -25,7 +9,6 @@ var __export = (target, all) => {
|
|
|
25
9
|
});
|
|
26
10
|
};
|
|
27
11
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
28
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
29
12
|
|
|
30
13
|
// src/errors.ts
|
|
31
14
|
var exports_errors = {};
|
|
@@ -262,11 +245,6 @@ function base64UrlDecode(str) {
|
|
|
262
245
|
}
|
|
263
246
|
|
|
264
247
|
// src/adapters/base-handler.ts
|
|
265
|
-
var exports_base_handler = {};
|
|
266
|
-
__export(exports_base_handler, {
|
|
267
|
-
OAuthHandler: () => OAuthHandler
|
|
268
|
-
});
|
|
269
|
-
|
|
270
248
|
class OAuthHandler {
|
|
271
249
|
config;
|
|
272
250
|
serverUrl;
|
|
@@ -2245,266 +2223,7 @@ function createSimpleIntegration(config) {
|
|
|
2245
2223
|
onDisconnect: config.onDisconnect
|
|
2246
2224
|
};
|
|
2247
2225
|
}
|
|
2248
|
-
|
|
2249
2226
|
// src/server.ts
|
|
2250
|
-
var globalServerConfig = null;
|
|
2251
|
-
function getDefaultRedirectUri() {
|
|
2252
|
-
if (typeof window !== "undefined") {
|
|
2253
|
-
return `${window.location.origin}/api/integrate/oauth/callback`;
|
|
2254
|
-
}
|
|
2255
|
-
const integrateUrl = getEnv("INTEGRATE_URL");
|
|
2256
|
-
if (integrateUrl) {
|
|
2257
|
-
return `${integrateUrl}/api/integrate/oauth/callback`;
|
|
2258
|
-
}
|
|
2259
|
-
const vercelUrl = getEnv("VERCEL_URL");
|
|
2260
|
-
if (vercelUrl) {
|
|
2261
|
-
return `https://${vercelUrl}/api/integrate/oauth/callback`;
|
|
2262
|
-
}
|
|
2263
|
-
return "http://localhost:3000/api/integrate/oauth/callback";
|
|
2264
|
-
}
|
|
2265
|
-
function createMCPServer(config) {
|
|
2266
|
-
if (typeof window !== "undefined") {
|
|
2267
|
-
throw new Error("createMCPServer() should only be called on the server-side. " + "Use createMCPClient() for client-side code.");
|
|
2268
|
-
}
|
|
2269
|
-
const providers = {};
|
|
2270
|
-
const updatedIntegrations = config.integrations.map((integration) => {
|
|
2271
|
-
if (integration.oauth) {
|
|
2272
|
-
const { clientId, clientSecret, redirectUri: integrationRedirectUri } = integration.oauth;
|
|
2273
|
-
if (!clientId || !clientSecret) {
|
|
2274
|
-
console.warn(`Warning: Integration "${integration.id}" is missing OAuth credentials. ` + `Provide clientId and clientSecret in the integration configuration.`);
|
|
2275
|
-
return integration;
|
|
2276
|
-
}
|
|
2277
|
-
const redirectUri = integrationRedirectUri || config.redirectUri || getDefaultRedirectUri();
|
|
2278
|
-
providers[integration.id] = {
|
|
2279
|
-
clientId,
|
|
2280
|
-
clientSecret,
|
|
2281
|
-
redirectUri
|
|
2282
|
-
};
|
|
2283
|
-
return {
|
|
2284
|
-
...integration,
|
|
2285
|
-
oauth: {
|
|
2286
|
-
...integration.oauth,
|
|
2287
|
-
redirectUri
|
|
2288
|
-
}
|
|
2289
|
-
};
|
|
2290
|
-
}
|
|
2291
|
-
return integration;
|
|
2292
|
-
});
|
|
2293
|
-
globalServerConfig = {
|
|
2294
|
-
providers,
|
|
2295
|
-
serverUrl: config.serverUrl,
|
|
2296
|
-
apiKey: config.apiKey
|
|
2297
|
-
};
|
|
2298
|
-
const clientConfig = {
|
|
2299
|
-
...config,
|
|
2300
|
-
integrations: updatedIntegrations,
|
|
2301
|
-
connectionMode: config.connectionMode || "lazy",
|
|
2302
|
-
singleton: config.singleton ?? true
|
|
2303
|
-
};
|
|
2304
|
-
const client = new MCPClient(clientConfig);
|
|
2305
|
-
if (config.apiKey) {
|
|
2306
|
-
client.setRequestHeader("X-API-KEY", config.apiKey);
|
|
2307
|
-
}
|
|
2308
|
-
client.__oauthConfig = {
|
|
2309
|
-
providers,
|
|
2310
|
-
serverUrl: config.serverUrl,
|
|
2311
|
-
apiKey: config.apiKey
|
|
2312
|
-
};
|
|
2313
|
-
const { POST, GET } = createOAuthRouteHandlers({
|
|
2314
|
-
providers,
|
|
2315
|
-
serverUrl: config.serverUrl,
|
|
2316
|
-
apiKey: config.apiKey
|
|
2317
|
-
});
|
|
2318
|
-
const handler = async (request, context) => {
|
|
2319
|
-
const method = request.method.toUpperCase();
|
|
2320
|
-
let action;
|
|
2321
|
-
let segments = [];
|
|
2322
|
-
if (context?.params?.action) {
|
|
2323
|
-
action = context.params.action;
|
|
2324
|
-
} else if (context?.params?.all) {
|
|
2325
|
-
const all = context.params.all;
|
|
2326
|
-
if (Array.isArray(all)) {
|
|
2327
|
-
segments = all;
|
|
2328
|
-
} else if (typeof all === "string") {
|
|
2329
|
-
segments = all.split("/").filter(Boolean);
|
|
2330
|
-
}
|
|
2331
|
-
if (segments.length === 2 && segments[0] === "oauth") {
|
|
2332
|
-
action = segments[1];
|
|
2333
|
-
} else if (segments.length === 1) {
|
|
2334
|
-
if (segments[0] === "mcp") {
|
|
2335
|
-
action = "mcp";
|
|
2336
|
-
} else {
|
|
2337
|
-
action = segments[0];
|
|
2338
|
-
}
|
|
2339
|
-
} else if (segments.length > 0) {
|
|
2340
|
-
action = segments[segments.length - 1];
|
|
2341
|
-
}
|
|
2342
|
-
} else {
|
|
2343
|
-
const url = new URL(request.url);
|
|
2344
|
-
const pathParts = url.pathname.split("/").filter(Boolean);
|
|
2345
|
-
segments = pathParts;
|
|
2346
|
-
const oauthIndex = pathParts.indexOf("oauth");
|
|
2347
|
-
if (oauthIndex >= 0 && oauthIndex < pathParts.length - 1) {
|
|
2348
|
-
action = pathParts[oauthIndex + 1];
|
|
2349
|
-
} else if (pathParts.length > 0) {
|
|
2350
|
-
action = pathParts[pathParts.length - 1];
|
|
2351
|
-
} else {
|
|
2352
|
-
action = "callback";
|
|
2353
|
-
}
|
|
2354
|
-
}
|
|
2355
|
-
if (action === "mcp" && method === "POST") {
|
|
2356
|
-
try {
|
|
2357
|
-
const body = await request.json();
|
|
2358
|
-
const authHeader = request.headers.get("authorization");
|
|
2359
|
-
const { OAuthHandler: OAuthHandler2 } = await Promise.resolve().then(() => exports_base_handler);
|
|
2360
|
-
const oauthHandler = new OAuthHandler2({
|
|
2361
|
-
providers,
|
|
2362
|
-
serverUrl: config.serverUrl,
|
|
2363
|
-
apiKey: config.apiKey
|
|
2364
|
-
});
|
|
2365
|
-
const result = await oauthHandler.handleToolCall(body, authHeader);
|
|
2366
|
-
return Response.json(result);
|
|
2367
|
-
} catch (error) {
|
|
2368
|
-
console.error("[MCP Tool Call] Error:", error);
|
|
2369
|
-
return Response.json({ error: error.message || "Failed to execute tool call" }, { status: error.statusCode || 500 });
|
|
2370
|
-
}
|
|
2371
|
-
}
|
|
2372
|
-
if (segments.length > 0) {
|
|
2373
|
-
if (segments.length === 2 && segments[0] !== "oauth") {
|
|
2374
|
-
return Response.json({ error: `Invalid route: /${segments.join("/")}` }, { status: 404 });
|
|
2375
|
-
}
|
|
2376
|
-
if (segments.length === 1 && segments[0] === "mcp") {
|
|
2377
|
-
return Response.json({ error: `Method ${method} not allowed for /mcp route. Use POST.` }, { status: 405 });
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
if (method === "GET" && action === "callback") {
|
|
2381
|
-
const url = new URL(request.url);
|
|
2382
|
-
const searchParams = url.searchParams;
|
|
2383
|
-
const code = searchParams.get("code");
|
|
2384
|
-
const state = searchParams.get("state");
|
|
2385
|
-
const error = searchParams.get("error");
|
|
2386
|
-
const errorDescription = searchParams.get("error_description");
|
|
2387
|
-
const defaultRedirectUrl = "/";
|
|
2388
|
-
const errorRedirectUrl = "/auth-error";
|
|
2389
|
-
if (error) {
|
|
2390
|
-
const errorMsg = errorDescription || error;
|
|
2391
|
-
console.error("[OAuth Redirect] Error:", errorMsg);
|
|
2392
|
-
return Response.redirect(new URL(`${errorRedirectUrl}?error=${encodeURIComponent(errorMsg)}`, request.url));
|
|
2393
|
-
}
|
|
2394
|
-
if (!code || !state) {
|
|
2395
|
-
console.error("[OAuth Redirect] Missing code or state parameter");
|
|
2396
|
-
return Response.redirect(new URL(`${errorRedirectUrl}?error=${encodeURIComponent("Invalid OAuth callback")}`, request.url));
|
|
2397
|
-
}
|
|
2398
|
-
let returnUrl = defaultRedirectUrl;
|
|
2399
|
-
try {
|
|
2400
|
-
const { parseState: parseState2 } = await Promise.resolve().then(() => exports_pkce);
|
|
2401
|
-
const stateData = parseState2(state);
|
|
2402
|
-
if (stateData.returnUrl) {
|
|
2403
|
-
returnUrl = stateData.returnUrl;
|
|
2404
|
-
}
|
|
2405
|
-
} catch (e) {
|
|
2406
|
-
try {
|
|
2407
|
-
const referrer = request.headers.get("referer") || request.headers.get("referrer");
|
|
2408
|
-
if (referrer) {
|
|
2409
|
-
const referrerUrl = new URL(referrer);
|
|
2410
|
-
const currentUrl = new URL(request.url);
|
|
2411
|
-
if (referrerUrl.origin === currentUrl.origin) {
|
|
2412
|
-
returnUrl = referrerUrl.pathname + referrerUrl.search;
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
} catch {}
|
|
2416
|
-
}
|
|
2417
|
-
const targetUrl = new URL(returnUrl, request.url);
|
|
2418
|
-
targetUrl.hash = `oauth_callback=${encodeURIComponent(JSON.stringify({ code, state }))}`;
|
|
2419
|
-
return Response.redirect(targetUrl);
|
|
2420
|
-
}
|
|
2421
|
-
const handlerContext = { params: { action: action || "callback" } };
|
|
2422
|
-
if (method === "POST") {
|
|
2423
|
-
return POST(request, handlerContext);
|
|
2424
|
-
} else if (method === "GET") {
|
|
2425
|
-
return GET(request, handlerContext);
|
|
2426
|
-
} else {
|
|
2427
|
-
return Response.json({ error: `Method ${method} not allowed` }, { status: 405 });
|
|
2428
|
-
}
|
|
2429
|
-
};
|
|
2430
|
-
const serverClient = client;
|
|
2431
|
-
serverClient.handler = handler;
|
|
2432
|
-
serverClient.POST = POST;
|
|
2433
|
-
serverClient.GET = GET;
|
|
2434
|
-
return {
|
|
2435
|
-
client: serverClient,
|
|
2436
|
-
POST,
|
|
2437
|
-
GET
|
|
2438
|
-
};
|
|
2439
|
-
}
|
|
2440
|
-
function createOAuthRouteHandlers(config) {
|
|
2441
|
-
const handler = createNextOAuthHandler(config);
|
|
2442
|
-
return handler.createRoutes();
|
|
2443
|
-
}
|
|
2444
|
-
var POST = async (req, context) => {
|
|
2445
|
-
if (!globalServerConfig) {
|
|
2446
|
-
return Response.json({ error: "OAuth not configured. Call createMCPServer() in your server initialization file first." }, { status: 500 });
|
|
2447
|
-
}
|
|
2448
|
-
const handler = createNextOAuthHandler(globalServerConfig);
|
|
2449
|
-
const routes = handler.createRoutes();
|
|
2450
|
-
return routes.POST(req, context);
|
|
2451
|
-
};
|
|
2452
|
-
var GET = async (req, context) => {
|
|
2453
|
-
if (!globalServerConfig) {
|
|
2454
|
-
return Response.json({ error: "OAuth not configured. Call createMCPServer() in your server initialization file first." }, { status: 500 });
|
|
2455
|
-
}
|
|
2456
|
-
const handler = createNextOAuthHandler(globalServerConfig);
|
|
2457
|
-
const routes = handler.createRoutes();
|
|
2458
|
-
return routes.GET(req, context);
|
|
2459
|
-
};
|
|
2460
|
-
function toNextJsHandler(clientOrOptions, redirectOptions) {
|
|
2461
|
-
let config;
|
|
2462
|
-
let redirectUrl;
|
|
2463
|
-
let errorRedirectUrl;
|
|
2464
|
-
if (!clientOrOptions) {
|
|
2465
|
-
config = globalServerConfig;
|
|
2466
|
-
redirectUrl = redirectOptions?.redirectUrl;
|
|
2467
|
-
errorRedirectUrl = redirectOptions?.errorRedirectUrl;
|
|
2468
|
-
} else if (clientOrOptions.__oauthConfig) {
|
|
2469
|
-
config = clientOrOptions.__oauthConfig;
|
|
2470
|
-
redirectUrl = redirectOptions?.redirectUrl;
|
|
2471
|
-
errorRedirectUrl = redirectOptions?.errorRedirectUrl;
|
|
2472
|
-
} else if (typeof clientOrOptions === "object" && clientOrOptions.providers) {
|
|
2473
|
-
const options = clientOrOptions;
|
|
2474
|
-
config = {
|
|
2475
|
-
providers: options.providers,
|
|
2476
|
-
serverUrl: options.serverUrl,
|
|
2477
|
-
apiKey: options.apiKey
|
|
2478
|
-
};
|
|
2479
|
-
redirectUrl = options.redirectUrl;
|
|
2480
|
-
errorRedirectUrl = options.errorRedirectUrl;
|
|
2481
|
-
} else {
|
|
2482
|
-
config = null;
|
|
2483
|
-
}
|
|
2484
|
-
if (!config) {
|
|
2485
|
-
throw new Error(`toNextJsHandler requires either:
|
|
2486
|
-
1. A client instance from createMCPServer()
|
|
2487
|
-
2. A config object with providers property
|
|
2488
|
-
3. No arguments (uses global config from createMCPServer)`);
|
|
2489
|
-
}
|
|
2490
|
-
const POST2 = async (req, context) => {
|
|
2491
|
-
const handler = createNextOAuthHandler(config);
|
|
2492
|
-
const routes = handler.toNextJsHandler({
|
|
2493
|
-
redirectUrl,
|
|
2494
|
-
errorRedirectUrl
|
|
2495
|
-
});
|
|
2496
|
-
return routes.POST(req, context);
|
|
2497
|
-
};
|
|
2498
|
-
const GET2 = async (req, context) => {
|
|
2499
|
-
const handler = createNextOAuthHandler(config);
|
|
2500
|
-
const routes = handler.toNextJsHandler({
|
|
2501
|
-
redirectUrl,
|
|
2502
|
-
errorRedirectUrl
|
|
2503
|
-
});
|
|
2504
|
-
return routes.GET(req, context);
|
|
2505
|
-
};
|
|
2506
|
-
return { POST: POST2, GET: GET2 };
|
|
2507
|
-
}
|
|
2508
2227
|
function toSolidStartHandler(clientOrHandlerOrOptions, _redirectOptions) {
|
|
2509
2228
|
if (clientOrHandlerOrOptions && clientOrHandlerOrOptions.handler && typeof clientOrHandlerOrOptions.handler === "function") {
|
|
2510
2229
|
const baseHandler = clientOrHandlerOrOptions.handler;
|
package/dist/react.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
1
|
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
8
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
|
-
for (let key of __getOwnPropNames(mod))
|
|
11
|
-
if (!__hasOwnProp.call(to, key))
|
|
12
|
-
__defProp(to, key, {
|
|
13
|
-
get: () => mod[key],
|
|
14
|
-
enumerable: true
|
|
15
|
-
});
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
2
|
var __export = (target, all) => {
|
|
19
3
|
for (var name in all)
|
|
20
4
|
__defProp(target, name, {
|
|
@@ -25,7 +9,6 @@ var __export = (target, all) => {
|
|
|
25
9
|
});
|
|
26
10
|
};
|
|
27
11
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
28
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
29
12
|
|
|
30
13
|
// src/react/hooks.ts
|
|
31
14
|
import { useState, useEffect } from "react";
|
package/dist/server.js
CHANGED
|
@@ -629,18 +629,6 @@ class HttpSessionTransport {
|
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
631
|
|
|
632
|
-
// src/protocol/messages.ts
|
|
633
|
-
var MCPMethod;
|
|
634
|
-
((MCPMethod2) => {
|
|
635
|
-
MCPMethod2["INITIALIZE"] = "initialize";
|
|
636
|
-
MCPMethod2["TOOLS_LIST"] = "tools/list";
|
|
637
|
-
MCPMethod2["TOOLS_CALL"] = "tools/call";
|
|
638
|
-
MCPMethod2["RESOURCES_LIST"] = "resources/list";
|
|
639
|
-
MCPMethod2["RESOURCES_READ"] = "resources/read";
|
|
640
|
-
MCPMethod2["PROMPTS_LIST"] = "prompts/list";
|
|
641
|
-
MCPMethod2["PROMPTS_GET"] = "prompts/get";
|
|
642
|
-
})(MCPMethod ||= {});
|
|
643
|
-
|
|
644
632
|
// src/client.ts
|
|
645
633
|
init_errors();
|
|
646
634
|
|
|
@@ -822,23 +810,6 @@ class OAuthWindowManager {
|
|
|
822
810
|
this.cleanup();
|
|
823
811
|
}
|
|
824
812
|
}
|
|
825
|
-
function sendCallbackToOpener(params) {
|
|
826
|
-
if (!isBrowser()) {
|
|
827
|
-
console.error("sendCallbackToOpener() can only be used in browser environments");
|
|
828
|
-
return;
|
|
829
|
-
}
|
|
830
|
-
if (!window.opener) {
|
|
831
|
-
console.error("No opener window found. This function should only be called from a popup window.");
|
|
832
|
-
return;
|
|
833
|
-
}
|
|
834
|
-
window.opener.postMessage({
|
|
835
|
-
type: "oauth_callback",
|
|
836
|
-
code: params.code,
|
|
837
|
-
state: params.state,
|
|
838
|
-
error: params.error
|
|
839
|
-
}, "*");
|
|
840
|
-
window.close();
|
|
841
|
-
}
|
|
842
813
|
|
|
843
814
|
// src/oauth/manager.ts
|
|
844
815
|
class OAuthManager {
|
|
@@ -1185,8 +1156,6 @@ class SimpleEventEmitter {
|
|
|
1185
1156
|
var MCP_SERVER_URL = "https://mcp.integrate.dev/api/v1/mcp";
|
|
1186
1157
|
var clientCache = new Map;
|
|
1187
1158
|
var cleanupClients = new Set;
|
|
1188
|
-
var cleanupHandlersRegistered = false;
|
|
1189
|
-
|
|
1190
1159
|
class MCPClient {
|
|
1191
1160
|
transport;
|
|
1192
1161
|
integrations;
|
|
@@ -1634,132 +1603,6 @@ class MCPClient {
|
|
|
1634
1603
|
return success;
|
|
1635
1604
|
}
|
|
1636
1605
|
}
|
|
1637
|
-
function registerCleanupHandlers() {
|
|
1638
|
-
if (cleanupHandlersRegistered)
|
|
1639
|
-
return;
|
|
1640
|
-
cleanupHandlersRegistered = true;
|
|
1641
|
-
const cleanup = async () => {
|
|
1642
|
-
const clients = Array.from(cleanupClients);
|
|
1643
|
-
cleanupClients.clear();
|
|
1644
|
-
await Promise.all(clients.map(async (client) => {
|
|
1645
|
-
try {
|
|
1646
|
-
if (client.isConnected()) {
|
|
1647
|
-
await client.disconnect();
|
|
1648
|
-
}
|
|
1649
|
-
} catch (error) {
|
|
1650
|
-
console.error("Error disconnecting client:", error);
|
|
1651
|
-
}
|
|
1652
|
-
}));
|
|
1653
|
-
};
|
|
1654
|
-
if (typeof process !== "undefined" && typeof process.on === "function" && typeof process.exit === "function") {
|
|
1655
|
-
try {
|
|
1656
|
-
process.on("SIGINT", async () => {
|
|
1657
|
-
await cleanup();
|
|
1658
|
-
process.exit(0);
|
|
1659
|
-
});
|
|
1660
|
-
process.on("SIGTERM", async () => {
|
|
1661
|
-
await cleanup();
|
|
1662
|
-
process.exit(0);
|
|
1663
|
-
});
|
|
1664
|
-
process.on("beforeExit", async () => {
|
|
1665
|
-
await cleanup();
|
|
1666
|
-
});
|
|
1667
|
-
} catch (error) {}
|
|
1668
|
-
}
|
|
1669
|
-
}
|
|
1670
|
-
function generateCacheKey(config) {
|
|
1671
|
-
const parts = [
|
|
1672
|
-
config.serverUrl || "default",
|
|
1673
|
-
config.clientInfo?.name || "integrate-sdk",
|
|
1674
|
-
config.clientInfo?.version || "0.1.0",
|
|
1675
|
-
JSON.stringify(config.integrations.map((p) => ({ id: p.id, tools: p.tools }))),
|
|
1676
|
-
JSON.stringify(config.headers || {}),
|
|
1677
|
-
config.timeout?.toString() || "30000"
|
|
1678
|
-
];
|
|
1679
|
-
return parts.join("|");
|
|
1680
|
-
}
|
|
1681
|
-
function createMCPClient(config) {
|
|
1682
|
-
const useSingleton = config.singleton ?? true;
|
|
1683
|
-
const connectionMode = config.connectionMode ?? "lazy";
|
|
1684
|
-
const autoCleanup = config.autoCleanup ?? true;
|
|
1685
|
-
if (useSingleton) {
|
|
1686
|
-
const cacheKey = generateCacheKey(config);
|
|
1687
|
-
const existing = clientCache.get(cacheKey);
|
|
1688
|
-
if (existing && existing.isConnected()) {
|
|
1689
|
-
return existing;
|
|
1690
|
-
}
|
|
1691
|
-
if (existing) {
|
|
1692
|
-
clientCache.delete(cacheKey);
|
|
1693
|
-
cleanupClients.delete(existing);
|
|
1694
|
-
}
|
|
1695
|
-
const client = new MCPClient(config);
|
|
1696
|
-
clientCache.set(cacheKey, client);
|
|
1697
|
-
if (autoCleanup) {
|
|
1698
|
-
cleanupClients.add(client);
|
|
1699
|
-
registerCleanupHandlers();
|
|
1700
|
-
}
|
|
1701
|
-
if (connectionMode === "eager") {
|
|
1702
|
-
client.connect().catch((error) => {
|
|
1703
|
-
console.error("Failed to connect client:", error);
|
|
1704
|
-
});
|
|
1705
|
-
}
|
|
1706
|
-
if (config.autoHandleOAuthCallback !== false) {
|
|
1707
|
-
processOAuthCallbackFromHash(client);
|
|
1708
|
-
}
|
|
1709
|
-
return client;
|
|
1710
|
-
} else {
|
|
1711
|
-
const client = new MCPClient(config);
|
|
1712
|
-
if (autoCleanup) {
|
|
1713
|
-
cleanupClients.add(client);
|
|
1714
|
-
registerCleanupHandlers();
|
|
1715
|
-
}
|
|
1716
|
-
if (connectionMode === "eager") {
|
|
1717
|
-
client.connect().catch((error) => {
|
|
1718
|
-
console.error("Failed to connect client:", error);
|
|
1719
|
-
});
|
|
1720
|
-
}
|
|
1721
|
-
if (config.autoHandleOAuthCallback !== false) {
|
|
1722
|
-
processOAuthCallbackFromHash(client);
|
|
1723
|
-
}
|
|
1724
|
-
return client;
|
|
1725
|
-
}
|
|
1726
|
-
}
|
|
1727
|
-
function processOAuthCallbackFromHash(client) {
|
|
1728
|
-
if (typeof window === "undefined" || !window.location) {
|
|
1729
|
-
return;
|
|
1730
|
-
}
|
|
1731
|
-
try {
|
|
1732
|
-
const hash = window.location.hash;
|
|
1733
|
-
if (hash && hash.includes("oauth_callback=")) {
|
|
1734
|
-
const hashParams = new URLSearchParams(hash.substring(1));
|
|
1735
|
-
const oauthCallbackData = hashParams.get("oauth_callback");
|
|
1736
|
-
if (oauthCallbackData) {
|
|
1737
|
-
const callbackParams = JSON.parse(decodeURIComponent(oauthCallbackData));
|
|
1738
|
-
if (callbackParams.code && callbackParams.state) {
|
|
1739
|
-
client.handleOAuthCallback(callbackParams).catch((error) => {
|
|
1740
|
-
console.error("Failed to process OAuth callback:", error);
|
|
1741
|
-
});
|
|
1742
|
-
window.history.replaceState(null, "", window.location.pathname + window.location.search);
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
}
|
|
1746
|
-
} catch (error) {
|
|
1747
|
-
console.error("Failed to process OAuth callback from hash:", error);
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
async function clearClientCache() {
|
|
1751
|
-
const clients = Array.from(clientCache.values());
|
|
1752
|
-
clientCache.clear();
|
|
1753
|
-
await Promise.all(clients.map(async (client) => {
|
|
1754
|
-
try {
|
|
1755
|
-
if (client.isConnected()) {
|
|
1756
|
-
await client.disconnect();
|
|
1757
|
-
}
|
|
1758
|
-
} catch (error) {
|
|
1759
|
-
console.error("Error disconnecting client during cache clear:", error);
|
|
1760
|
-
}
|
|
1761
|
-
}));
|
|
1762
|
-
}
|
|
1763
1606
|
|
|
1764
1607
|
// src/adapters/nextjs.ts
|
|
1765
1608
|
function createNextOAuthHandler(config) {
|
|
@@ -6424,7 +6267,7 @@ async function getProviderTokens(manualTokens) {
|
|
|
6424
6267
|
try {
|
|
6425
6268
|
const nextHeaders = await import("next/headers").catch(() => null);
|
|
6426
6269
|
if (nextHeaders && typeof nextHeaders.headers === "function") {
|
|
6427
|
-
const headersList = nextHeaders.headers();
|
|
6270
|
+
const headersList = await Promise.resolve(nextHeaders.headers());
|
|
6428
6271
|
tokensString = headersList.get("x-integrate-tokens");
|
|
6429
6272
|
}
|
|
6430
6273
|
} catch {}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-tokens.d.ts","sourceRoot":"","sources":["../../../src/utils/request-tokens.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAsB,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"request-tokens.d.ts","sourceRoot":"","sources":["../../../src/utils/request-tokens.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAsB,iBAAiB,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAyE9G;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,oBAAoB,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC,CAMxH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "integrate-sdk",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.28",
|
|
4
4
|
"description": "Type-safe 3rd party integration SDK for the Integrate MCP server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -42,7 +42,9 @@
|
|
|
42
42
|
],
|
|
43
43
|
"scripts": {
|
|
44
44
|
"prep": "bun run type-check && bun run build",
|
|
45
|
-
"build": "bun build
|
|
45
|
+
"build": "bun run build:client && bun run build:server && bun run build:adapters && bun run build:ai && bun run build:types && bun run build:copy-types",
|
|
46
|
+
"build:client": "bun build index.ts react.ts --outdir dist --target browser --format esm --external react",
|
|
47
|
+
"build:server": "bun build server.ts oauth.ts --outdir dist --target node --format esm",
|
|
46
48
|
"build:adapters": "cd src/adapters && bun build *.ts --outdir ../../dist/adapters --target node --format esm && cd ../..",
|
|
47
49
|
"build:ai": "cd src/ai && bun build *.ts --outdir ../../dist/ai --target node --format esm && cd ../..",
|
|
48
50
|
"build:types": "tsc --emitDeclarationOnly --declaration --declarationMap",
|