@@ -16,7 +16,11 @@ Create a file at `app/api/createConnector/route.ts`:
1616``` typescript
1717// app/api/createConnector/route.ts
1818import { NextResponse } from " next/server" ;
19- import { createVectorizeConnector } from " @vectorize-io/vectorize-connect" ;
19+ import {
20+ createVectorizeGDriveConnector ,
21+ createVectorizeDropboxConnector ,
22+ createSourceConnector
23+ } from " @vectorize-io/vectorize-connect" ;
2024
2125interface VectorizeAPIConfig {
2226 organizationId: string ;
@@ -42,12 +46,29 @@ export async function POST(request: Request) {
4246 );
4347 }
4448
45- // Create the connector (Vectorize managed)
46- const connectorId = await createVectorizeConnector (
47- config ,
48- connectorName ,
49- platformType
50- );
49+ // Create the connector based on platform type
50+ let connectorId: string ;
51+
52+ switch (platformType ) {
53+ case " GOOGLE_DRIVE_OAUTH_MULTI" :
54+ connectorId = await createVectorizeGDriveConnector (config , connectorName );
55+ break ;
56+ case " DROPBOX_OAUTH_MULTI" :
57+ connectorId = await createVectorizeDropboxConnector (config , connectorName );
58+ break ;
59+ case " NOTION_OAUTH_MULTI" :
60+ connectorId = await createSourceConnector (config , {
61+ name: connectorName ,
62+ type: " NOTION_OAUTH_MULTI" ,
63+ config: {}
64+ });
65+ break ;
66+ default :
67+ return NextResponse .json (
68+ { error: ` Unsupported platform type: ${platformType } ` },
69+ { status: 400 }
70+ );
71+ }
5172
5273 return NextResponse .json ({ connectorId }, { status: 200 });
5374 } catch (error : any ) {
@@ -61,18 +82,17 @@ export async function POST(request: Request) {
6182### Google Drive Multi-User Connector
6283
6384``` typescript
64- import { createVectorizeConnector } from " @vectorize-io/vectorize-connect" ;
85+ import { createVectorizeGDriveConnector } from " @vectorize-io/vectorize-connect" ;
6586
6687const config = {
6788 organizationId: process .env .VECTORIZE_ORGANIZATION_ID ! ,
6889 authorization: process .env .VECTORIZE_API_KEY ! ,
6990};
7091
7192// Create Google Drive connector
72- const gdriveConnectorId = await createVectorizeConnector (
93+ const gdriveConnectorId = await createVectorizeGDriveConnector (
7394 config ,
74- " Team Google Drive" ,
75- " GOOGLE_DRIVE_OAUTH_MULTI"
95+ " Team Google Drive"
7696);
7797
7898console .log (' Google Drive connector created:' , gdriveConnectorId );
@@ -81,18 +101,17 @@ console.log('Google Drive connector created:', gdriveConnectorId);
81101### Dropbox Multi-User Connector
82102
83103``` typescript
84- import { createVectorizeConnector } from " @vectorize-io/vectorize-connect" ;
104+ import { createVectorizeDropboxConnector } from " @vectorize-io/vectorize-connect" ;
85105
86106const config = {
87107 organizationId: process .env .VECTORIZE_ORGANIZATION_ID ! ,
88108 authorization: process .env .VECTORIZE_API_KEY ! ,
89109};
90110
91111// Create Dropbox connector
92- const dropboxConnectorId = await createVectorizeConnector (
112+ const dropboxConnectorId = await createVectorizeDropboxConnector (
93113 config ,
94- " Team Dropbox Storage" ,
95- " DROPBOX_OAUTH_MULTI"
114+ " Team Dropbox Storage"
96115);
97116
98117console .log (' Dropbox connector created:' , dropboxConnectorId );
@@ -101,26 +120,29 @@ console.log('Dropbox connector created:', dropboxConnectorId);
101120### Notion Multi-User Connector
102121
103122``` typescript
104- import { createVectorizeConnector } from " @vectorize-io/vectorize-connect" ;
123+ import { createSourceConnector } from " @vectorize-io/vectorize-connect" ;
105124
106125const config = {
107126 organizationId: process .env .VECTORIZE_ORGANIZATION_ID ! ,
108127 authorization: process .env .VECTORIZE_API_KEY ! ,
109128};
110129
111130// Create Notion connector
112- const notionConnectorId = await createVectorizeConnector (
131+ const notionConnectorId = await createSourceConnector (
113132 config ,
114- " Team Notion Workspace" ,
115- " NOTION_OAUTH_MULTI"
133+ {
134+ name: " Team Notion Workspace" ,
135+ type: " NOTION_OAUTH_MULTI" ,
136+ config: {}
137+ }
116138);
117139
118140console .log (' Notion connector created:' , notionConnectorId );
119141```
120142
121143## Alternative: Using createSourceConnector
122144
123- For more control over connector configuration:
145+ For more control over connector configuration, you can use the generic ` createSourceConnector ` function for any platform :
124146
125147``` typescript
126148import { createSourceConnector } from ' @vectorize-io/vectorize-connect' ;
@@ -145,7 +167,7 @@ const dropboxConnectorId = await createSourceConnector(
145167 }
146168);
147169
148- // Notion with createSourceConnector
170+ // Notion with createSourceConnector (required for Notion)
149171const notionConnectorId = await createSourceConnector (
150172 config ,
151173 {
@@ -286,58 +308,137 @@ await handleCreateConnector("NOTION_OAUTH_MULTI", "Team Notion Workspace");
286308### Basic Error Handling
287309
288310``` typescript
311+ // Google Drive error handling
312+ try {
313+ const connectorId = await createVectorizeGDriveConnector (
314+ vectorizeConfig ,
315+ " Team Google Drive"
316+ );
317+ } catch (error ) {
318+ if (error .response ?.status === 401 ) {
319+ console .error (' Invalid Vectorize API token' );
320+ } else if (error .response ?.status === 403 ) {
321+ console .error (' Insufficient permissions or plan limitations' );
322+ } else {
323+ console .error (' Google Drive connector creation failed:' , error .message );
324+ }
325+ }
326+
327+ // Dropbox error handling
328+ try {
329+ const connectorId = await createVectorizeDropboxConnector (
330+ vectorizeConfig ,
331+ " Team Dropbox Storage"
332+ );
333+ } catch (error ) {
334+ if (error .response ?.status === 401 ) {
335+ console .error (' Invalid Vectorize API token' );
336+ } else if (error .response ?.status === 403 ) {
337+ console .error (' Insufficient permissions or plan limitations' );
338+ } else {
339+ console .error (' Dropbox connector creation failed:' , error .message );
340+ }
341+ }
342+
343+ // Notion error handling
289344try {
290- const connectorId = await createVectorizeConnector (
345+ const connectorId = await createSourceConnector (
291346 vectorizeConfig ,
292- " Team Google Drive" ,
293- " GOOGLE_DRIVE_OAUTH_MULTI"
347+ {
348+ name: " Team Notion Workspace" ,
349+ type: " NOTION_OAUTH_MULTI" ,
350+ config: {}
351+ }
294352 );
295353} catch (error ) {
296354 if (error .response ?.status === 401 ) {
297355 console .error (' Invalid Vectorize API token' );
298356 } else if (error .response ?.status === 403 ) {
299357 console .error (' Insufficient permissions or plan limitations' );
300358 } else {
301- console .error (' Connector creation failed:' , error .message );
359+ console .error (' Notion connector creation failed:' , error .message );
302360 }
303361}
304362```
305363
306364### Platform-Specific Error Handling
307365
308366``` typescript
309- const createConnectorWithErrorHandling = async (
310- platformType : string ,
311- connectorName : string
312- ) => {
367+ const createGoogleDriveConnector = async (connectorName : string ) => {
368+ try {
369+ const connectorId = await createVectorizeGDriveConnector (
370+ vectorizeConfig ,
371+ connectorName
372+ );
373+
374+ console .log (' Google Drive connector created successfully:' , connectorId );
375+ return connectorId ;
376+ } catch (error ) {
377+ if (error .response ?.status === 401 ) {
378+ throw new Error (' Invalid Vectorize API credentials for Google Drive' );
379+ } else if (error .response ?.status === 403 ) {
380+ throw new Error (' Insufficient permissions for Google Drive connector creation' );
381+ } else if (error .response ?.status === 400 ) {
382+ throw new Error (' Invalid configuration for Google Drive connector' );
383+ } else {
384+ throw new Error (` Failed to create Google Drive connector: ${error .message } ` );
385+ }
386+ }
387+ };
388+
389+ const createDropboxConnector = async (connectorName : string ) => {
390+ try {
391+ const connectorId = await createVectorizeDropboxConnector (
392+ vectorizeConfig ,
393+ connectorName
394+ );
395+
396+ console .log (' Dropbox connector created successfully:' , connectorId );
397+ return connectorId ;
398+ } catch (error ) {
399+ if (error .response ?.status === 401 ) {
400+ throw new Error (' Invalid Vectorize API credentials for Dropbox' );
401+ } else if (error .response ?.status === 403 ) {
402+ throw new Error (' Insufficient permissions for Dropbox connector creation' );
403+ } else if (error .response ?.status === 400 ) {
404+ throw new Error (' Invalid configuration for Dropbox connector' );
405+ } else {
406+ throw new Error (` Failed to create Dropbox connector: ${error .message } ` );
407+ }
408+ }
409+ };
410+
411+ const createNotionConnector = async (connectorName : string ) => {
313412 try {
314- const connectorId = await createVectorizeConnector (
413+ const connectorId = await createSourceConnector (
315414 vectorizeConfig ,
316- connectorName ,
317- platformType
415+ {
416+ name: connectorName ,
417+ type: " NOTION_OAUTH_MULTI" ,
418+ config: {}
419+ }
318420 );
319421
320- console .log (` ${ platformType } connector created successfully:` , connectorId );
422+ console .log (' Notion connector created successfully:' , connectorId );
321423 return connectorId ;
322424 } catch (error ) {
323- // Handle specific platform errors
324425 if (error .response ?.status === 401 ) {
325- throw new Error (` Invalid Vectorize API credentials for ${ platformType } ` );
426+ throw new Error (' Invalid Vectorize API credentials for Notion ' );
326427 } else if (error .response ?.status === 403 ) {
327- throw new Error (` Insufficient permissions for ${ platformType } connector creation ` );
428+ throw new Error (' Insufficient permissions for Notion connector creation' );
328429 } else if (error .response ?.status === 400 ) {
329- throw new Error (` Invalid configuration for ${ platformType } connector ` );
430+ throw new Error (' Invalid configuration for Notion connector' );
330431 } else {
331- throw new Error (` Failed to create ${ platformType } connector: ${error .message } ` );
432+ throw new Error (` Failed to create Notion connector: ${error .message } ` );
332433 }
333434 }
334435};
335436
336437// Usage with error handling
337438try {
338- await createConnectorWithErrorHandling ( " GOOGLE_DRIVE_OAUTH_MULTI " , " Team Google Drive" );
339- await createConnectorWithErrorHandling ( " DROPBOX_OAUTH_MULTI " , " Team Dropbox" );
340- await createConnectorWithErrorHandling ( " NOTION_OAUTH_MULTI " , " Team Notion" );
439+ await createGoogleDriveConnector ( " Team Google Drive" );
440+ await createDropboxConnector ( " Team Dropbox Storage " );
441+ await createNotionConnector ( " Team Notion Workspace " );
341442} catch (error ) {
342443 console .error (' Connector creation failed:' , error .message );
343444}
0 commit comments