Skip to content

Commit 7ee41cf

Browse files
Merge pull request #4 from vectorize-io/finalGdriveChanges
Final Gdrive changes
2 parents 1ff5feb + 66b0f59 commit 7ee41cf

File tree

7 files changed

+158
-43
lines changed

7 files changed

+158
-43
lines changed

README.md

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,84 @@
1-
# test-vectorize-connect-sdk
1+
# test-vectorize-connect-sdk
2+
3+
A Next.js demonstration project showcasing the functionality of the [@vectorize-io/vectorize-connect](https://www.npmjs.com/package/@vectorize-io/vectorize-connect) package.
4+
5+
## Overview
6+
7+
This repository provides a practical implementation of the Vectorize Connect SDK, allowing developers to quickly understand how to integrate and utilize the package's features in a Next.js environment.
8+
9+
## Features
10+
11+
- Integration examples with the Vectorize Connect SDK
12+
- Interactive UI components for testing SDK functionality
13+
- Google Drive connectivity demonstration
14+
15+
16+
## Prerequisites
17+
18+
- Node.js
19+
- npm or yarn
20+
- A Vectorize account and API token
21+
22+
## Environment Setup
23+
24+
To fully test the features of this demonstration, you'll need to set up the following environment variables:
25+
26+
```
27+
VECTORIZE_TOKEN=your_vectorize_token
28+
VECTORIZE_ORG=your_vectorize_org_id
29+
```
30+
31+
### Google Drive Features
32+
33+
To test the Google Drive integration features, the above environment variables are required.
34+
35+
Additionally, if you wish to try the white label connector functionality, you'll need to set these Google-specific variables:
36+
37+
```
38+
GOOGLE_OAUTH_CLIENT_ID=your_google_oauth_client_id
39+
GOOGLE_OAUTH_CLIENT_SECRET=your_google_oauth_client_secret
40+
GOOGLE_API_KEY=your_google_api_key
41+
```
42+
43+
## Installation
44+
45+
1. Clone the repository:
46+
```bash
47+
git clone https://github.com/yourusername/test-vectorize-connect-sdk.git
48+
cd test-vectorize-connect-sdk
49+
```
50+
51+
2. Install dependencies:
52+
```bash
53+
npm install
54+
# or
55+
yarn install
56+
```
57+
58+
3. Create a `.env.local` file in the root directory and add your environment variables.
59+
60+
4. Start the development server:
61+
```bash
62+
npm run dev
63+
# or
64+
yarn dev
65+
```
66+
67+
5. Open your browser and navigate to `http://localhost:3000`
68+
69+
## Usage
70+
71+
The demo application provides a user interface to test various features of the Vectorize Connect SDK. You can:
72+
73+
- Test Google Drive integrations
74+
- Try out white label connector functionality
75+
- Explore SDK methods and responses
76+
77+
78+
## License
79+
80+
[MIT](LICENSE)
81+
82+
## Support
83+
84+
For questions or support with the Vectorize Connect SDK, please refer to the [official documentation](https://docs.vectorize.io) or reach out to the Vectorize support team.

package-lock.json

Lines changed: 4 additions & 4 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.3",
14+
"@vectorize-io/vectorize-connect": "^0.2.4",
1515
"next": "15.2.3",
1616
"react": "^18.2.0",
1717
"react-dom": "^18.2.0"

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {manageGDriveUser, VectorizeAPIConfig} from '@vectorize-io/vectorize-conn
55

66
// Base URL for API endpoints
77
const BASE_URL = process.env.VECTORIZE_API_URL;
8-
const API_PATH = '/api';
8+
const API_PATH = process.env.VECTORIZE_API_PATH;
99

1010
const ALLOWED_ORIGINS = [BASE_URL, 'https://api.vectorize.io/v1'].filter(Boolean);
1111
// Adjust this array for all the origins you want to allow
@@ -92,6 +92,14 @@ export async function POST(request: NextRequest) {
9292
// Determine platformUrl - pass undefined if BASE_URL is not set
9393
const platformUrl = BASE_URL ? `${BASE_URL}${API_PATH}` : undefined;
9494

95+
console.log("Received request to add Google Drive user:", {
96+
selectionData,
97+
connectorId,
98+
userId,
99+
platformUrl,
100+
config
101+
});
102+
95103
// Call the manageGDriveUser function from @vectorize-io/vectorize-connect
96104
const response = await manageGDriveUser(
97105
config,

src/app/api/get_One_Time_Vectorize_Connector_Token/route.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,20 @@ import { NextRequest, NextResponse } from "next/server";
99
* - Calls the Vectorize API to get a one-time token
1010
* - Returns the token response to the client
1111
*/
12-
export async function POST(request: NextRequest) {
12+
export async function GET(request: NextRequest) {
1313
try {
1414
// Get authentication details from environment variables or secure storage
1515
const apiKey = process.env.VECTORIZE_TOKEN;
1616
const organizationId = process.env.VECTORIZE_ORG;
17-
18-
const Base_URL = process.env.VECTORIZE_API_URL
19-
const API_Path = process.env.VECTORIZE_API_PATH
2017

21-
22-
if (!apiKey || !organizationId || !Base_URL || !API_Path) {
18+
if (!apiKey || !organizationId) {
2319
return NextResponse.json({
2420
error: 'Missing Vectorize API configuration'
2521
}, { status: 500 });
2622
}
23+
24+
const Base_URL = process.env.VECTORIZE_API_URL
25+
const API_Path = process.env.VECTORIZE_API_PATH
2726

2827
// Configure the Vectorize API client
2928
const config: VectorizeAPIConfig = {
@@ -43,16 +42,23 @@ export async function POST(request: NextRequest) {
4342
}, { status: 400 });
4443
}
4544

46-
console.log("getting one time connector token for userId:", userId, "and connectorId:", connectorId);
45+
46+
47+
console.log("getting one time connector token for userId:", userId, "and connectorId:", connectorId, "with URL" , `${Base_URL}${API_Path}`);
48+
49+
// Determine platformUrl - pass undefined if BASE_URL is not set
50+
const platformUrl = Base_URL ? `${Base_URL}${API_Path}` : undefined;
4751

4852
// Call Vectorize API to get the token
4953
const tokenResponse = await getOneTimeConnectorToken(
5054
config,
5155
userId,
5256
connectorId,
53-
`${Base_URL}${API_Path}`,
57+
platformUrl,
5458
);
5559

60+
console.log("Token response:", tokenResponse);
61+
5662
// Return the token to the client
5763
return NextResponse.json(tokenResponse, { status: 200 });
5864

src/app/api/google-callback/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function GET(request: NextRequest) {
2020
clientId: process.env.GOOGLE_OAUTH_CLIENT_ID!,
2121
clientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET!,
2222
apiKey: process.env.GOOGLE_API_KEY!,
23-
redirectUri: "http://localhost:3001" + CALLBACK_PATH,
23+
redirectUri: "http://localhost:3000" + CALLBACK_PATH,
2424
};
2525

2626
try {

src/app/googleDrive/page.tsx

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,40 +116,58 @@ export default function Home() {
116116
}
117117
};
118118

119-
// Handle the redirect to Google Drive connect for Non-White Label
120-
const handleNonWhiteLabelConnectGoogleDrive = async () => {
121-
setIsLoading(true);
122-
setError(null);
123-
setSuccessMessage(null);
124-
setAddedUserId(null);
125-
126-
try {
127-
const config = await fetch("/api/getVectorizeConfig")
119+
120+
// Handle the redirect to Google Drive connect for Non-White Label
121+
const handleNonWhiteLabelConnectGoogleDrive = async () => {
122+
setIsLoading(true);
123+
setError(null);
124+
setSuccessMessage(null);
125+
setAddedUserId(null);
126+
127+
try {
128+
// Get Vectorize configuration
129+
const config = await fetch("/api/getVectorizeConfig")
128130
.then(response => response.json())
129131
.then(data => {
130132
return {
131133
organizationId: data.organizationId,
132134
authorization: data.authorization
133135
}
134136
});
135-
136-
// Only set platformUrl if BASE_URL exists
137-
const platformUrl = BASE_URL? BASE_URL : undefined;
138-
139-
// Call the redirect function (opens in a new tab)
140-
await redirectToVectorizeGoogleDriveConnect(
141-
`/api/get_One_Time_Vectorize_Connector_Token?userId=${"newNonWhiteLabelUser" + Math.floor(Math.random() * 1000)}&connectorId=${nonWhiteLabelConnectorId!}`, // Random username for demo purposes
142-
config.organizationId,
143-
platformUrl,
144-
);
145-
} catch (err) {
146-
const errorMessage = err instanceof Error ? err.message : 'Failed to connect to Google Drive';
147-
setError(errorMessage);
148-
console.error('Google Drive connection error:', err);
149-
} finally {
150-
setIsLoading(false);
137+
138+
// Generate random user ID for demo purposes
139+
const userId = "newNonWhiteLabelUser" + Math.floor(Math.random() * 1000);
140+
141+
// Get one-time token from API
142+
const tokenResponse = await fetch(`/api/get_One_Time_Vectorize_Connector_Token?userId=${userId}&connectorId=${nonWhiteLabelConnectorId!}`)
143+
.then(response => {
144+
if (!response.ok) {
145+
throw new Error(`Failed to generate one-time token. Status: ${response.status}`);
146+
}
147+
return response.json();
148+
});
149+
150+
if (!tokenResponse || !tokenResponse.token) {
151+
throw new Error('Failed to generate one-time token');
151152
}
152-
};
153+
154+
// Only set platformUrl if redirect_URI exists
155+
const platformUrl = redirect_URI ? redirect_URI : undefined;
156+
157+
// Call the redirect function with the obtained token
158+
await redirectToVectorizeGoogleDriveConnect(
159+
tokenResponse.token,
160+
config.organizationId,
161+
platformUrl
162+
);
163+
} catch (err) {
164+
const errorMessage = err instanceof Error ? err.message : 'Failed to connect to Google Drive';
165+
setError(errorMessage);
166+
console.error('Google Drive connection error:', err);
167+
} finally {
168+
setIsLoading(false);
169+
}
170+
};
153171

154172
// Handle the redirect to Google Drive connect for White Label
155173
const handleWhiteLabelConnectGoogleDrive = async () => {
@@ -170,7 +188,7 @@ export default function Home() {
170188
});
171189

172190
// Set to your redirectUri
173-
const redirectUri = "http://localhost:3001" + CALLBACK_PATH;
191+
const redirectUri = "http://localhost:3000" + CALLBACK_PATH;
174192

175193
const config = {
176194
clientId: clientId,

0 commit comments

Comments
 (0)