Guides
SDK Helpers (Node.js)
Reusable Node.js helper functions for HyreLog API calls.
Reusable Client
const API_BASE = 'https://api.hyrelog.com';
type HyreLogClient = {
sendEvent: (payload: Record<string, unknown>) => Promise<unknown>;
listEvents: (params?: Record<string, string | number>) => Promise<unknown>;
keyStatus: () => Promise<unknown>;
};
export function createHyreLogClient(apiKey: string): HyreLogClient {
async function request(path: string, init: RequestInit = {}) {
const res = await fetch(`${API_BASE}${path}`, {
...init,
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
...(init.headers || {}),
},
});
if (!res.ok) {
const body = await res.text();
throw new Error(`HyreLog API error ${res.status}: ${body}`);
}
return res.json();
}
return {
sendEvent: (payload) =>
request('/v1/events', {
method: 'POST',
body: JSON.stringify(payload),
}),
listEvents: (params = {}) => {
const qs = new URLSearchParams(
Object.entries(params).map(([k, v]) => [k, String(v)]),
);
return request(`/v1/events?${qs.toString()}`);
},
keyStatus: () => request('/v1/keys/status'),
};
}Usage Example
const client = createHyreLogClient(process.env.HYRELOG_API_KEY!);
await client.sendEvent({
category: 'auth',
action: 'user.login',
idempotencyKey: crypto.randomUUID(),
});