API client for browser and Node.js

@codmir/client

Low-level API client for direct Codmir API access. For most use cases, prefer @codmir/sdk.

Installation

npm install @codmir/client

Quick Start

import { CodmirClient } from '@codmir/client';

const client = new CodmirClient({
  token: process.env.CODMIR_TOKEN,
});

// Make API requests
const response = await client.get('/projects');
const project = await client.post('/projects', {
  name: 'My Project',
});

API Reference

Constructor

new CodmirClient(options: ClientOptions)
OptionTypeRequiredDescription
tokenstringYesAPI token
baseUrlstringNoAPI base URL
timeoutnumberNoRequest timeout (ms)
retriesnumberNoMax retry attempts

Methods

// GET request
client.get<T>(path: string, params?: object): Promise<T>

// POST request
client.post<T>(path: string, body?: object): Promise<T>

// PUT request
client.put<T>(path: string, body?: object): Promise<T>

// PATCH request
client.patch<T>(path: string, body?: object): Promise<T>

// DELETE request
client.delete<T>(path: string): Promise<T>

Examples

Projects

// List projects
const projects = await client.get<Project[]>('/v1/projects');

// Create project
const project = await client.post<Project>('/v1/projects', {
  name: 'New Project',
  gitRemote: 'https://github.com/org/repo',
});

// Update project
await client.patch(`/v1/projects/${id}`, {
  name: 'Updated Name',
});

Events

// Emit event
await client.post('/v1/events', {
  type: 'ci.workflow.completed',
  payload: { ... },
});

// Query events
const events = await client.get('/v1/events', {
  type: 'ci.*',
  since: '24h',
});

Chat

// Send message
const response = await client.post('/v1/chat', {
  message: 'Help me with this code',
  context: { files: ['main.ts'] },
});

Error Handling

import { CodmirClient, ApiError } from '@codmir/client';

try {
  await client.get('/projects/unknown');
} catch (error) {
  if (error instanceof ApiError) {
    console.log(error.status);   // 404
    console.log(error.message);  // 'Project not found'
    console.log(error.code);     // 'NOT_FOUND'
  }
}

When to Use

Use CaseRecommended
Most applications@codmir/sdk
Custom API wrappers@codmir/client
Direct API access@codmir/client
Type-safe helpers@codmir/sdk

Next Steps