integrate-sdk 0.3.7 → 0.3.8
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 +40 -0
- package/dist/server.js +15 -0
- package/dist/src/adapters/nextjs-oauth-redirect.d.ts +34 -0
- package/dist/src/adapters/nextjs-oauth-redirect.d.ts.map +1 -0
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/oauth/types.d.ts +0 -9
- package/dist/src/oauth/types.d.ts.map +1 -1
- package/dist/src/oauth/window-manager.d.ts +1 -1
- package/dist/src/oauth/window-manager.d.ts.map +1 -1
- package/package.json +3 -15
- package/dist/src/adapters/nextjs-callback.d.ts +0 -44
- package/dist/src/adapters/nextjs-callback.d.ts.map +0 -1
- package/src/adapters/auto-routes.ts +0 -217
- package/src/adapters/base-handler.ts +0 -212
- package/src/adapters/nextjs-callback.tsx +0 -160
- package/src/adapters/nextjs.ts +0 -318
- package/src/adapters/tanstack-start.ts +0 -264
- package/src/client.ts +0 -952
- package/src/config/types.ts +0 -180
- package/src/errors.ts +0 -207
- package/src/index.ts +0 -110
- package/src/integrations/vercel-ai.ts +0 -104
- package/src/oauth/manager.ts +0 -307
- package/src/oauth/pkce.ts +0 -127
- package/src/oauth/types.ts +0 -101
- package/src/oauth/window-manager.ts +0 -322
- package/src/plugins/generic.ts +0 -119
- package/src/plugins/github-client.ts +0 -345
- package/src/plugins/github.ts +0 -122
- package/src/plugins/gmail-client.ts +0 -114
- package/src/plugins/gmail.ts +0 -108
- package/src/plugins/server-client.ts +0 -20
- package/src/plugins/types.ts +0 -89
- package/src/protocol/jsonrpc.ts +0 -88
- package/src/protocol/messages.ts +0 -145
- package/src/server.ts +0 -117
- package/src/transport/http-session.ts +0 -322
- package/src/transport/http-stream.ts +0 -331
- package/src/utils/naming.ts +0 -52
package/dist/index.js
CHANGED
|
@@ -699,6 +699,21 @@ class OAuthWindowManager {
|
|
|
699
699
|
let state = params.get("state");
|
|
700
700
|
let error = params.get("error");
|
|
701
701
|
let errorDescription = params.get("error_description");
|
|
702
|
+
if (!code && !error && window.location.hash) {
|
|
703
|
+
try {
|
|
704
|
+
const hash = window.location.hash.substring(1);
|
|
705
|
+
const hashParams = new URLSearchParams(hash);
|
|
706
|
+
const oauthCallback = hashParams.get("oauth_callback");
|
|
707
|
+
if (oauthCallback) {
|
|
708
|
+
const parsed = JSON.parse(decodeURIComponent(oauthCallback));
|
|
709
|
+
code = parsed.code;
|
|
710
|
+
state = parsed.state;
|
|
711
|
+
window.history.replaceState(null, "", window.location.pathname + window.location.search);
|
|
712
|
+
}
|
|
713
|
+
} catch (e) {
|
|
714
|
+
console.error("Failed to parse OAuth callback params from hash:", e);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
702
717
|
if (!code && !error) {
|
|
703
718
|
try {
|
|
704
719
|
const stored = sessionStorage.getItem("oauth_callback_params");
|
|
@@ -1356,6 +1371,30 @@ async function clearClientCache() {
|
|
|
1356
1371
|
// src/index.ts
|
|
1357
1372
|
init_nextjs();
|
|
1358
1373
|
|
|
1374
|
+
// src/adapters/nextjs-oauth-redirect.ts
|
|
1375
|
+
function createOAuthRedirectHandler(config) {
|
|
1376
|
+
const redirectUrl = config?.redirectUrl || "/";
|
|
1377
|
+
const errorRedirectUrl = config?.errorRedirectUrl || "/auth-error";
|
|
1378
|
+
return async function GET(req) {
|
|
1379
|
+
const { searchParams } = new URL(req.url);
|
|
1380
|
+
const code = searchParams.get("code");
|
|
1381
|
+
const state = searchParams.get("state");
|
|
1382
|
+
const error = searchParams.get("error");
|
|
1383
|
+
const errorDescription = searchParams.get("error_description");
|
|
1384
|
+
if (error) {
|
|
1385
|
+
const errorMsg = errorDescription || error;
|
|
1386
|
+
console.error("[OAuth Redirect] Error:", errorMsg);
|
|
1387
|
+
return Response.redirect(new URL(`${errorRedirectUrl}?error=${encodeURIComponent(errorMsg)}`, req.url));
|
|
1388
|
+
}
|
|
1389
|
+
if (!code || !state) {
|
|
1390
|
+
console.error("[OAuth Redirect] Missing code or state parameter");
|
|
1391
|
+
return Response.redirect(new URL(`${errorRedirectUrl}?error=${encodeURIComponent("Invalid OAuth callback")}`, req.url));
|
|
1392
|
+
}
|
|
1393
|
+
const targetUrl = new URL(redirectUrl, req.url);
|
|
1394
|
+
targetUrl.hash = `oauth_callback=${encodeURIComponent(JSON.stringify({ code, state }))}`;
|
|
1395
|
+
return Response.redirect(targetUrl);
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1359
1398
|
// src/adapters/tanstack-start.ts
|
|
1360
1399
|
function createTanStackOAuthHandler(config) {
|
|
1361
1400
|
const handler = new OAuthHandler(config);
|
|
@@ -1590,6 +1629,7 @@ export {
|
|
|
1590
1629
|
generateCodeChallenge,
|
|
1591
1630
|
createTanStackOAuthHandler,
|
|
1592
1631
|
createSimplePlugin,
|
|
1632
|
+
createOAuthRedirectHandler,
|
|
1593
1633
|
createNextOAuthHandler,
|
|
1594
1634
|
createMCPClient,
|
|
1595
1635
|
convertMCPToolsToVercelAI,
|
package/dist/server.js
CHANGED
|
@@ -699,6 +699,21 @@ class OAuthWindowManager {
|
|
|
699
699
|
let state = params.get("state");
|
|
700
700
|
let error = params.get("error");
|
|
701
701
|
let errorDescription = params.get("error_description");
|
|
702
|
+
if (!code && !error && window.location.hash) {
|
|
703
|
+
try {
|
|
704
|
+
const hash = window.location.hash.substring(1);
|
|
705
|
+
const hashParams = new URLSearchParams(hash);
|
|
706
|
+
const oauthCallback = hashParams.get("oauth_callback");
|
|
707
|
+
if (oauthCallback) {
|
|
708
|
+
const parsed = JSON.parse(decodeURIComponent(oauthCallback));
|
|
709
|
+
code = parsed.code;
|
|
710
|
+
state = parsed.state;
|
|
711
|
+
window.history.replaceState(null, "", window.location.pathname + window.location.search);
|
|
712
|
+
}
|
|
713
|
+
} catch (e) {
|
|
714
|
+
console.error("Failed to parse OAuth callback params from hash:", e);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
702
717
|
if (!code && !error) {
|
|
703
718
|
try {
|
|
704
719
|
const stored = sessionStorage.getItem("oauth_callback_params");
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js OAuth Redirect Handler
|
|
3
|
+
* Handles OAuth callback redirects and forwards parameters to the client
|
|
4
|
+
*/
|
|
5
|
+
type NextRequest = any;
|
|
6
|
+
type NextResponse = any;
|
|
7
|
+
export interface OAuthRedirectConfig {
|
|
8
|
+
/** URL to redirect to after OAuth callback (default: '/') */
|
|
9
|
+
redirectUrl?: string;
|
|
10
|
+
/** URL to redirect to on OAuth error (default: '/auth-error') */
|
|
11
|
+
errorRedirectUrl?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create OAuth redirect handler for Next.js
|
|
15
|
+
*
|
|
16
|
+
* This handler processes OAuth callbacks from providers and redirects
|
|
17
|
+
* to your application with the OAuth parameters encoded in the URL.
|
|
18
|
+
*
|
|
19
|
+
* @param config - Redirect configuration
|
|
20
|
+
* @returns Next.js route handler
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* // app/oauth/callback/route.ts
|
|
25
|
+
* import { createOAuthRedirectHandler } from 'integrate-sdk';
|
|
26
|
+
*
|
|
27
|
+
* export const GET = createOAuthRedirectHandler({
|
|
28
|
+
* redirectUrl: '/dashboard',
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare function createOAuthRedirectHandler(config?: OAuthRedirectConfig): (req: NextRequest) => Promise<NextResponse>;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=nextjs-oauth-redirect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nextjs-oauth-redirect.d.ts","sourceRoot":"","sources":["../../../src/adapters/nextjs-oauth-redirect.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,KAAK,WAAW,GAAG,GAAG,CAAC;AACvB,KAAK,YAAY,GAAG,GAAG,CAAC;AAExB,MAAM,WAAW,mBAAmB;IAClC,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,CAAC,EAAE,mBAAmB,IAI3C,KAAK,WAAW,KAAG,OAAO,CAAC,YAAY,CAAC,CAkCnE"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -7,10 +7,12 @@ export type { ToolInvocationOptions } from "./client.js";
|
|
|
7
7
|
export { OAuthManager } from "./oauth/manager.js";
|
|
8
8
|
export { OAuthWindowManager, sendCallbackToOpener } from "./oauth/window-manager.js";
|
|
9
9
|
export { generateCodeVerifier, generateCodeChallenge, generateState } from "./oauth/pkce.js";
|
|
10
|
-
export type { OAuthFlowConfig, PopupOptions, AuthStatus, PendingAuth, AuthorizationUrlResponse, OAuthCallbackResponse, OAuthCallbackParams,
|
|
10
|
+
export type { OAuthFlowConfig, PopupOptions, AuthStatus, PendingAuth, AuthorizationUrlResponse, OAuthCallbackResponse, OAuthCallbackParams, } from "./oauth/types.js";
|
|
11
11
|
export { OAuthHandler } from "./adapters/base-handler.js";
|
|
12
12
|
export type { OAuthHandlerConfig, AuthorizeRequest, AuthorizeResponse, CallbackRequest, CallbackResponse, StatusResponse, } from "./adapters/base-handler.js";
|
|
13
13
|
export { createNextOAuthHandler } from "./adapters/nextjs.js";
|
|
14
|
+
export { createOAuthRedirectHandler } from "./adapters/nextjs-oauth-redirect.js";
|
|
15
|
+
export type { OAuthRedirectConfig } from "./adapters/nextjs-oauth-redirect.js";
|
|
14
16
|
export { createTanStackOAuthHandler } from "./adapters/tanstack-start.js";
|
|
15
17
|
export type { MCPClientConfig, ReauthContext, ReauthHandler } from "./config/types.js";
|
|
16
18
|
export { IntegrateSDKError, AuthenticationError, AuthorizationError, TokenExpiredError, ConnectionError, ToolCallError, isAuthError, isTokenExpiredError, isAuthorizationError, parseServerError, } from "./errors.js";
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3E,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7F,YAAY,EACV,eAAe,EACf,YAAY,EACZ,UAAU,EACV,WAAW,EACX,wBAAwB,EACxB,qBAAqB,EACrB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC3E,YAAY,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGzD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7F,YAAY,EACV,eAAe,EACf,YAAY,EACZ,UAAU,EACV,WAAW,EACX,wBAAwB,EACxB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,YAAY,EACV,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ACV,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,EACnB,OAAO,EACP,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,YAAY,EACV,cAAc,EACd,2BAA2B,GAC5B,MAAM,6BAA6B,CAAC"}
|
|
@@ -81,13 +81,4 @@ export interface OAuthCallbackParams {
|
|
|
81
81
|
/** State parameter for CSRF protection */
|
|
82
82
|
state: string;
|
|
83
83
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Configuration for OAuth callback route handler
|
|
86
|
-
*/
|
|
87
|
-
export interface OAuthCallbackHandlerConfig {
|
|
88
|
-
/** URL to redirect to after successful OAuth (default: '/') */
|
|
89
|
-
redirectUrl?: string;
|
|
90
|
-
/** URL to redirect to on OAuth error (default: '/auth-error') */
|
|
91
|
-
errorRedirectUrl?: string;
|
|
92
|
-
}
|
|
93
84
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/oauth/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6CAA6C;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IAC3B,oDAAoD;IACpD,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,sDAAsD;IACtD,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAA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IAClC,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,KAAK,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -64,7 +64,7 @@ export declare class OAuthWindowManager {
|
|
|
64
64
|
*/
|
|
65
65
|
private listenForPopupCallback;
|
|
66
66
|
/**
|
|
67
|
-
* Parse callback parameters from current URL or sessionStorage (for redirect flow)
|
|
67
|
+
* Parse callback parameters from current URL, hash, or sessionStorage (for redirect flow)
|
|
68
68
|
*/
|
|
69
69
|
private listenForRedirectCallback;
|
|
70
70
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"window-manager.d.ts","sourceRoot":"","sources":["../../../src/oauth/window-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AASpE;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,kBAAkB,CAA+C;IACzE,OAAO,CAAC,iBAAiB,CAA8C;IAEvE;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI;IAwC7D;;;;;;;;;;OAUG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAQ/B;;;;;;;;;;;;;;;;;OAiBG;IACH,iBAAiB,CACf,IAAI,EAAE,OAAO,GAAG,UAAU,EAC1B,SAAS,GAAE,MAAsB,GAChC,OAAO,CAAC,mBAAmB,CAAC;IAQ/B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAkE9B;;OAEG;IACH,OAAO,CAAC,yBAAyB;
|
|
1
|
+
{"version":3,"file":"window-manager.d.ts","sourceRoot":"","sources":["../../../src/oauth/window-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AASpE;;;;;;GAMG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,kBAAkB,CAA+C;IACzE,OAAO,CAAC,iBAAiB,CAA8C;IAEvE;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI;IAwC7D;;;;;;;;;;OAUG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAQ/B;;;;;;;;;;;;;;;;;OAiBG;IACH,iBAAiB,CACf,IAAI,EAAE,OAAO,GAAG,UAAU,EAC1B,SAAS,GAAE,MAAsB,GAChC,OAAO,CAAC,mBAAmB,CAAC;IAQ/B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAkE9B;;OAEG;IACH,OAAO,CAAC,yBAAyB;IAiEjC;;OAEG;IACH,OAAO,CAAC,OAAO;IAiBf;;;OAGG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,GAAG,IAAI,CAwBP"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "integrate-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.8",
|
|
4
4
|
"description": "Type-safe TypeScript SDK for MCP Client with plugin-based OAuth provider configuration",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,21 +26,16 @@
|
|
|
26
26
|
"./oauth": {
|
|
27
27
|
"import": "./dist/oauth.js",
|
|
28
28
|
"types": "./dist/oauth.d.ts"
|
|
29
|
-
},
|
|
30
|
-
"./oauth-callback": {
|
|
31
|
-
"import": "./src/adapters/nextjs-callback.tsx",
|
|
32
|
-
"types": "./dist/adapters/nextjs-callback.d.ts"
|
|
33
29
|
}
|
|
34
30
|
},
|
|
35
31
|
"files": [
|
|
36
32
|
"dist",
|
|
37
|
-
"src",
|
|
38
33
|
"index.ts",
|
|
39
34
|
"server.ts",
|
|
40
35
|
"oauth.ts"
|
|
41
36
|
],
|
|
42
37
|
"scripts": {
|
|
43
|
-
"build": "bun build index.ts server.ts oauth.ts --outdir dist --target node --format esm
|
|
38
|
+
"build": "bun build index.ts server.ts oauth.ts --outdir dist --target node --format esm && bun run build:types",
|
|
44
39
|
"build:types": "tsc --emitDeclarationOnly --declaration --declarationMap",
|
|
45
40
|
"dev": "bun --watch src/index.ts",
|
|
46
41
|
"type-check": "tsc --noEmit",
|
|
@@ -63,18 +58,11 @@
|
|
|
63
58
|
"license": "MIT",
|
|
64
59
|
"devDependencies": {
|
|
65
60
|
"@types/bun": "latest",
|
|
66
|
-
"@types/react": "^18.0.0",
|
|
67
61
|
"simple-git-hooks": "^2.13.1",
|
|
68
62
|
"typescript": "^5.3.3"
|
|
69
63
|
},
|
|
70
64
|
"peerDependencies": {
|
|
71
|
-
"typescript": ">=5.0.0"
|
|
72
|
-
"react": ">=18.0.0"
|
|
73
|
-
},
|
|
74
|
-
"peerDependenciesMeta": {
|
|
75
|
-
"react": {
|
|
76
|
-
"optional": true
|
|
77
|
-
}
|
|
65
|
+
"typescript": ">=5.0.0"
|
|
78
66
|
},
|
|
79
67
|
"simple-git-hooks": {
|
|
80
68
|
"pre-commit": "./scripts/check-version.sh"
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Next.js OAuth Callback Handler
|
|
3
|
-
* Provides a pre-built OAuth callback page component for Next.js App Router
|
|
4
|
-
*
|
|
5
|
-
* This eliminates the need for users to manually create callback pages.
|
|
6
|
-
*/
|
|
7
|
-
import type { OAuthCallbackHandlerConfig } from '../oauth/types.js';
|
|
8
|
-
/**
|
|
9
|
-
* OAuth Callback Page Component
|
|
10
|
-
*
|
|
11
|
-
* This component:
|
|
12
|
-
* 1. Extracts OAuth callback parameters (code, state, error) from URL
|
|
13
|
-
* 2. Sends them to the opener window (for popup mode) via postMessage
|
|
14
|
-
* 3. Stores them in sessionStorage (for redirect mode)
|
|
15
|
-
* 4. Redirects to the configured URL
|
|
16
|
-
*
|
|
17
|
-
* @param config - Callback handler configuration
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```tsx
|
|
21
|
-
* // app/oauth/callback/page.tsx
|
|
22
|
-
* import { OAuthCallbackPage } from 'integrate-sdk/oauth-callback';
|
|
23
|
-
*
|
|
24
|
-
* export default function CallbackPage() {
|
|
25
|
-
* return <OAuthCallbackPage redirectUrl="/dashboard" />;
|
|
26
|
-
* }
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
export declare function OAuthCallbackPage(config?: OAuthCallbackHandlerConfig): import("react/jsx-runtime").JSX.Element;
|
|
30
|
-
/**
|
|
31
|
-
* Create a default export wrapper for easier usage
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```tsx
|
|
35
|
-
* // app/oauth/callback/page.tsx
|
|
36
|
-
* import { createOAuthCallbackPage } from 'integrate-sdk/oauth-callback';
|
|
37
|
-
*
|
|
38
|
-
* export default createOAuthCallbackPage({
|
|
39
|
-
* redirectUrl: '/dashboard',
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare function createOAuthCallbackPage(config?: OAuthCallbackHandlerConfig): () => import("react/jsx-runtime").JSX.Element;
|
|
44
|
-
//# sourceMappingURL=nextjs-callback.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nextjs-callback.d.ts","sourceRoot":"","sources":["../../../src/adapters/nextjs-callback.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAEpE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,0BAA0B,2CA2GpE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,CAAC,EAAE,0BAA0B,iDAI1E"}
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Auto-generated OAuth Routes
|
|
3
|
-
* Automatically creates the correct route handlers based on framework detection
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { OAuthHandler, type OAuthHandlerConfig } from './base-handler.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Global OAuth configuration
|
|
10
|
-
* Set by createMCPClient when oauthConfig is provided
|
|
11
|
-
*/
|
|
12
|
-
let globalOAuthConfig: OAuthHandlerConfig | null = null;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Set the global OAuth configuration
|
|
16
|
-
* Called internally by createMCPClient
|
|
17
|
-
*/
|
|
18
|
-
export function setGlobalOAuthConfig(config: OAuthHandlerConfig): void {
|
|
19
|
-
globalOAuthConfig = config;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Get the global OAuth configuration
|
|
24
|
-
*/
|
|
25
|
-
export function getGlobalOAuthConfig(): OAuthHandlerConfig | null {
|
|
26
|
-
return globalOAuthConfig;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Universal OAuth route handler
|
|
31
|
-
* Automatically detects framework and handles all OAuth actions
|
|
32
|
-
*
|
|
33
|
-
* This is the magic function that makes everything "just work"
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* // app/api/integrate/oauth/[action]/route.ts (Next.js)
|
|
38
|
-
* export * from 'integrate-sdk/oauth';
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```typescript
|
|
43
|
-
* // app/routes/api/integrate/oauth/[action].ts (TanStack Start)
|
|
44
|
-
* export * from 'integrate-sdk/oauth';
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
// Framework detection helpers (unused but kept for future enhancements)
|
|
49
|
-
// function isNextJS(request: any): boolean {
|
|
50
|
-
// return (
|
|
51
|
-
// request?.constructor?.name === 'NextRequest' ||
|
|
52
|
-
// typeof request?.nextUrl !== 'undefined' ||
|
|
53
|
-
// typeof (globalThis as any).NextResponse !== 'undefined'
|
|
54
|
-
// );
|
|
55
|
-
// }
|
|
56
|
-
|
|
57
|
-
// function isTanStackStart(request: any): boolean {
|
|
58
|
-
// return (
|
|
59
|
-
// request instanceof Request &&
|
|
60
|
-
// !isNextJS(request)
|
|
61
|
-
// );
|
|
62
|
-
// }
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Universal POST handler
|
|
66
|
-
* Handles authorize and callback actions
|
|
67
|
-
*/
|
|
68
|
-
export async function POST(
|
|
69
|
-
req: any,
|
|
70
|
-
context?: { params: { action: string } }
|
|
71
|
-
): Promise<any> {
|
|
72
|
-
if (!globalOAuthConfig) {
|
|
73
|
-
throw new Error(
|
|
74
|
-
'OAuth configuration not found. Did you configure oauthProviders in createMCPClient?'
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const handler = new OAuthHandler(globalOAuthConfig);
|
|
79
|
-
const action = context?.params?.action;
|
|
80
|
-
|
|
81
|
-
if (!action) {
|
|
82
|
-
return createErrorResponse('Missing action parameter', 400);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
try {
|
|
86
|
-
if (action === 'authorize') {
|
|
87
|
-
const body = await parseRequestBody(req);
|
|
88
|
-
const result = await handler.handleAuthorize(body);
|
|
89
|
-
return createSuccessResponse(result);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (action === 'callback') {
|
|
93
|
-
const body = await parseRequestBody(req);
|
|
94
|
-
const result = await handler.handleCallback(body);
|
|
95
|
-
return createSuccessResponse(result);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return createErrorResponse(`Unknown action: ${action}`, 404);
|
|
99
|
-
} catch (error: any) {
|
|
100
|
-
console.error(`[OAuth ${action}] Error:`, error);
|
|
101
|
-
return createErrorResponse(error.message, 500);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Universal GET handler
|
|
107
|
-
* Handles status action
|
|
108
|
-
*/
|
|
109
|
-
export async function GET(
|
|
110
|
-
req: any,
|
|
111
|
-
context?: { params: { action: string } }
|
|
112
|
-
): Promise<any> {
|
|
113
|
-
if (!globalOAuthConfig) {
|
|
114
|
-
throw new Error(
|
|
115
|
-
'OAuth configuration not found. Did you configure oauthProviders in createMCPClient?'
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const handler = new OAuthHandler(globalOAuthConfig);
|
|
120
|
-
const action = context?.params?.action;
|
|
121
|
-
|
|
122
|
-
if (!action) {
|
|
123
|
-
return createErrorResponse('Missing action parameter', 400);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
try {
|
|
127
|
-
if (action === 'status') {
|
|
128
|
-
const { provider, sessionToken } = parseQueryParams(req);
|
|
129
|
-
|
|
130
|
-
if (!provider || !sessionToken) {
|
|
131
|
-
return createErrorResponse(
|
|
132
|
-
'Missing provider or session token',
|
|
133
|
-
400
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const result = await handler.handleStatus(provider, sessionToken);
|
|
138
|
-
return createSuccessResponse(result);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return createErrorResponse(`Unknown action: ${action}`, 404);
|
|
142
|
-
} catch (error: any) {
|
|
143
|
-
console.error(`[OAuth ${action}] Error:`, error);
|
|
144
|
-
return createErrorResponse(error.message, 500);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Parse request body (works for both Next.js and standard Request)
|
|
150
|
-
*/
|
|
151
|
-
async function parseRequestBody(req: any): Promise<any> {
|
|
152
|
-
if (typeof req.json === 'function') {
|
|
153
|
-
return await req.json();
|
|
154
|
-
}
|
|
155
|
-
throw new Error('Unable to parse request body');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Parse query parameters (works for both Next.js and standard Request)
|
|
160
|
-
*/
|
|
161
|
-
function parseQueryParams(req: any): { provider?: string; sessionToken?: string } {
|
|
162
|
-
let url: URL;
|
|
163
|
-
|
|
164
|
-
// Next.js
|
|
165
|
-
if (req.nextUrl) {
|
|
166
|
-
url = new URL(req.nextUrl);
|
|
167
|
-
}
|
|
168
|
-
// Standard Request
|
|
169
|
-
else if (req.url) {
|
|
170
|
-
url = new URL(req.url);
|
|
171
|
-
} else {
|
|
172
|
-
return {};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const provider = url.searchParams.get('provider') || undefined;
|
|
176
|
-
const sessionToken = req.headers?.get?.('x-session-token') || undefined;
|
|
177
|
-
|
|
178
|
-
return { provider, sessionToken };
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Create success response (works for both frameworks)
|
|
183
|
-
*/
|
|
184
|
-
function createSuccessResponse(data: any): any {
|
|
185
|
-
// Try Next.js first
|
|
186
|
-
if (typeof (globalThis as any).NextResponse !== 'undefined') {
|
|
187
|
-
const NextResponse = (globalThis as any).NextResponse;
|
|
188
|
-
return NextResponse.json(data);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// Fallback to standard Response
|
|
192
|
-
return new Response(JSON.stringify(data), {
|
|
193
|
-
status: 200,
|
|
194
|
-
headers: { 'Content-Type': 'application/json' },
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Create error response (works for both frameworks)
|
|
200
|
-
*/
|
|
201
|
-
function createErrorResponse(message: string, status: number): any {
|
|
202
|
-
// Try Next.js first
|
|
203
|
-
if (typeof (globalThis as any).NextResponse !== 'undefined') {
|
|
204
|
-
const NextResponse = (globalThis as any).NextResponse;
|
|
205
|
-
return NextResponse.json({ error: message }, { status });
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Fallback to standard Response
|
|
209
|
-
return new Response(
|
|
210
|
-
JSON.stringify({ error: message }),
|
|
211
|
-
{
|
|
212
|
-
status,
|
|
213
|
-
headers: { 'Content-Type': 'application/json' },
|
|
214
|
-
}
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
|