2.0.0 • Published 2 days ago

carbon-connect v2.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 days ago

Carbon Connect

Carbon Connect is a React component designed for managing integrations with a variety of data sources.

Installation

To install Carbon Connect, use npm as follows:

npm install carbon-connect-react

Prerequisites

The package expects the following npm packages to be installed in your project:

  1. @radix-ui/react-dialog
  2. react
  3. react-dom
  4. react-drag-drop-files
  5. react-icons
  6. react-toastify
  7. tailwindcss

Please check for the versions from package.json if you encounter a version mismatch error.

Component Properties

The CarbonConnect component accepts the following properties:

PropertyTypeRequired?Description
brandIconStringYesA URL or a local path to your organization's brand icon.
orgNameStringYesThe name of your organization. This is displayed in the initial announcement modal view.
tokenFetcherFunctionYesA function that returns a promise which resolves with the access and refresh tokens.
onSuccessFunctionNoA callback function that will be called after the file upload is successful.
onErrorFunctionNoA callback function that will be called if there is any error in the file upload.
childrenReact Node(JSX)NoYou can pass any valid React node that will be used as a trigger to open the component.
entryPointStringNoThe initial active step when the component loads. Default entry point is 'LOCAL_FILES'. More integrations are upcoming.
maxFileSizeNumberNoMaximum file size in bytes that is allowed to be uploaded. Defaults to 10 MB
tagsObjectNoAny additional data you want to associate with the component's state, such as an app ID.
enabledIntegrationsdictNoLet's you choose which 3rd party integrations to show. See below for more details about this prop
primaryBackgroundColorStringNoThe primary background color of the component. Defaults to #000000.
primaryTextColorStringNoThe primary text color of the component. Defaults to #FFFFFF.
secondaryBackgroundColorStringNoThe secondary background color of the component. Defaults to #FFFFFF.
secondaryTextColorStringNoThe secondary text color of the component. Defaults to #000000.
allowMultipleFilesBooleanNoWhether or not to allow multiple files to be uploaded at once. Defaults to false.
chunkSizeNumberNoThe no.of tokens per chunk. Defaults to 1500.
overlapSizeNumberNoThe no.of tokens to overlap between chunks. Defaults to 20.
openBooleanNoWhether or not to open the component. Defaults to false.
setOpenFunctionNoA function that will be called to set the open state of the component. Defaults to None.
tosURLStringNoA URL to your organization's terms of service. Defaults to https://carbon.ai/terms.
privacyPolicyURLStringNoA URL to your organization's privacy policy. Defaults to https://carbon.ai/privacy.
navigateBackURLStringNoA URL to your intended destination. Defaults to None.

When u do not pass open or setOpen, CC will manage the open state internally. If you pass open and setOpen, you will have to manage the open state yourself.

Note about Google Docs

Our oAuth app is in approval phase. your users will see a warning message when they try to connect their Google account. Please ignore the warning and proceed to connect your account. We will update this section once our app is approved.

Usage

This section demonstrates how to integrate the CarbonConnect component within a Next.js project.

Client Side Configuration

  1. Import necessary libraries and components:
import { CarbonConnect } from 'carbon-connect-react';
import axios from 'axios';
  1. Token Retrieval: Set up the tokenFetcher function. It's designed to request authentication tokens from your backend:
const tokenFetcher = async () => {
  const response = await axios.get('/api/auth/fetchCarbonTokens', {
    params: { customer_id: 'your_customer_id' },
  });
  return response.data; // Must return data containing access_token
};
  1. Implement CarbonConnect Component: Here's a concise usage example. Customize according to your requirements:
<CarbonConnect
  orgName="Your Organization"
  brandIcon="path/to/your/brand/icon"
  tokenFetcher={tokenFetcher}
  tags={{
    tag1: 'tag1_value',
    tag2: 'tag2_value',
    tag3: 'tag3_value',
  }}
  maxFileSize={10000000}
  enabledIntegrations={[
    {
      id: 'LOCAL_FILES',
      chunkSize: 100,
      overlapSize: 10,
      maxFileSize: 20000000,
      allowMultipleFiles: true,
      maxFilesCount: 5,
      allowedFileTypes: [
        {
          extension: 'csv',
          chunkSize: 1200,
          overlapSize: 120,
        },
        {
          extension: 'txt',
          chunkSize: 1599,
          overlapSize: 210,
        },
        {
          extension: 'pdf',
        },
      ],
    },
    {
      id: 'NOTION',
      chunkSize: 1500,
      overlapSize: 20,
    },
    {
      id: 'WEB_SCRAPER',
      chunkSize: 1500,
      overlapSize: 20,
    },
    {
      id: 'GOOGLE_DRIVE',
      chunkSize: 1000,
      overlapSize: 20,
    },
  ]}
  onSuccess={(data) => console.log('Data on Success: ', data)}
  onError={(error) => console.log('Data on Error: ', error)}
  primaryBackgroundColor="#F2F2F2"
  primaryTextColor="#555555"
  secondaryBackgroundColor="#f2f2f2"
  secondaryTextColor="#000000"
  allowMultipleFiles={true}
  open={true}
  chunkSize={1500}
  overlapSize={20}
  // entryPoint="LOCAL_FILES"
