Skip to main content

Overview

The @databite/build package provides the core functionality for creating connectors using a fluent API. It includes the ConnectorBuilder class, action and sync creators, and helper functions for building type-safe connectors.

Installation

npm install @databite/build @databite/types
Peer Dependencies:
npm install zod typescript

Core Classes

ConnectorBuilder

The main class for building connectors with a fluent API:
import { createConnector } from "@databite/build";
import { z } from "zod";

const connector = createConnector()
  .withIdentity("my-service", "My Service")
  .withVersion("1.0.0")
  .withAuthor("Your Name")
  .withLogo("https://example.com/logo.png")
  .withDescription("Connector for My Service")
  .build();

Builder Methods

Identity & Metadata

// Set connector identity
.withIdentity(id: string, name: string)

// Set version
.withVersion(version: string)

// Set author
.withAuthor(author: string)

// Set logo URL
.withLogo(logo: string)

// Set documentation URL
.withDocumentationUrl(url: string)

// Set description
.withDescription(description: string)

Configuration

// Add integration configuration schema
.withIntegrationConfig(config: ZodSchema)

// Add connection configuration schema
.withConnectionConfig(config: ZodSchema)

// Add tags for categorization
.withTags(...tags: string[])

// Add categories
.withCategories(...categories: ConnectorCategory[])

Refresh Handling

// Set refresh function
.withRefresh(
  (connection: Connection<TConnectionConfig>) => Promise<z.infer<TConnectionConfig>>
)

Actions & Syncs

// Add actions
.withActions(actions: Record<string, Action>)

// Add syncs
.withSyncs(syncs: Record<string, Sync>)

Helper Functions

createAction

Creates an action with automatic retry logic and timeout handling:
import { createAction } from "@databite/build";
import { z } from "zod";

const action = createAction({
  label: "Get User",
  description: "Fetch user by ID",
  inputSchema: z.object({ id: z.string() }),
  outputSchema: z.object({
    user: z.object({ id: z.string(), name: z.string() }),
  }),
  maxRetries: 3,
  timeout: 30000,
  handler: async (params, connection) => {
    // Your implementation
    return { user: { id: params.id, name: "John Doe" } };
  },
});

createSync

Creates a sync operation for data synchronization:
import { createSync } from "@databite/build";

const sync = createSync({
  label: "Sync Users",
  description: "Synchronize user data",
  schedule: "0 9 * * *", // Daily at 9 AM
  outputSchema: z.array(z.object({ id: z.string() })),
  maxRetries: 3,
  timeout: 60000,
  handler: async (connection) => {
    // Your sync implementation
    return [{ id: "1" }, { id: "2" }];
  },
});