integrate-sdk 0.5.8 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -1
- package/dist/index.js +1 -1
- package/dist/server.js +25 -16
- package/dist/src/config/types.d.ts +1 -1
- package/dist/src/server.d.ts +31 -2
- package/dist/src/server.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,6 +28,19 @@ bun add integrate-sdk
|
|
|
28
28
|
|
|
29
29
|
## Quick Start (2 Files Only!)
|
|
30
30
|
|
|
31
|
+
### 0. Configure OAuth Redirect URI
|
|
32
|
+
|
|
33
|
+
⚠️ **Important**: Configure your OAuth apps with this redirect URI:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
http://localhost:3000/api/integrate/oauth/callback
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- **GitHub**: Settings → Developer settings → OAuth Apps → Authorization callback URL
|
|
40
|
+
- **Google/Gmail**: Google Cloud Console → Credentials → Authorized redirect URIs
|
|
41
|
+
|
|
42
|
+
For production, use: `https://yourdomain.com/api/integrate/oauth/callback`
|
|
43
|
+
|
|
31
44
|
### 1. Create Server Config
|
|
32
45
|
|
|
33
46
|
Define your OAuth providers once:
|
|
@@ -62,14 +75,16 @@ That's it! Just import and export:
|
|
|
62
75
|
|
|
63
76
|
```typescript
|
|
64
77
|
// app/api/integrate/[...all]/route.ts
|
|
78
|
+
import { serverClient } from "@/lib/integrate-server";
|
|
65
79
|
import { toNextJsHandler } from "integrate-sdk/server";
|
|
66
80
|
|
|
67
81
|
export const { POST, GET } = toNextJsHandler({
|
|
82
|
+
client: serverClient, // Pass the client
|
|
68
83
|
redirectUrl: "/dashboard",
|
|
69
84
|
});
|
|
70
85
|
```
|
|
71
86
|
|
|
72
|
-
This
|
|
87
|
+
This imports your config from step 1 and handles ALL OAuth operations (authorize, callback, status, disconnect) in one file!
|
|
73
88
|
|
|
74
89
|
### 3. Use in Your App
|
|
75
90
|
|
package/dist/index.js
CHANGED
|
@@ -1063,7 +1063,7 @@ class MCPClient {
|
|
|
1063
1063
|
}
|
|
1064
1064
|
getDefaultRedirectUri(oauthApiBase) {
|
|
1065
1065
|
if (typeof window === "undefined" || !window.location) {
|
|
1066
|
-
return "http://localhost:3000/oauth/callback";
|
|
1066
|
+
return "http://localhost:3000/api/integrate/oauth/callback";
|
|
1067
1067
|
}
|
|
1068
1068
|
const origin = window.location.origin;
|
|
1069
1069
|
const normalizedPath = oauthApiBase.replace(/\/$/, "");
|
package/dist/server.js
CHANGED
|
@@ -1063,7 +1063,7 @@ class MCPClient {
|
|
|
1063
1063
|
}
|
|
1064
1064
|
getDefaultRedirectUri(oauthApiBase) {
|
|
1065
1065
|
if (typeof window === "undefined" || !window.location) {
|
|
1066
|
-
return "http://localhost:3000/oauth/callback";
|
|
1066
|
+
return "http://localhost:3000/api/integrate/oauth/callback";
|
|
1067
1067
|
}
|
|
1068
1068
|
const origin = window.location.origin;
|
|
1069
1069
|
const normalizedPath = oauthApiBase.replace(/\/$/, "");
|
|
@@ -1946,15 +1946,15 @@ function createSimplePlugin(config) {
|
|
|
1946
1946
|
var globalServerConfig = null;
|
|
1947
1947
|
function getDefaultRedirectUri() {
|
|
1948
1948
|
if (typeof window !== "undefined") {
|
|
1949
|
-
return `${window.location.origin}/oauth/callback`;
|
|
1949
|
+
return `${window.location.origin}/api/integrate/oauth/callback`;
|
|
1950
1950
|
}
|
|
1951
1951
|
if (process.env.INTEGRATE_URL) {
|
|
1952
|
-
return `${process.env.INTEGRATE_URL}/oauth/callback`;
|
|
1952
|
+
return `${process.env.INTEGRATE_URL}/api/integrate/oauth/callback`;
|
|
1953
1953
|
}
|
|
1954
1954
|
if (process.env.VERCEL_URL) {
|
|
1955
|
-
return `https://${process.env.VERCEL_URL}/oauth/callback`;
|
|
1955
|
+
return `https://${process.env.VERCEL_URL}/api/integrate/oauth/callback`;
|
|
1956
1956
|
}
|
|
1957
|
-
return "http://localhost:3000/oauth/callback";
|
|
1957
|
+
return "http://localhost:3000/api/integrate/oauth/callback";
|
|
1958
1958
|
}
|
|
1959
1959
|
function createMCPServer(config) {
|
|
1960
1960
|
if (typeof window !== "undefined") {
|
|
@@ -1992,6 +1992,7 @@ function createMCPServer(config) {
|
|
|
1992
1992
|
singleton: config.singleton ?? true
|
|
1993
1993
|
};
|
|
1994
1994
|
const client = new MCPClient(clientConfig);
|
|
1995
|
+
client.__oauthConfig = { providers };
|
|
1995
1996
|
const { POST, GET } = createOAuthRouteHandlers({ providers });
|
|
1996
1997
|
return {
|
|
1997
1998
|
client,
|
|
@@ -2019,21 +2020,29 @@ var GET = async (req, context) => {
|
|
|
2019
2020
|
const routes = handler.createRoutes();
|
|
2020
2021
|
return routes.GET(req, context);
|
|
2021
2022
|
};
|
|
2022
|
-
function toNextJsHandler(
|
|
2023
|
+
function toNextJsHandler(options) {
|
|
2023
2024
|
const POST2 = async (req, context) => {
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
const
|
|
2025
|
+
const config = options.config || options.client?.__oauthConfig;
|
|
2026
|
+
if (!config) {
|
|
2027
|
+
return Response.json({ error: 'OAuth not configured. You must pass either "client" (from createMCPServer) or "config" to toNextJsHandler().' }, { status: 500 });
|
|
2028
|
+
}
|
|
2029
|
+
const handler = createNextOAuthHandler(config);
|
|
2030
|
+
const routes = handler.toNextJsHandler({
|
|
2031
|
+
redirectUrl: options.redirectUrl,
|
|
2032
|
+
errorRedirectUrl: options.errorRedirectUrl
|
|
2033
|
+
});
|
|
2029
2034
|
return routes.POST(req, context);
|
|
2030
2035
|
};
|
|
2031
2036
|
const GET2 = async (req, context) => {
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
const
|
|
2037
|
+
const config = options.config || options.client?.__oauthConfig;
|
|
2038
|
+
if (!config) {
|
|
2039
|
+
return Response.json({ error: 'OAuth not configured. You must pass either "client" (from createMCPServer) or "config" to toNextJsHandler().' }, { status: 500 });
|
|
2040
|
+
}
|
|
2041
|
+
const handler = createNextOAuthHandler(config);
|
|
2042
|
+
const routes = handler.toNextJsHandler({
|
|
2043
|
+
redirectUrl: options.redirectUrl,
|
|
2044
|
+
errorRedirectUrl: options.errorRedirectUrl
|
|
2045
|
+
});
|
|
2037
2046
|
return routes.GET(req, context);
|
|
2038
2047
|
};
|
|
2039
2048
|
return { POST: POST2, GET: GET2 };
|
|
@@ -170,7 +170,7 @@ export interface MCPClientConfig<TPlugins extends readonly MCPPlugin[]> {
|
|
|
170
170
|
* **Server-side (createMCPServer):** If not provided, auto-detects from environment:
|
|
171
171
|
* - INTEGRATE_URL (primary)
|
|
172
172
|
* - VERCEL_URL
|
|
173
|
-
* - Falls back to 'http://localhost:3000/oauth/callback'
|
|
173
|
+
* - Falls back to 'http://localhost:3000/api/integrate/oauth/callback'
|
|
174
174
|
*
|
|
175
175
|
* **Client-side (createMCPClient):** If not provided, auto-detects from:
|
|
176
176
|
* - window.location.origin + oauthApiBase + '/callback'
|
package/dist/src/server.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ import type { MCPPlugin } from './plugins/types.js';
|
|
|
23
23
|
* export const { client: serverClient } = createMCPServer({
|
|
24
24
|
* redirectUri: process.env.INTEGRATE_URL
|
|
25
25
|
* ? `${process.env.INTEGRATE_URL}/oauth/callback`
|
|
26
|
-
* : 'http://localhost:3000/oauth/callback',
|
|
26
|
+
* : 'http://localhost:3000/api/integrate/oauth/callback',
|
|
27
27
|
* plugins: [
|
|
28
28
|
* githubPlugin({
|
|
29
29
|
* clientId: process.env.GITHUB_CLIENT_ID!,
|
|
@@ -146,15 +146,44 @@ export declare const GET: (req: any, context: {
|
|
|
146
146
|
* });
|
|
147
147
|
*
|
|
148
148
|
* // app/api/integrate/[...all]/route.ts
|
|
149
|
+
*
|
|
150
|
+
* // RECOMMENDED: Import serverClient from your server setup file
|
|
151
|
+
* import { serverClient } from '@/lib/integrate-server';
|
|
149
152
|
* import { toNextJsHandler } from 'integrate-sdk/server';
|
|
150
153
|
*
|
|
151
154
|
* export const { POST, GET } = toNextJsHandler({
|
|
155
|
+
* client: serverClient, // Pass the client from createMCPServer
|
|
156
|
+
* redirectUrl: '/dashboard',
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* // Alternative: Provide config inline
|
|
160
|
+
* export const { POST, GET } = toNextJsHandler({
|
|
161
|
+
* config: {
|
|
162
|
+
* providers: {
|
|
163
|
+
* github: {
|
|
164
|
+
* clientId: process.env.GITHUB_CLIENT_ID!,
|
|
165
|
+
* clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
166
|
+
* },
|
|
167
|
+
* },
|
|
168
|
+
* },
|
|
152
169
|
* redirectUrl: '/dashboard',
|
|
153
170
|
* });
|
|
154
171
|
* ```
|
|
155
172
|
*/
|
|
156
|
-
export declare function toNextJsHandler(
|
|
173
|
+
export declare function toNextJsHandler(options: {
|
|
174
|
+
/** Server client instance from createMCPServer (extracts config automatically) */
|
|
175
|
+
client?: any;
|
|
176
|
+
/** Custom OAuth handler config (provide inline) */
|
|
177
|
+
config?: {
|
|
178
|
+
providers: Record<string, {
|
|
179
|
+
clientId: string;
|
|
180
|
+
clientSecret: string;
|
|
181
|
+
redirectUri?: string;
|
|
182
|
+
}>;
|
|
183
|
+
};
|
|
184
|
+
/** URL to redirect to after successful OAuth */
|
|
157
185
|
redirectUrl?: string;
|
|
186
|
+
/** URL to redirect to on OAuth error */
|
|
158
187
|
errorRedirectUrl?: string;
|
|
159
188
|
}): {
|
|
160
189
|
POST: (req: any, context: {
|
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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