></CarbonConnect>

Server Side Configuration

Your backend should handle token requests like this:

const response = await axios.get('https://api.carbon.ai/auth/v1/access_token', {
  headers: {
    'Content-Type': 'application/json',
    'customer-id': '<YOUR_USER_UNIQUE_IDENTIFIER>',
    authorization: 'Bearer <YOUR_API_KEY>',
  },
});
if (response.status === 200 && response.data) {
  res.status(200).json(response.data);
}

Return Value Expectation:

Ensure that your tokenFetcher returns an object structured as:

{
  access_token: string;
}

Enabling integrations

Another important prop is enabledIntegrations. This prop lets you choose which integrations to show in the component. You can also pass additional configuration for each integration. We have provided an example in the above code snippet. Here is the list of all the integrations that you can enable:

  1. LOCAL_FILES: This integration lets you upload files from your local machine. You can pass the following configuration for this integration:

    • chunkSize: This is the no.of tokens per chunk. Defaults to 1500.
    • overlapSize: This is the size of the overlap in tokens. Defaults to 20.
    • maxFileSize: This is the maximum file size in bytes that is allowed to be uploaded. Defaults to 10 MB.
    • allowMultipleFiles: Whether or not to allow multiple files to be uploaded at once. Defaults to false.
    • maxFilesCount: This is the maximum no.of files that can be uploaded at once. Defaults to 10.
    • skipEmbeddingGeneration: Whether or not to skip embeddings generation. Defaults to false.
    • allowedFileTypes: This is an array of objects. Each object represents a file type that is allowed to be uploaded. Each object can have the following properties:
      • extension: The file extension of the file type. This is a required property.
      • chunkSize: This is the no.of tokens per chunk. Defaults to 1500.
      • overlapSize: This is the size of the overlap in tokens. Defaults to 20.
      • skipEmbeddingGeneration: Whether or not to skip embeddings generation. Defaults to false.
  2. NOTION: This integration lets you upload files from your notion account. You can pass the following configuration for this integration

    • chunkSize: This is the no.of tokens per chunk. Defaults to 1500.
    • overlapSize: This is the size of the overlap in tokens. Defaults to 20.
    • skipEmbeddingGeneration: Whether or not to skip embeddings generation. Defaults to false.
  3. WEB_SCRAPER: This integration lets you scrape URLs. You can pass the following configuration for this integration:

    • chunkSize: This is the no.of tokens per chunk. Defaults to 1500.
    • overlapSize: This is the size of the overlap in tokens. Defaults to 20.
    • skipEmbeddingGeneration: Whether or not to skip embeddings generation. Defaults to false.
  4. GOOGLE_DRIVE: This integration lets you upload files from your Google Docs. You can pass the following configuration for this integration:

    • chunkSize: This is the no.of tokens per chunk. Defaults to 1500.
    • overlapSize: This is the size of the overlap in tokens. Defaults to 20.
    • skipEmbeddingGeneration: Whether or not to skip embeddings generation. Defaults to false.
  5. INTERCOM: This integration lets you select pages from your Intercom. You can pass the following configuration for this integration:

    • chunkSize: This is the no.of tokens per chunk. Defaults to 1500.
    • overlapSize: This is the size of the overlap in tokens. Defaults to 20.
    • skipEmbeddingGeneration: Whether or not to skip embeddings generation. Defaults to false.
  6. DROPBOX: This integration lets you upload files from your Dropbox. You can pass the following configuration for this integration:

    • chunkSize: This is the no.of tokens per chunk. Defaults to 1500.
    • overlapSize: This is the size of the overlap in tokens. Defaults to 20.
    • skipEmbeddingGeneration: Whether or not to skip embeddings generation. Defaults to false.
  7. ONEDRIVE: This integration lets you upload files from your Onedrive. You can pass the following configuration for this integration:

    • chunkSize: This is the no.of tokens per chunk. Defaults to 1500.
    • overlapSize: This is the size of the overlap in tokens. Defaults to 20.
    • skipEmbeddingGeneration: Whether or not to skip embeddings generation. Defaults to false.

