This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the MailBots JavaScript SDK (@mailbots/mailbots-sdk) - a client library for interacting with the MailBots API. It's designed to work in both Node.js server environments and browser contexts.
npm test- Run tests with mocked API requests (default)npm run test:live- Run tests against live API (requires .env configuration)npm run test:rebuild- Rebuild mock responses from live API calls
npm run build- Build all targets (node, browser, and dist)npm run build:watch- Watch mode for node and browser buildsnpm run build:node- Build Node.js version only (outputs to lib-node/)npm run build:browser- Build browser version only (outputs to lib-browser/)npm run build:dist- Build webpack distribution (outputs to dist/)
npm run build:docs- Generate and deploy documentationnpm run dev:docs- Serve documentation in watch mode
The SDK uses conditional compilation to support both server and browser environments:
- Server builds include OAuth2 functionality via
simple-oauth2 - Browser builds exclude server-only features for security
- Environment detection via
process.env.SERVERflag in Babel configuration
- MailBotsClient: Main client class that aggregates all API modules
- API Modules: Separate modules for different functionality areas:
tasks.js- Task management (create, update, delete, trigger)auth.js- OAuth2 authentication flowsusers.js- User managementpeople.js- People/contacts managementwebhooks.js- Webhook utilitiesmailbots.js- MailBot-specific operationsutil.js- Shared utilities and request handling
- Direct instantiation:
new MailBotsClient(config) - From bot webhook:
MailBotsClient.fromBot(bot)- factory method that extracts configuration and access token from webhook bot object
- Uses Axios for HTTP requests
- Supports both callbacks and promises/async-await
- Bearer token authentication
- Distributed tracing via
x-mailbots-sessionidheader
Complete CRUD operations for MailBots tasks including:
- Creating tasks with email content
- Updating task properties and scheduling
- Triggering tasks programmatically
- Email sending with automatic task creation
- OAuth2 authorization code flow (server-only)
- Manual access token setting for webhook contexts
- Secure client secret handling (server environments only)
- Uses Nock for HTTP mocking
- Mocked requests match values in .env.example
- Live testing requires actual MailBot configurations in .env
- Transforms ES6+ for broad compatibility
- Conditional compilation removes server-specific code for browser builds
- Dead code elimination for optimized output
- lib-node/: CommonJS for Node.js (includes OAuth2)
- lib-browser/: Browser-compatible build (excludes server features)
- dist/: Webpack bundle for direct browser inclusion
- typings/: TypeScript definitions
Testing requires configuration of MailBot credentials:
- Client ID, secret, redirect URI, scope
- Access tokens for authenticated requests
- API host configuration for different environments