integrate-sdk 0.7.12 → 0.7.14
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/index.js +1 -54
- package/dist/server.js +1 -55
- package/dist/src/server.d.ts +11 -56
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2384,8 +2384,7 @@ function createMCPServer(config) {
|
|
|
2384
2384
|
return {
|
|
2385
2385
|
client,
|
|
2386
2386
|
POST,
|
|
2387
|
-
GET
|
|
2388
|
-
handler
|
|
2387
|
+
GET
|
|
2389
2388
|
};
|
|
2390
2389
|
}
|
|
2391
2390
|
function createOAuthRouteHandlers(config) {
|
|
@@ -2455,58 +2454,6 @@ function toNextJsHandler(clientOrOptions, redirectOptions) {
|
|
|
2455
2454
|
};
|
|
2456
2455
|
return { POST: POST2, GET: GET2 };
|
|
2457
2456
|
}
|
|
2458
|
-
function toAstroHandler(baseHandler, options) {
|
|
2459
|
-
const defaultRedirectUrl = options?.redirectUrl || "/";
|
|
2460
|
-
const errorRedirectUrl = options?.errorRedirectUrl || "/auth-error";
|
|
2461
|
-
return async (ctx) => {
|
|
2462
|
-
const wrappedHandler = async (request, context) => {
|
|
2463
|
-
const url = new URL(request.url);
|
|
2464
|
-
const method = request.method.toUpperCase();
|
|
2465
|
-
const pathParts = url.pathname.split("/").filter(Boolean);
|
|
2466
|
-
const oauthIndex = pathParts.indexOf("oauth");
|
|
2467
|
-
if (method === "GET" && oauthIndex >= 0 && pathParts[oauthIndex + 1] === "callback") {
|
|
2468
|
-
const searchParams = url.searchParams;
|
|
2469
|
-
const code = searchParams.get("code");
|
|
2470
|
-
const state = searchParams.get("state");
|
|
2471
|
-
const error = searchParams.get("error");
|
|
2472
|
-
const errorDescription = searchParams.get("error_description");
|
|
2473
|
-
if (error) {
|
|
2474
|
-
const errorMsg = errorDescription || error;
|
|
2475
|
-
console.error("[OAuth Redirect] Error:", errorMsg);
|
|
2476
|
-
return Response.redirect(new URL(`${errorRedirectUrl}?error=${encodeURIComponent(errorMsg)}`, request.url));
|
|
2477
|
-
}
|
|
2478
|
-
if (!code || !state) {
|
|
2479
|
-
console.error("[OAuth Redirect] Missing code or state parameter");
|
|
2480
|
-
return Response.redirect(new URL(`${errorRedirectUrl}?error=${encodeURIComponent("Invalid OAuth callback")}`, request.url));
|
|
2481
|
-
}
|
|
2482
|
-
let returnUrl = defaultRedirectUrl;
|
|
2483
|
-
try {
|
|
2484
|
-
const { parseState: parseState2 } = await Promise.resolve().then(() => exports_pkce);
|
|
2485
|
-
const stateData = parseState2(state);
|
|
2486
|
-
if (stateData.returnUrl) {
|
|
2487
|
-
returnUrl = stateData.returnUrl;
|
|
2488
|
-
}
|
|
2489
|
-
} catch (e) {
|
|
2490
|
-
try {
|
|
2491
|
-
const referrer = request.headers.get("referer") || request.headers.get("referrer");
|
|
2492
|
-
if (referrer) {
|
|
2493
|
-
const referrerUrl = new URL(referrer);
|
|
2494
|
-
const currentUrl = new URL(request.url);
|
|
2495
|
-
if (referrerUrl.origin === currentUrl.origin) {
|
|
2496
|
-
returnUrl = referrerUrl.pathname + referrerUrl.search;
|
|
2497
|
-
}
|
|
2498
|
-
}
|
|
2499
|
-
} catch {}
|
|
2500
|
-
}
|
|
2501
|
-
const targetUrl = new URL(returnUrl, request.url);
|
|
2502
|
-
targetUrl.hash = `oauth_callback=${encodeURIComponent(JSON.stringify({ code, state }))}`;
|
|
2503
|
-
return Response.redirect(targetUrl);
|
|
2504
|
-
}
|
|
2505
|
-
return baseHandler(request, context);
|
|
2506
|
-
};
|
|
2507
|
-
return wrappedHandler(ctx.request, { params: { all: ctx.params.all } });
|
|
2508
|
-
};
|
|
2509
|
-
}
|
|
2510
2457
|
function toSolidStartHandler(clientOrHandlerOrOptions, _redirectOptions) {
|
|
2511
2458
|
if (clientOrHandlerOrOptions && clientOrHandlerOrOptions.handler && typeof clientOrHandlerOrOptions.handler === "function") {
|
|
2512
2459
|
const baseHandler = clientOrHandlerOrOptions.handler;
|
package/dist/server.js
CHANGED
|
@@ -2210,8 +2210,7 @@ function createMCPServer(config) {
|
|
|
2210
2210
|
return {
|
|
2211
2211
|
client,
|
|
2212
2212
|
POST,
|
|
2213
|
-
GET
|
|
2214
|
-
handler
|
|
2213
|
+
GET
|
|
2215
2214
|
};
|
|
2216
2215
|
}
|
|
2217
2216
|
function createOAuthRouteHandlers(config) {
|
|
@@ -2281,58 +2280,6 @@ function toNextJsHandler(clientOrOptions, redirectOptions) {
|
|
|
2281
2280
|
};
|
|
2282
2281
|
return { POST: POST2, GET: GET2 };
|
|
2283
2282
|
}
|
|
2284
|
-
function toAstroHandler(baseHandler, options) {
|
|
2285
|
-
const defaultRedirectUrl = options?.redirectUrl || "/";
|
|
2286
|
-
const errorRedirectUrl = options?.errorRedirectUrl || "/auth-error";
|
|
2287
|
-
return async (ctx) => {
|
|
2288
|
-
const wrappedHandler = async (request, context) => {
|
|
2289
|
-
const url = new URL(request.url);
|
|
2290
|
-
const method = request.method.toUpperCase();
|
|
2291
|
-
const pathParts = url.pathname.split("/").filter(Boolean);
|
|
2292
|
-
const oauthIndex = pathParts.indexOf("oauth");
|
|
2293
|
-
if (method === "GET" && oauthIndex >= 0 && pathParts[oauthIndex + 1] === "callback") {
|
|
2294
|
-
const searchParams = url.searchParams;
|
|
2295
|
-
const code = searchParams.get("code");
|
|
2296
|
-
const state = searchParams.get("state");
|
|
2297
|
-
const error = searchParams.get("error");
|
|
2298
|
-
const errorDescription = searchParams.get("error_description");
|
|
2299
|
-
if (error) {
|
|
2300
|
-
const errorMsg = errorDescription || error;
|
|
2301
|
-
console.error("[OAuth Redirect] Error:", errorMsg);
|
|
2302
|
-
return Response.redirect(new URL(`${errorRedirectUrl}?error=${encodeURIComponent(errorMsg)}`, request.url));
|
|
2303
|
-
}
|
|
2304
|
-
if (!code || !state) {
|
|
2305
|
-
console.error("[OAuth Redirect] Missing code or state parameter");
|
|
2306
|
-
return Response.redirect(new URL(`${errorRedirectUrl}?error=${encodeURIComponent("Invalid OAuth callback")}`, request.url));
|
|
2307
|
-
}
|
|
2308
|
-
let returnUrl = defaultRedirectUrl;
|
|
2309
|
-
try {
|
|
2310
|
-
const { parseState: parseState2 } = await Promise.resolve().then(() => exports_pkce);
|
|
2311
|
-
const stateData = parseState2(state);
|
|
2312
|
-
if (stateData.returnUrl) {
|
|
2313
|
-
returnUrl = stateData.returnUrl;
|
|
2314
|
-
}
|
|
2315
|
-
} catch (e) {
|
|
2316
|
-
try {
|
|
2317
|
-
const referrer = request.headers.get("referer") || request.headers.get("referrer");
|
|
2318
|
-
if (referrer) {
|
|
2319
|
-
const referrerUrl = new URL(referrer);
|
|
2320
|
-
const currentUrl = new URL(request.url);
|
|
2321
|
-
if (referrerUrl.origin === currentUrl.origin) {
|
|
2322
|
-
returnUrl = referrerUrl.pathname + referrerUrl.search;
|
|
2323
|
-
}
|
|
2324
|
-
}
|
|
2325
|
-
} catch {}
|
|
2326
|
-
}
|
|
2327
|
-
const targetUrl = new URL(returnUrl, request.url);
|
|
2328
|
-
targetUrl.hash = `oauth_callback=${encodeURIComponent(JSON.stringify({ code, state }))}`;
|
|
2329
|
-
return Response.redirect(targetUrl);
|
|
2330
|
-
}
|
|
2331
|
-
return baseHandler(request, context);
|
|
2332
|
-
};
|
|
2333
|
-
return wrappedHandler(ctx.request, { params: { all: ctx.params.all } });
|
|
2334
|
-
};
|
|
2335
|
-
}
|
|
2336
2283
|
function toSolidStartHandler(clientOrHandlerOrOptions, _redirectOptions) {
|
|
2337
2284
|
if (clientOrHandlerOrOptions && clientOrHandlerOrOptions.handler && typeof clientOrHandlerOrOptions.handler === "function") {
|
|
2338
2285
|
const baseHandler = clientOrHandlerOrOptions.handler;
|
|
@@ -2447,7 +2394,6 @@ export {
|
|
|
2447
2394
|
toSvelteKitHandler,
|
|
2448
2395
|
toSolidStartHandler,
|
|
2449
2396
|
toNextJsHandler,
|
|
2450
|
-
toAstroHandler,
|
|
2451
2397
|
gmailPlugin,
|
|
2452
2398
|
githubPlugin,
|
|
2453
2399
|
genericOAuthPlugin,
|
package/dist/src/server.d.ts
CHANGED
|
@@ -53,6 +53,17 @@ import type { MCPPlugin } from './plugins/types.js';
|
|
|
53
53
|
* export const POST = serverClient.handler;
|
|
54
54
|
* export const GET = serverClient.handler;
|
|
55
55
|
* ```
|
|
56
|
+
*
|
|
57
|
+
* Or for Astro:
|
|
58
|
+
* ```typescript
|
|
59
|
+
* // pages/api/integrate/[...all].ts (Astro)
|
|
60
|
+
* import { serverClient } from '@/lib/integrate-server';
|
|
61
|
+
* import type { APIRoute } from 'astro';
|
|
62
|
+
*
|
|
63
|
+
* export const ALL: APIRoute = async (ctx) => {
|
|
64
|
+
* return serverClient.handler(ctx.request);
|
|
65
|
+
* };
|
|
66
|
+
* ```
|
|
56
67
|
*/
|
|
57
68
|
export declare function createMCPServer<TPlugins extends readonly MCPPlugin[]>(config: MCPServerConfig<TPlugins>): {
|
|
58
69
|
/** Server-side MCP client instance with auto-connection and attached handler */
|
|
@@ -73,13 +84,6 @@ export declare function createMCPServer<TPlugins extends readonly MCPPlugin[]>(c
|
|
|
73
84
|
action: string;
|
|
74
85
|
}>;
|
|
75
86
|
}) => Promise<any>;
|
|
76
|
-
/** Unified handler function - handles both POST and GET requests */
|
|
77
|
-
handler: (request: Request, context?: {
|
|
78
|
-
params?: {
|
|
79
|
-
action?: string;
|
|
80
|
-
all?: string | string[];
|
|
81
|
-
};
|
|
82
|
-
}) => Promise<Response>;
|
|
83
87
|
};
|
|
84
88
|
export type { MCPPlugin } from './plugins/types.js';
|
|
85
89
|
export type { MCPClientConfig } from './config/types.js';
|
|
@@ -217,55 +221,6 @@ export declare function toNextJsHandler(clientOrOptions?: any | {
|
|
|
217
221
|
}>;
|
|
218
222
|
}) => Promise<any>;
|
|
219
223
|
};
|
|
220
|
-
/**
|
|
221
|
-
* Create Astro handler with configurable redirect URLs
|
|
222
|
-
*
|
|
223
|
-
* Wraps the unified handler with redirect URL configuration
|
|
224
|
-
*
|
|
225
|
-
* @param baseHandler - Handler function from createMCPServer
|
|
226
|
-
* @param options - Redirect URL configuration
|
|
227
|
-
* @returns Wrapped handler function for Astro
|
|
228
|
-
*
|
|
229
|
-
* @example
|
|
230
|
-
* ```typescript
|
|
231
|
-
* // lib/integrate-server.ts
|
|
232
|
-
* import { createMCPServer, githubPlugin } from 'integrate-sdk/server';
|
|
233
|
-
*
|
|
234
|
-
* export const { client: serverClient } = createMCPServer({
|
|
235
|
-
* plugins: [
|
|
236
|
-
* githubPlugin({
|
|
237
|
-
* clientId: import.meta.env.GITHUB_CLIENT_ID!,
|
|
238
|
-
* clientSecret: import.meta.env.GITHUB_CLIENT_SECRET!,
|
|
239
|
-
* }),
|
|
240
|
-
* ],
|
|
241
|
-
* });
|
|
242
|
-
*
|
|
243
|
-
* // pages/api/integrate/[...all].ts
|
|
244
|
-
* import { toAstroHandler } from 'integrate-sdk/server';
|
|
245
|
-
* import { serverClient } from '@/lib/integrate-server';
|
|
246
|
-
*
|
|
247
|
-
* export const ALL = toAstroHandler(serverClient.handler, {
|
|
248
|
-
* redirectUrl: '/dashboard',
|
|
249
|
-
* errorRedirectUrl: '/auth-error',
|
|
250
|
-
* });
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
253
|
-
export declare function toAstroHandler(baseHandler: (request: Request, context?: {
|
|
254
|
-
params?: {
|
|
255
|
-
action?: string;
|
|
256
|
-
all?: string | string[];
|
|
257
|
-
};
|
|
258
|
-
}) => Promise<Response>, options?: {
|
|
259
|
-
/** URL to redirect to after successful OAuth callback (default: '/') */
|
|
260
|
-
redirectUrl?: string;
|
|
261
|
-
/** URL to redirect to on OAuth error (default: '/auth-error') */
|
|
262
|
-
errorRedirectUrl?: string;
|
|
263
|
-
}): (ctx: {
|
|
264
|
-
request: Request;
|
|
265
|
-
params: {
|
|
266
|
-
all?: string | string[];
|
|
267
|
-
};
|
|
268
|
-
}) => Promise<Response>;
|
|
269
224
|
/**
|
|
270
225
|
* Create SolidStart handler with configurable redirect URLs
|
|
271
226
|
*
|
package/dist/src/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AA8CpD
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AA8CpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,wBAAgB,eAAe,CAAC,QAAQ,SAAS,SAAS,SAAS,EAAE,EACnE,MAAM,EAAE,eAAe,CAAC,QAAQ,CAAC;IA+R/B,gFAAgF;;IAGhF,4DAA4D;;;;;;;;IAG5D,2DAA2D;;;;;;;;EAG9D;AAYD,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpD,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE9E;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,IAAI,GACf,KAAK,GAAG,EACR,SAAS;IAAE,MAAM,EAAE;QAAE,MAAM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