Callback function props

  1. onSuccess: You can let CC trigger a callback function upon successful file upload, 3rd party account connection and file selection, Webscraping request initiation. This function will pass data in the following format:
{
  status: 200,
  data: [Object 1, Object 2, ...] or null,
  action: <ACTION_TYPE>, // `ACTION_TYPE` can be one of the following: `INITIATE`, `ADD`, `UPDATE`, `CANCEL`
  event: <EVENT_TYPE>, // `EVENT_TYPE` can be one of the following: `INITIATE`, `ADD`, `UPDATE`, `CANCEL`
  integration: <INTEGRATION_NAME>, // `INTEGRATION_NAME` can be one of the following: `LOCAL_FILES`, `NOTION`, `WEB_SCRAPER`, `GOOGLE_DRIVE`, `INTERCOM`, `DROPBOX`, `ONEDRIVE`
}
  1. onError: CC will also call another call back method if there is an error while uploading file. This function will pass data in the following format:
{
  status: 400,
  action: 'UPDATE',
  event: 'UPDATE',
  integration: `<INTEGRATION_NAME>`, // 'LOCAL_FILES' or 'WEB_SCRAPER',
  data: `<data_object>`, // This field will be present only if the error is related to a file or web scraper
}

`onSuccess Event Types

  1. INITIATE: This event type is triggered when a user enters the integration flow (either for auth or file selection)
  2. ADD: This event type is triggered when a user authenticates an account under an integration.
  3. UPDATE: This event type is triggered when a user adds or removes files for an integration. We’ll list the files added or removed.
  4. CANCEL: This event type is triggered when when a user exits the integration flow without taking any action.

Data format for onSuccess callback

The data field will contain the following information:

  1. For LOCAL_FILES: An array of objects in the following format
{
    id: <File_ID>,
    name: <Name of the file>,
    source: <File Type in case of a local file>,
    external_file_id: <External File ID>,
    tags: <Tags passed in while uploading the file>,
    sync_status: <Sync status>,
  }
  1. For WEB_SCRAPER: An array containing only one object in the following format
{
  urls: `<Array of user inputed URLs>`,
  validUrls: `<Array of valid URLs>`,
  tags: `<Tags passed in to the CC>`,
}
  1. For 3rd party integrations: An array containing only one object in the following format
{
  data_source_external_id: `<Email address of the Notion account>`,
  sync_status: `<Sync status>`,
  data: `<Array of objects corresponding to the files / pages selected>`,
}

Each file object will be in the following format:

{
    "id": `Unique ID for the file, can be used for resyncing, deleting, updating tags etc.`,
    "source": `<integration_name>`, // One among `LOCAL_FILES`, `NOTION`, `WEB_SCRAPER`, `GOOGLE_DRIVE`, `INTERCOM`, `DROPBOX`, `ONEDRIVE`
    "organization_id": `<organization_id>`, // This is your unique organization id in carbon
    "organization_supplied_user_id": `<organization_supplied_user_id>`, // This is the unique user id that you pass to CC
    "organization_user_data_source_id": `<organization_user_data_source_id>`, // This is the unique user data source id that CC creates for each user for each integration
    "external_file_id": `<external_file_id>`, // This is the unique file id in the 3rd party integration
    "external_url": `<external_url>`, // This is the unique url of the file in the 3rd party integration
    "sync_status": `<sync_status>`, // This is the sync status of the file. It can be one of the following: `READY`, `QUEUED_FOR_SYNCING`, `SYNCING`, `SYNC_ERROR`
    "last_sync": `<last_sync>`, // This is the timestamp of the last sync
    "tags": `<tags>`, // These are the tags passed in to CC
    "file_statistics": `<file_statistics>`, // This is the file statistics object
    "file_metadata": `<file_metadata>`, // This is the file metadata object
    "chunk_size":   `<chunk_size>`, // This is the chunk size used for the file
    "chunk_overlap": `<chunk_overlap>`, // This is the chunk overlap used for the file
    "name": `<name>`, // This is the name of the file
    "enable_auto_sync": `<enable_auto_sync>`, // This is the auto sync status of the file. This is a boolean flag
    "presigned_url": `<presigned_url>`, // This is the presigned url of the file
    "parsed_text_url": `<parsed_text_url>`, // This is the parsed text url of the file
    "skip_embedding_generation": `<skip_embedding_generation>`, // This is the skip embedding generation status of the file. This is a boolean flag
    "created_at": `<created_at>`, // This is the timestamp of the file creation
    "updated_at": `<updated_at>`, // This is the timestamp of the file updation
    "action": `<action>`, // This is the action type. It can be one of the following: `ADD`, `UPDATE`, `REMOVE`
}

Get in Touch

If you have any questions, encounter any issues, please don't hesitate to reach out to us at team@carbon.ai. We're always delighted to hear from our users!

2.0.0

2 days ago

2.0.0-beta29

4 days ago

2.0.0-beta28

4 days ago

2.0.0-beta26

8 days ago

2.0.0-beta27

8 days ago

2.0.0-beta25

9 days ago

2.0.0-beta24

10 days ago

2.0.0-beta23

15 days ago

2.0.0-beta22

18 days ago

2.0.0-beta21

19 days ago

2.0.0-beta20

19 days ago

2.0.0-debug

21 days ago

2.0.0-beta19

22 days ago

2.0.0-beta18

22 days ago

2.0.0-beta17

23 days ago

2.0.0-beta15.1

24 days ago

2.0.0-beta15.2

24 days ago

2.0.0-beta15.3

24 days ago

2.0.0-beta14.2

24 days ago

2.0.0-beta15

24 days ago

2.0.0-beta16

24 days ago

2.0.0-beta14.1

25 days ago

2.0.0-beta13

30 days ago

1.5.68

1 month ago

2.0.0-beta9

1 month ago

2.0.0-beta11

1 month ago

2.0.0-beta10

1 month ago

2.0.0-beta12

1 month ago

2.0.0-beta8

1 month ago

2.0.0-beta7

2 months ago

2.0.0-beta6

2 months ago

2.0.0-beta5

2 months ago

2.0.0-beta3

2 months ago

2.0.0-beta4

2 months ago

2.0.0-beta1

2 months ago

2.0.0-beta2

2 months ago

1.5.67

2 months ago

1.5.66

2 months ago

1.5.65

2 months ago

1.5.64

2 months ago

1.5.63

3 months ago

1.5.62

3 months ago

1.5.61

3 months ago

1.5.60

3 months ago

1.5.59

4 months ago

1.5.58

4 months ago

1.5.56

4 months ago

1.5.57

4 months ago

1.5.52

4 months ago

1.5.54

4 months ago

1.5.53

4 months ago

1.5.55

4 months ago

1.5.51

4 months ago

1.5.50

5 months ago

1.2.3

10 months ago

1.2.2

10 months ago

1.2.1

10 months ago

1.5.5

9 months ago

1.5.4

9 months ago

1.5.3

9 months ago

1.5.2

9 months ago

1.5.1

9 months ago

1.5.0

9 months ago

1.4.11

10 months ago

1.4.10

10 months ago

1.4.13

9 months ago

1.4.12

9 months ago

1.4.15

9 months ago

1.4.14

9 months ago

1.4.6

10 months ago

1.4.5

10 months ago

1.4.4

10 months ago

1.4.3

10 months ago

1.4.2

10 months ago

1.4.1

10 months ago

1.4.0

10 months ago

1.5.30

7 months ago

1.5.32

7 months ago

1.5.31

7 months ago

1.5.34

7 months ago

1.5.33

7 months ago

1.5.36

6 months ago

1.5.35

6 months ago

1.5.38

6 months ago

1.5.37

6 months ago

1.5.41

6 months ago

1.5.40

6 months ago

1.5.43

6 months ago

1.5.9

9 months ago

1.5.42

6 months ago

1.5.8

9 months ago

1.5.45

5 months ago

1.5.7

9 months ago

1.5.44

5 months ago

1.5.6

9 months ago

1.5.46

5 months ago

1.3.5

10 months ago

1.3.4

10 months ago

1.3.3

10 months ago

1.3.2

10 months ago

1.3.1

10 months ago

1.3.0

10 months ago

1.5.10

8 months ago

1.5.12

8 months ago

1.5.11

8 months ago

1.5.14

8 months ago

1.5.16

8 months ago

1.5.15

8 months ago

1.5.18

8 months ago

1.5.17

8 months ago

1.5.19

8 months ago

1.5.21

8 months ago

1.5.20

8 months ago

1.4.9

10 months ago

1.5.23

8 months ago

1.4.8

10 months ago

1.5.22

8 months ago

1.4.7

10 months ago

1.5.25

8 months ago

1.5.24

8 months ago

1.5.27

8 months ago

1.5.26

8 months ago

1.5.29

7 months ago

1.5.28

7 months ago

1.2.0

10 months ago

1.1.1

11 months ago

1.1.0

11 months ago

1.0.11

11 months ago

1.0.12

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

0.1.0

11 months ago

0.1.2

11 months ago

0.1.1

11 months ago

1.0.10

11 months ago

0.1.4

11 months ago

0.1.3

11 months ago

0.1.6

11 months ago

0.1.5

11 months ago

0.0.91

11 months ago

0.0.9

11 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.4

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago