Github Repo

You can reference this example repo with our Javascript SDK implemented.

Installation


Use the package manager npm to install carbon-connect-js.

npm install carbon-connect-js

Usage


You can employ the generateAccessToken() function to create an access token, which enables user authentication across various methods in the SDK.

The access token will be valid for 10 hours.

import * as Carbon from 'carbon-connect-js';

// Note: Access token generation should happen prior to other function calls!

// Generate Access Token
const accessTokenResponse = await Carbon.generateAccessToken(
  'api_key',
  'customer_id'
);
console.log(accessTokenResponse.data.access_token);

// Get White Label data
const whiteLabelResponse = Carbon.getWhiteLabelData('ACCESS_TOKEN');
console.log(whiteLabelResponse.data);

Enabling Connectors


You can initialize user authentication and file selection flows for connectors using the generateOauthurl method.

Pass in access token generated via the generateAccessToken() method to generate an OAuth URL for a specific connectors (ie: integrationName: GOOGLE_DRIVE).

 import * as Carbon from 'carbon-connect-js';

 async function generateIntegrationOAuthURL() {
   try {
     const response = await Carbon.generateOauthurl({
       accessToken: 'YOUR_ACCESS_TOKEN',
       integrationName: 'CONNECTOR_NAME',
       // Accepted values are: NOTION, GOOGLE_DRIVE, ONEDRIVE, INTERCOM,
       // DROPBOX, ZENDESK, BOX, CONFLUENCE, SHAREPOINT, ZOTERO, RSS, GMAIL
     });

     if (response.status === 200) {
       console.log('Generated OAuth URL:', response.data.oauth_url);
     } else {
       console.error('Error:', response.error);
     }
   } catch (err) {
     console.error('Unexpected error:', err.message);
   }
 }

 generateIntegrationOAuthURL();

Carbon autonomously manages the state of each user’s connections.

If the user hasn’t authenticated their account, the OAuth URL directs them to the authentication flow.

If the user has already authenticated their account, the OAuth URL navigates them to the file selection flow.

Custom Types


Types that are used in the helper methods provided by the SDK.

TextEmbeddingModel
OPENAI
AZURE_OPENAI
COHERE_MULTILINGUAL_V3
OPENAI_ADA_SMALL_512
OPENAI_ADA_SMALL_1536
OPENAI_ADA_LARGE_256
OPENAI_ADA_LARGE_1024
OPENAI_ADA_LARGE_3072
EmbeddingModel
OPENAI
AZURE_OPENAI
COHERE_MULTILINGUAL_V3
VERTEX_MULTIMODAL
OPENAI_ADA_SMALL_512
OPENAI_ADA_SMALL_1536
OPENAI_ADA_LARGE_256
OPENAI_ADA_LARGE_1024
OPENAI_ADA_LARGE_3072

Methods


Health

Authentication

Connectors

Files

Websites

Retrieval