Skip to main content

Installation

Install the Brew SDK using your preferred package manager:
npm install brew-sdk

Package Details

PropertyValue
Package Namebrew-sdk
Version0.1.0
LicenseApache-2.0
Repositorygithub.com/GetBrew/brew-typescript-sdk

Requirements

TypeScript Version

TypeScript 4.9 or higher is required.

Runtime Support

The SDK supports the following JavaScript runtimes:
RuntimeMinimum Version
Node.js20 LTS or later (non-EOL versions)
Deno1.28.0 or higher
Bun1.0 or later
Web BrowsersUp-to-date Chrome, Firefox, Safari, Edge

Edge Runtimes

The SDK also works with:
  • Cloudflare Workers
  • Vercel Edge Runtime
  • Nitro v2.6 or greater

Testing Frameworks

  • Jest 28 or greater with the "node" environment
  • Note: "jsdom" environment is not currently supported
React Native is not currently supported. If you need React Native support, please open an issue on GitHub.

Basic Setup

After installation, import and initialize the client:
import BrewSDK from 'brew-sdk';

// Using environment variable (recommended)
const client = new BrewSDK();

// Or with explicit API key
const client = new BrewSDK({
  apiKey: 'your_api_key_here',
});

Configuration Options

The client accepts these configuration options:
import BrewSDK from 'brew-sdk';

const client = new BrewSDK({
  // Your API key (defaults to BREW_SDK_API_KEY env var)
  apiKey: process.env.BREW_SDK_API_KEY,

  // Override the base URL (defaults to https://brew.new/api)
  baseURL: 'https://api.brew.new/v1',

  // Request timeout in milliseconds (default: 60000 / 1 minute)
  timeout: 30000,

  // Maximum retry attempts for failed requests (default: 2)
  maxRetries: 3,

  // Default headers for all requests
  defaultHeaders: {
    'X-Custom-Header': 'value',
  },

  // Log level: 'debug', 'info', 'warn', 'error', 'off'
  logLevel: 'info',
});

ESM and CommonJS

The SDK supports both ESM and CommonJS imports:
import BrewSDK from 'brew-sdk';

const client = new BrewSDK();

Deno Usage

For Deno, import from npm:
import BrewSDK from 'npm:brew-sdk';

const client = new BrewSDK();

TypeScript Configuration

For optimal TypeScript support, ensure your tsconfig.json includes:
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "strict": true,
    "esModuleInterop": true
  }
}

Verifying Installation

Verify the SDK is installed correctly:
import BrewSDK from 'brew-sdk';

async function verifySetup() {
  try {
    const client = new BrewSDK();
    const docs = await client.send.transactional.documentation();
    console.log('SDK installed and authenticated successfully!');
    return true;
  } catch (error) {
    if (error instanceof BrewSDK.AuthenticationError) {
      console.error('API key is invalid or missing');
    } else {
      console.error('Setup verification failed:', error);
    }
    return false;
  }
}

verifySetup();

Environment Setup

For production applications, we recommend this project structure:
my-app/
├── .env                 # Local environment variables (git-ignored)
├── .env.example         # Example env file (committed)
├── src/
│   └── lib/
│       └── brew.ts      # SDK client singleton
└── package.json
Create a client singleton (src/lib/brew.ts):
import BrewSDK from 'brew-sdk';

// Create a single client instance to reuse
export const brew = new BrewSDK();

// Or with custom configuration
export const brew = new BrewSDK({
  maxRetries: 3,
  timeout: 30000,
});
Then import and use throughout your app:
import { brew } from '@/lib/brew';

await brew.contacts.import.create({ contacts: [...] });

Next Steps

Need Help?

Our team is ready to support you at every step of your journey with Brew. Choose the option that works best for you:

Search Documentation

Type in the “Ask any question” search bar at the top left to instantly find relevant documentation pages.

ChatGPT/Claude Integration

Click “Open in ChatGPT” at the top right of any page to analyze documentation with ChatGPT or Claude for deeper insights.