Skip to content

Commit 83413ac

Browse files
authored
Merge pull request #5 from vectorize-io/dropBoxOAuth
Drop box OAuth
2 parents 7ee41cf + 1a783ea commit 83413ac

File tree

15 files changed

+1902
-366
lines changed

15 files changed

+1902
-366
lines changed

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@types/react": "^18.2.0",
1313
"@types/react-dom": "^18.2.0",
14-
"@vectorize-io/vectorize-connect": "^0.2.4",
14+
"@vectorize-io/vectorize-connect": "^0.3.1",
1515
"next": "15.2.3",
1616
"react": "^18.2.0",
1717
"react-dom": "^18.2.0"

public/GDrive.png

16.1 KB
Loading

public/dropbox-wbg.png

20.2 KB
Loading

src/app/api/add-google-drive-user/[connectorId]/route.ts

Lines changed: 0 additions & 150 deletions
This file was deleted.

src/app/api/createGDriveConnector/route.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// /api/createSourceConnector/route.ts
2+
3+
import { NextResponse } from "next/server";
4+
import {
5+
createVectorizeGDriveConnector,
6+
createWhiteLabelGDriveConnector,
7+
createVectorizeDropboxConnector,
8+
createWhiteLabelDropboxConnector,
9+
VectorizeAPIConfig
10+
} from "@vectorize-io/vectorize-connect";
11+
12+
/**
13+
* Creates a new connector with the provided configuration based on connectorType
14+
* @param request - The incoming HTTP request containing connector configuration
15+
* @returns JSON response with the created connector ID or error message
16+
*/
17+
export async function POST(request: Request) {
18+
try {
19+
// 1. Parse the incoming request
20+
const {
21+
connectorType,
22+
connectorName,
23+
platformUrl,
24+
clientId,
25+
clientSecret,
26+
appKey,
27+
appSecret
28+
} = await request.json();
29+
30+
// 2. Gather environment variables for your Vectorize config
31+
const config: VectorizeAPIConfig = {
32+
organizationId: process.env.VECTORIZE_ORG ?? "",
33+
authorization: process.env.VECTORIZE_TOKEN ?? "",
34+
};
35+
36+
// Optionally, validate environment variables before proceeding
37+
if (!config.organizationId) {
38+
return NextResponse.json(
39+
{ error: "Missing VECTORIZE_ORG in environment" },
40+
{ status: 500 }
41+
);
42+
}
43+
if (!config.authorization) {
44+
return NextResponse.json(
45+
{ error: "Missing VECTORIZE_TOKEN in environment" },
46+
{ status: 500 }
47+
);
48+
}
49+
50+
console.log("Received request to create connector:", {
51+
connectorType,
52+
connectorName,
53+
platformUrl,
54+
});
55+
56+
// Use provided platformUrl or pass undefined to use the default from vectorize-connect
57+
const apiPlatformUrl = platformUrl;
58+
59+
// 3. Call the appropriate function based on connector type
60+
let connectorId: string;
61+
62+
if (connectorType === "GDriveWhiteLabel") {
63+
// Validate required parameters for white label connector
64+
if (!clientId || !clientSecret) {
65+
return NextResponse.json(
66+
{ error: "Client ID and Client Secret are required for white label connectors" },
67+
{ status: 400 }
68+
);
69+
}
70+
71+
connectorId = await createWhiteLabelGDriveConnector(
72+
config,
73+
connectorName,
74+
clientId,
75+
clientSecret,
76+
apiPlatformUrl
77+
);
78+
} else if (connectorType === "GDriveVectorize") {
79+
connectorId = await createVectorizeGDriveConnector(
80+
config,
81+
connectorName,
82+
apiPlatformUrl
83+
);
84+
} else if (connectorType === "DropboxWhiteLabel") {
85+
// Validate required parameters for white label Dropbox connector
86+
if (!appKey || !appSecret) {
87+
return NextResponse.json(
88+
{ error: "App Key and App Secret are required for white label Dropbox connectors" },
89+
{ status: 400 }
90+
);
91+
}
92+
93+
connectorId = await createWhiteLabelDropboxConnector(
94+
config,
95+
connectorName,
96+
appKey,
97+
appSecret,
98+
apiPlatformUrl
99+
);
100+
} else if (connectorType === "DropboxVectorize") {
101+
connectorId = await createVectorizeDropboxConnector(
102+
config,
103+
connectorName,
104+
apiPlatformUrl
105+
);
106+
} else {
107+
return NextResponse.json(
108+
{ error: "Invalid connector type. Must be one of: 'GDriveWhiteLabel', 'GDriveVectorize', 'DropboxWhiteLabel', 'DropboxVectorize'" },
109+
{ status: 400 }
110+
);
111+
}
112+
113+
console.log("Connector created successfully:", connectorId);
114+
115+
return NextResponse.json(connectorId, { status: 200 });
116+
} catch (error: any) {
117+
// 4. Error handling
118+
console.error("Error creating connector:", error);
119+
return NextResponse.json({ error: error.message || "Unexpected error" }, { status: 500 });
120+
}
121+
}

0 commit comments

Comments
 (0)