{"id":26886293,"url":"https://github.com/vectorize-io/vectorize-connect-sdk","last_synced_at":"2025-03-31T19:18:21.519Z","repository":{"id":282974741,"uuid":"931222093","full_name":"vectorize-io/vectorize-connect-sdk","owner":"vectorize-io","description":"Vectorize Connect SDK","archived":false,"fork":false,"pushed_at":"2025-03-25T00:34:29.000Z","size":158,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T01:27:26.071Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vectorize-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-11T23:08:55.000Z","updated_at":"2025-03-25T00:34:34.000Z","dependencies_parsed_at":"2025-03-18T00:24:19.795Z","dependency_job_id":"aa9e1a4f-62ba-403a-8674-cd6364b7c296","html_url":"https://github.com/vectorize-io/vectorize-connect-sdk","commit_stats":null,"previous_names":["vectorize-io/vectorize-connect-sdk"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vectorize-io%2Fvectorize-connect-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vectorize-io%2Fvectorize-connect-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vectorize-io%2Fvectorize-connect-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vectorize-io%2Fvectorize-connect-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vectorize-io","download_url":"https://codeload.github.com/vectorize-io/vectorize-connect-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246523840,"owners_count":20791444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-31T19:18:20.997Z","updated_at":"2025-03-31T19:18:21.503Z","avatar_url":"https://github.com/vectorize-io.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vectorize Connect SDK\n\nTypeScript/JavaScript SDK for connecting different platforms such as Google Drive to the Vectorize platform.\n\nThis is a lightweight client that provides functionality for Google Drive OAuth authentication and Vectorize API integration. The SDK helps you create connectors to Google Drive, let users select files, and manage those connections through the Vectorize platform.\n\n## SDK Installation\n\n### NPM\n```bash\nnpm install @vectorize-io/vectorize-connect\n```\n\n### Yarn\n```bash\nyarn add @vectorize-io/vectorize-connect\n```\n\n### pnpm\n```bash\nnpm add @vectorize-io/vectorize-connect\n```\n\n## Documentation\n\nFor detailed documentation, please refer to:\n\n- [General Guide](./docs/general-guide.md) - Overview and common concepts\n- [Google Drive Guide](./docs/google-drive-guide.md) - Google Drive specific integration\n- [API Reference](./docs/API.md) - Complete API documentation\n- [White Label Guide](./docs/white-label-guide.md) - White label integration\n- [Non-White Label Guide](./docs/non-white-label-guide.md) - Non-white label integration\n- [Setup Guide](./docs/setup.md) - Setup instructions\n\n## SDK Example Usage\n\n### Google Drive OAuth with White Label\n\n```typescript\nimport { startGDriveOAuth } from '@vectorize-io/vectorize-connect';\n\nconst handleOAuth = () =\u003e {\n  startGDriveOAuth({\n    clientId: 'YOUR_GOOGLE_OAUTH_CLIENT_ID',\n    clientSecret: 'YOUR_GOOGLE_OAUTH_CLIENT_SECRET',\n    apiKey: \"YOUR_GOOGLE_API_KEY\",\n    redirectUri: 'https://your-app.com/oauth/callback',\n    scopes: [\n      'https://www.googleapis.com/auth/drive.file'\n    ],\n    onSuccess: (response) =\u003e {\n      console.log('Selected files:', response.fileIds);\n      console.log('Refresh token:', response.refreshToken);\n    },\n    onError: (error) =\u003e {\n      console.error('Authentication failed:', error);\n    }\n  });\n};\n```\n\n## Server-Side OAuth Callback Handler for White Label  (Next.js)\n\n```typescript\n// pages/api/oauth/callback.js or app/api/oauth/callback/route.js\nimport { createGDrivePickerCallbackResponse } from '@vectorize-io/vectorize-connect';\n\nexport async function GET(req) {\n  const url = new URL(req.url);\n  const code = url.searchParams.get('code');\n  const error = url.searchParams.get('error');\n  \n  const config = {\n    clientId: process.env.GOOGLE_OAUTH_CLIENT_ID,\n    clientSecret: process.env.GOOGLE_OAUTH_CLIENT_SECRET,\n    redirectUri: `${process.env.BASE_URL}/api/oauth/callback`,\n    apiKey: process.env.GOOGLE_API_KEY\n  };\n  \n  const response = await createGDrivePickerCallbackResponse(\n    code,\n    config,\n    error\n  );\n  \n  // Return the response directly\n  return new Response(response.body, {\n    status: response.status,\n    headers: { 'Content-Type': 'text/html' }\n  });\n}\n```\n\n### Using Vectorize's Hosted OAuth\n\n```typescript\nimport { redirectToVectorizeGoogleDriveConnect, getOneTimeConnectorToken } from '@vectorize-io/vectorize-connect';\n\nconst connectToGoogleDrive = async () =\u003e {\n  try {\n    // Get one-time token from API endpoint\n    const tokenResponse = await fetch(`/api/get-one-time-connector-token?userId=user123\u0026connectorId=connector-id`)\n      .then(response =\u003e {\n        if (!response.ok) {\n          throw new Error(`Failed to generate token. Status: ${response.status}`);\n        }\n        return response.json();\n      });\n    \n    // Connect to Google Drive using Vectorize platform\n    await redirectToVectorizeGoogleDriveConnect(\n      tokenResponse.token,\n      'your-org-id',\n      'https://platform.vectorize.io' // Optional platform URL\n    );\n    \n    console.log('Connection process completed');\n  } catch (error) {\n    console.error('Connection process failed:', error);\n  }\n};\n```\n\n### File Selection with Existing Refresh Token\n\n```typescript\nimport { startGDriveFileSelection } from '@vectorize-io/vectorize-connect';\n\nconst selectFiles = async (refreshToken) =\u003e {\n  await startGDriveFileSelection({\n    clientId: 'YOUR_GOOGLE_OAUTH_CLIENT_ID',\n    clientSecret: 'YOUR_GOOGLE_OAUTH_CLIENT_SECRET',\n    apiKey: 'YOUR_GOOGLE_API_KEY',\n    onSuccess: (response) =\u003e {\n      console.log('Selected files:', response.fileIds);\n    },\n    onError: (error) =\u003e {\n      console.error('File selection failed:', error);\n    }\n  }, refreshToken);\n};\n```\n\n### Creating a Google Drive Connector\n\n```typescript\nimport { createGDriveSourceConnector } from '@vectorize-io/vectorize-connect';\n\nconst createConnector = async () =\u003e {\n  try {\n    // Standard connector using Vectorize's OAuth\n    const connectorId = await createGDriveSourceConnector(\n      {\n        organizationId: 'YOUR_VECTORIZE_ORG_ID',\n        authorization: 'YOUR_VECTORIZE_TOKEN'\n      },\n      false, // Use Vectorize's OAuth\n      'My Google Drive Connector' // Name of the new connector\n    );\n    \n    console.log('Created connector ID:', connectorId);\n    return connectorId;\n  } catch (error) {\n    console.error('Failed to create connector:', error);\n  }\n};\n\nconst createWhiteLabelConnector = async () =\u003e {\n  try {\n    // White label connector using your own OAuth credentials\n    const connectorId = await createGDriveSourceConnector(\n      {\n        organizationId: 'YOUR_VECTORIZE_ORG_ID',\n        authorization: 'YOUR_VECTORIZE_TOKEN'\n      },\n      true, // White label with your own OAuth\n      'My White Label Connector', // Name of the new connector\n      'https://api.vectorize.io/v1', // Default API URL\n      'YOUR_GOOGLE_OAUTH_CLIENT_ID',\n      'YOUR_GOOGLE_OAUTH_CLIENT_SECRET'\n    );\n    \n    console.log('Created white label connector ID:', connectorId);\n    return connectorId;\n  } catch (error) {\n    console.error('Failed to create white label connector:', error);\n  }\n};\n```\n\n### Managing Google Drive Users\n\nFunctions to manage Users in the vectorize connector:\n\n```typescript\nimport { manageGDriveUser } from '@vectorize-io/vectorize-connect';\n\n// Add a user's Google Drive files to a connector\nconst addUser = async (connectorId, fileIds, refreshToken, userId) =\u003e {\n  try {\n    await manageGDriveUser(\n      {\n        organizationId: 'YOUR_VECTORIZE_ORG_ID',\n        authorization: 'YOUR_VECTORIZE_TOKEN'\n      },\n      connectorId,\n      fileIds,\n      refreshToken,\n      userId,\n      'add' // Add a new user\n    );\n    \n    console.log('User added successfully');\n  } catch (error) {\n    console.error('Failed to add user:', error);\n  }\n};\n\n// Update a user's file selection\nconst updateUser = async (connectorId, fileIds, refreshToken, userId) =\u003e {\n  try {\n    await manageGDriveUser(\n      {\n        organizationId: 'YOUR_VECTORIZE_ORG_ID',\n        authorization: 'YOUR_VECTORIZE_TOKEN'\n      },\n      connectorId,\n      fileIds,\n      refreshToken,\n      userId,\n      'edit' // Update existing user\n    );\n    \n    console.log('User updated successfully');\n  } catch (error) {\n    console.error('Failed to update user:', error);\n  }\n};\n\n// Remove a user's access\nconst removeUser = async (connectorId, fileIds, refreshToken, userId) =\u003e {\n  try {\n    await manageGDriveUser(\n      {\n        organizationId: 'YOUR_VECTORIZE_ORG_ID',\n        authorization: 'YOUR_VECTORIZE_TOKEN'\n      },\n      connectorId,\n      fileIds,\n      refreshToken,\n      userId,\n      'remove' // Remove user\n    );\n    \n    console.log('User removed successfully');\n  } catch (error) {\n    console.error('Failed to remove user:', error);\n  }\n};\n```\n\n\n\n## Change the Base URL\n\nIf you need to connect to a different Vectorize API endpoint:\n\n```typescript\nimport { createGDriveSourceConnector } from '@vectorize-io/vectorize-connect';\n\nconst createConnector = async () =\u003e {\n  try {\n    const connectorId = await createGDriveSourceConnector(\n      {\n        organizationId: 'YOUR_VECTORIZE_ORG_ID'\n      },\n      false,\n      'My Connector',\n      'https://custom-api.vectorize.io/v1' // Custom API URL\n    );\n    \n    return connectorId;\n  } catch (error) {\n    console.error('Failed to create connector:', error);\n  }\n};\n```\n\n## API Reference\n\n### OAuth Functions\n\n#### `startGDriveOAuth(config: OAuthConfig): Window | null`\n\nInitiates the Google Drive OAuth flow in a popup window with file selection.\n\n#### `startGDriveFileSelection(config: OAuthConfig, refreshToken: string, targetWindow?: Window): Promise\u003cWindow | null\u003e`\n\nOpens a file picker using an existing refresh token, without repeating the OAuth flow.\n\n#### `createGDrivePickerCallbackResponse(code: string, config: OAuthConfig, error?: string | OAuthError): Promise\u003cResponse\u003e`\n\nCreates a response for the OAuth callback page to handle token exchange and file picking.\n\n#### `redirectToVectorizeGoogleDriveConnect(oneTimeToken: string, organizationId: string, platformUrl?: string): Promise\u003cvoid\u003e`\n\nRedirects to Vectorize's hosted Google Drive connection page in an iframe, which handles OAuth and file selection using a secure one-time token. Automatically adds the user to the specified connector ID without requiring a separate API route.\n\n#### `getOneTimeConnectorToken(config: VectorizeAPIConfig, userId: string, connectorId: string, platformUrl?: string): Promise\u003c{ token: string; expires_at: number; ttl: number }\u003e`\n\nGets a one-time authentication token for connector operations. This token is used for secure authentication when redirecting users to the Vectorize platform.\n\n### Vectorize API Functions\n\n#### `createGDriveSourceConnector(config: VectorizeAPIConfig, whiteLabel: boolean, connectorName: string, platformUrl?: string, clientId?: string, clientSecret?: string): Promise\u003cstring\u003e`\n\nCreates a Google Drive connector in Vectorize, returning the connector ID.\n\n#### `manageGDriveUser(config: VectorizeAPIConfig, connectorId: string, fileIds: string[], refreshToken: string, userId: string, action: \"add\" | \"edit\" | \"remove\", platformUrl?: string): Promise\u003cResponse\u003e`\n\nAdds, updates, or removes a user's Google Drive files from a Vectorize connector.\n\n## Configuration Types\n\n### `OAuthConfig`\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `clientId` | `string` | Your Google OAuth client ID |\n| `clientSecret` | `string` | Your Google OAuth client secret (server-side only) |\n| `redirectUri` | `string` | URI where Google will redirect after authentication |\n| `apiKey` | `string` | Google API key for using the Picker API |\n| `scopes` | `string[]` | Google OAuth scopes to request |\n| `onSuccess` | `(response: OAuthResponse) =\u003e void` | Success callback function |\n| `onError` | `(error: OAuthError) =\u003e void` | Error callback function |\n\n### `VectorizeAPIConfig`\n\n| Property | Type | Description |\n|----------|------|-------------|\n| `organizationId` | `string` | Your Vectorize organization ID |\n| `authorization` | `string` | Your Vectorize API key (optional) |\n\n## Requirements\n\n- This SDK is compatible with Node.js environments and modern browsers\n- TypeScript 4.7+ for type definitions\n- Next.js 14.0.0+ for server components (optional)\n\n## Summary\n\nThe Vectorize Connect SDK provides:\n\n- Google Drive OAuth authentication\n- File selection functionality\n- Token management for Google Drive API\n- Vectorize API integration for Google Drive connectors\n- User management capabilities\n\n## Detailed Documentation\n\nFor more detailed documentation, please refer to the following guides:\n\n- [API Reference](./docs/API.md)\n- [White-label Integration Guide](./docs/white-label-guide.md)\n- [Non-white-label Integration Guide](./docs/non-white-label-guide.md)\n- [TypeScript Definitions](./docs/types.md)\n- [Setup Guide](./docs/setup.md)\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvectorize-io%2Fvectorize-connect-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvectorize-io%2Fvectorize-connect-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvectorize-io%2Fvectorize-connect-sdk/lists"}