indi-runtime
v0.0.3
Published
Indi runtime SDK for API monitoring in production
Maintainers
Readme
@indi/runtime
Lightweight SDK for monitoring your APIs in production. Auto-learns response schemas and detects violations — missing fields, type mismatches, schema drift, slow responses, and unexpected status codes.
Zero dependencies. Works with any framework.
Install
npm install @indi/runtimeQuick Start
Sign up at indimapper.com to get your API key and team ID, then:
import { indi } from '@indi/runtime';
indi.init({
apiKey: 'your-api-key',
teamId: 'your-team-id',
});
indi.watch('/api/users', { learningPeriod: 20 });
indi.watch('/api/orders', { maxResponseTime: 500 });How It Works
- Intercepts — Patches
fetchandXMLHttpRequestto inspect responses without affecting your app - Learns — Observes the first N responses to build a schema baseline (which fields exist, their types, required vs optional)
- Validates — After learning, every response is checked against the baseline
- Reports — Violations are logged to the console and sent to your Indi dashboard
API
indi.init(config)
| Option | Type | Description |
|--------|------|-------------|
| apiKey | string | Your API key from the dashboard |
| teamId | string | Your team ID from the dashboard |
| sampleRate | number | 0-1, percentage of requests to validate (default 1) |
| defaults.maxResponseTime | number | Max response time in ms |
| defaults.expectedStatus | number[] | Expected status codes |
| defaults.learningPeriod | number | Responses to observe before locking schema (default 20) |
indi.watch(endpoint, options?)
Start monitoring an endpoint. Supports wildcards: indi.watch('/api/*').
| Option | Type | Description |
|--------|------|-------------|
| method | string | HTTP method to match |
| maxResponseTime | number | Max response time in ms |
| expectedStatus | number[] | Expected status codes |
| learningPeriod | number | Responses before locking schema |
indi.unwatch(endpoint)
Stop monitoring an endpoint.
indi.destroy()
Unpatch fetch/XHR and clean up.
Violation Types
| Type | Description |
|------|-------------|
| missing_field | A required field is missing from the response |
| type_mismatch | A field's type changed (e.g. number became string) |
| schema_drift | A new field appeared that wasn't seen during learning |
| slow_response | Response time exceeded the threshold |
| unexpected_status | Status code not in the expected list |
License
MIT
