@orchard9ai/crime-api-client
v0.1.1
Published
TypeScript client for Crime API generated with Orval
Readme
@orchard9ai/crime-api-client
TypeScript client for the Crime API, generated with Orval from the OpenAPI specification.
Installation
npm install @orchard9ai/crime-api-client
# or
pnpm add @orchard9ai/crime-api-client
# or
yarn add @orchard9ai/crime-api-clientUsage
Initialize the API Client
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:
- JWT Authentication: Used for user sessions
- API Key Authentication: Used for server-side integrations
- Project Key Authentication: Used for project-specific access
- Omnipotent Authentication: Used for admin operations
Example API Calls
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: '[email protected]',
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
- 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:
cd ../api
docker-compose -f docker-compose.dev.yml up -dDefault ports:
- API: http://localhost:24570
- PostgreSQL: localhost:24572
- ClickHouse: localhost:24573
- Redis: localhost:24575
Development
Building the Package
pnpm install
pnpm run generate # Regenerate from OpenAPI spec
pnpm run build # Build the packageRunning the Example
node example.jsUpdating the OpenAPI Specification
- Update the
openapi.yamlfile - Run
pnpm run generateto regenerate the client code - Run
pnpm run buildto build the package
License
MIT
