npm package: @orchard9ai/crime-api-client
Description: TypeScript client for Crime API generated with Orval
Author: Orchard AI
Latest version: 0.1.1

# @orchard9ai/crime-api-client

TypeScript client for the Crime API, generated with Orval from the OpenAPI specification.

## Installation

```bash
npm install @orchard9ai/crime-api-client
# or
pnpm add @orchard9ai/crime-api-client
# or
yarn add @orchard9ai/crime-api-client
```

## Usage

### Initialize the API Client

```typescript
import { initializeCrimeApi, getAPIDocumentation } from '@orchard9ai/crime-api-client';

// Initialize with your API configuration
initializeCrimeApi({
  baseURL: 'http://localhost:24570',
  jwt: 'your-jwt-token', // Optional: for JWT authentication
  apiKey: 'your-api-key', // Optional: for API key authentication
  projectKey: 'your-project-key', // Optional: for project key authentication
  omnipotentKey: 'your-omnipotent-key', // Optional: for admin authentication
});

// Get the API functions
const api = getAPIDocumentation();
```

### Authentication Types

The Crime API supports multiple authentication methods:

1. **JWT Authentication**: Used for user sessions
2. **API Key Authentication**: Used for server-side integrations
3. **Project Key Authentication**: Used for project-specific access
4. **Omnipotent Authentication**: Used for admin operations

### Example API Calls

```javascript
const { initializeCrimeApi, getAPIDocumentation } = require('@orchard9ai/crime-api-client');

// Initialize the client
initializeCrimeApi({
  baseURL: 'http://localhost:24570'
});

// Get API functions
const api = getAPIDocumentation();

async function example() {
  // Register a new user
  const registerResponse = await api.postAuthRegisterEmail({
    email: 'user@example.com',
    password: 'securePassword123',
    companyName: 'My Company',
    companyWebsite: 'https://mycompany.com'
  });

  // Update client with JWT
  initializeCrimeApi({
    baseURL: 'http://localhost:24570',
    jwt: registerResponse.token
  });

  // Get current session
  const session = await api.getAuthSession();

  // Create a project
  const companyId = registerResponse.company.id;
  const project = await api.postCompaniesCompanyIdProjects(companyId, {
    name: 'My Project',
    description: 'Project description'
  });

  // Create a project key
  const projectKey = await api.postCompaniesCompanyIdProjectsIdKeys(
    companyId,
    project.id,
    { type: 'write' }
  );

  // Track events using project key authentication
  initializeCrimeApi({
    baseURL: 'http://localhost:24570',
    projectKey: projectKey.key
  });

  // Track an event
  await api.postEvents({
    code: 'page_view',
    endUserId: 'user-123',
    context: { page: '/dashboard' }
  });
}
```

## Known Issues

1. **Event Registration**: Before tracking events, they must be registered through the company events API.

## API Documentation

The full API documentation is available in the OpenAPI specification file (`openapi.yaml`).

### Available Endpoints

- **Authentication**: Register, login, password reset, session management
- **Companies**: Company management and settings
- **Projects**: Project creation and management
- **Events**: Event tracking and analytics
- **End Users**: User management and insights
- **Goals & KPIs**: Goal setting and KPI tracking
- **Personas**: User persona management
- **Analytics**: Insights and metrics
- **Team**: Team member management
- **Admin**: Administrative operations (requires omnipotent auth)

## Docker Development

The Crime API runs in Docker. See the main API documentation for Docker setup:

```bash
cd ../api
docker-compose -f docker-compose.dev.yml up -d
```

Default ports:
- API: http://localhost:24570
- PostgreSQL: localhost:24572
- ClickHouse: localhost:24573
- Redis: localhost:24575

## Development

### Building the Package

```bash
pnpm install
pnpm run generate  # Regenerate from OpenAPI spec
pnpm run build     # Build the package
```

### Running the Example

```bash
node example.js
```

### Updating the OpenAPI Specification

1. Update the `openapi.yaml` file
2. Run `pnpm run generate` to regenerate the client code
3. Run `pnpm run build` to build the package

## License

MIT