Back to SDKs
TypeScript / JavaScriptv3.2.0
TypeScript SDK
The official Pharmako SDK for TypeScript and JavaScript applications.
Installation
npm install @pharmako/sdkOr using yarn or pnpm:
yarn add @pharmako/sdkpnpm add @pharmako/sdkQuick Start
import { Pharmako } from '@pharmako/sdk';
// Initialize the client
const pharmako = new Pharmako({
apiKey: process.env.PHARMAKO_API_KEY,
});
// Fetch a patient
const patient = await pharmako.patients.get('patient_123');
console.log(patient.name);
// List lab results
const labs = await pharmako.labs.list({
patientId: 'patient_123',
limit: 10,
});
// Create a webhook subscription
const webhook = await pharmako.webhooks.create({
url: 'https://your-app.com/webhooks',
events: ['patient.updated', 'lab.completed'],
});TypeScript Support
The SDK is written in TypeScript and includes full type definitions for all API responses.
import { Pharmako, Patient, LabResult } from '@pharmako/sdk';
const pharmako = new Pharmako({ apiKey: '...' });
// Fully typed responses
const patient: Patient = await pharmako.patients.get('patient_123');
// Type-safe filters
const labs: LabResult[] = await pharmako.labs.list({
patientId: patient.id,
status: 'completed', // Autocomplete available
orderBy: 'created_at',
});Error Handling
import { Pharmako, PharmakoError } from '@pharmako/sdk';
try {
const patient = await pharmako.patients.get('invalid_id');
} catch (error) {
if (error instanceof PharmakoError) {
console.error('API Error:', error.message);
console.error('Status:', error.status);
console.error('Code:', error.code);
}
}