TypeScript / JavaScript SDK
Official TypeScript and JavaScript client for StoneDock Connect.
The @onepathhealth/connect package (currently v2.6.0) is the official TypeScript SDK. It wraps every public API endpoint with full type safety, typed errors, and IDE autocomplete.
Access: The SDK is distributed through GitHub Packages. After your BAA is executed, you'll receive an invitation to the GitHub organization that grants install access.
Setup
Create an .npmrc file in your project root with your GitHub token:
# .npmrc
@onepathhealth:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}Then install:
npm install @onepathhealth/connectQuick Start
import { OnepathClient } from "@onepathhealth/connect";
const onepath = new OnepathClient({
apiKey: process.env.ONEPATH_API_KEY,
// baseUrl defaults to https://api.onepath.health
// use https://sandbox.onepath.health for testing
});
// Onboard a user
const user = await onepath.users.onboard({
externalId: "your-internal-user-id",
consentScopeId: "full-health",
consentToken: await generateConsentToken(userId),
});
// Submit health data
await onepath.users.updateHealthData(user.userId, {
observations: [
{
code: "8867-4",
system: "http://loinc.org",
display: "Heart rate",
valueQuantity: { value: 72, unit: "beats/min" },
effectiveDateTime: new Date().toISOString(),
},
],
});
// Get AI insights
const insights = await onepath.insights.get(user.userId);
console.log(insights.summary);Client Options
const onepath = new OnepathClient({
apiKey: "onepath_production_...", // defaults to process.env.ONEPATH_API_KEY
baseUrl: "https://api.onepath.health", // override for sandbox
timeout: 30_000, // request timeout in ms (default: 30s)
consentJwt: "...", // default consent JWT forwarded on every call; override per-call where supported
});All Resources
Most user-scoped methods take an optional trailing consentJwt argument to override the client's default for a single call — pass it explicitly whenever one client instance serves more than one externalId.
onepath.users
// Register a user — idempotent on externalId
const user = await onepath.users.onboard({
externalId: "user-123",
consentScopeId: "full-health",
consentToken: "...",
});
// Submit FHIR health data
await onepath.users.updateHealthData(userId, {
observations: [...],
conditions: [...],
medications: [...],
});
// Retrieve all health data on file
const data = await onepath.users.getHealthData(userId);onepath.insights
const insights = await onepath.insights.get(userId);
// { summary, insights: [...], healthScore, generatedAt }onepath.healthSummary
const summary = await onepath.healthSummary.get(userId);
// raw FHIR observations, conditions, and demographics — unprocessed, unlike insights.get()onepath.healthScore
const score = await onepath.healthScore.get(userId);
// { overallScore: 78, domains: { cardiovascular: 82, metabolic: 74, ... } }onepath.lab
const result = await onepath.lab.analyze(userId, {
documentBase64: pdfBuffer.toString("base64"),
fhirResourceId: "optional-doc-id",
});
// { findings: [{ testName, value, status, loincCode }], summary }Requires labs.analyze. Adding a provider comment to a lab result requires the separate labs.comment scope — see the API Reference.
onepath.coaching
// Start a session
const response = await onepath.coaching.chat(userId, {
message: "What does my latest lab work say about my cholesterol?",
includeHealthContext: true,
});
// Continue the session
const follow = await onepath.coaching.chat(userId, {
sessionId: response.sessionId,
message: "What can I do to improve it?",
});onepath.chat
General-purpose chat, separate from coaching — session-based Q&A not tied to a coaching flow.
const reply = await onepath.chat.send(userId, "What should I ask my doctor at my next visit?");
// omit sessionId to start a new session; pass it back to continue one
const follow = await onepath.chat.send(userId, "Anything about my cholesterol?", reply.sessionId);
const history = await onepath.chat.getHistory(userId);
const sessions = await onepath.chat.getSessions(userId);
// Chat scoped to a specific resource (e.g. a lab result)
await onepath.chat.withResource(userId, { resourceType: "lab-result", resourceId: labId, message: "Explain this result" });onepath.documents
const docs = await onepath.documents.list(userId);
const analysis = await onepath.documents.analyze(documentId);
const reply = await onepath.documents.chat(documentId, "Summarize this document");Binary download isn't wrapped by the SDK — fetch GET /partner/v1/documents/{documentId}/download directly with your API key.
onepath.demographics
const demo = await onepath.demographics.get(userId);
await onepath.demographics.update(userId, { heightCm: 180, weightKg: 82 }); // only send fields you're changingonepath.goals
const goals = await onepath.goals.list(userId);
const goal = await onepath.goals.create(userId, {
title: "Reduce resting heart rate to under 70 bpm",
category: "cardiovascular",
targetDate: "2027-01-01",
});
await onepath.goals.update(userId, goal.goalId, { progress: 40 });onepath.fitnessPlans
const plans = await onepath.fitnessPlans.list(userId, "active"); // status filter is optional
const plan = await onepath.fitnessPlans.create(userId, { title: "8-week base build", goalIds: [goal.goalId] });
await onepath.fitnessPlans.updateStatus(userId, plan.planId, "completed");
await onepath.fitnessPlans.coachingChat(userId, plan.planId, { message: "Adjust this week's plan, I'm traveling" });onepath.productAdvisor
const reply = await onepath.productAdvisor.chat(userId, [{ role: "user", content: "What should I take for recovery?" }]);
const sessions = await onepath.productAdvisor.getSessions(userId);
await onepath.productAdvisor.closeSession(userId, sessionId); // soft-close — history is retainedonepath.usage
Partner-account-level, not patient-scoped — no consentJwt needed.
const current = await onepath.usage.getCurrent();
const history = await onepath.usage.getHistory(6); // months of history, default 3onepath.practitioners
Provisions a FHIR Practitioner identity for one of your clinicians so writes elsewhere (messaging, care team, visit notes, appointments, lab comments) can attribute a specific action to a specific person.
const practitioner = await onepath.practitioners.register({
practitionerId: "dr-smith-01",
displayName: "Dr. Jane Smith",
role: "clinician",
npi: "1234567890",
});
const list = await onepath.practitioners.list();
const one = await onepath.practitioners.get("dr-smith-01");onepath.careTeam
A patient's roster of assigned providers (treating / covering / supervising). Requires care_team.read/care_team.write and a registered practitioner.
await onepath.careTeam.addMember(userId, { practitionerId: "dr-smith-01", role: "treating" });
await onepath.careTeam.updateStatus(userId, "dr-smith-01", "paused");
await onepath.careTeam.endMembership(userId, "dr-smith-01"); // soft-end, history kept
const team = await onepath.careTeam.list(userId, { includeEnded: true });
const patients = await onepath.careTeam.listPatients("dr-smith-01");onepath.messaging
Store-and-forward compliance record of patient↔provider messages — not a live chat backend. Your own app remains the real-time transport; StoneDock mirrors messages after the fact. Requires messaging.read/messaging.write and a registered practitioner.
await onepath.messaging.send(userId, {
practitionerId: "dr-smith-01",
direction: "patient-to-provider",
content: "Question about my last lab result",
});
const all = await onepath.messaging.list(userId);
const withOne = await onepath.messaging.list(userId, "dr-smith-01"); // scoped to one provider's threadonepath.visitNotes
Freeform, provider-authored visit notes. Requires visit_notes.read/visit_notes.write.
const note = await onepath.visitNotes.create(userId, {
practitionerId: "dr-smith-01",
title: "Follow-up visit",
reasonForVisit: "Routine check-in",
});
await onepath.visitNotes.update(userId, note.noteId, { assessment: "Stable" }); // needs expectedVersion in params
await onepath.visitNotes.sign(userId, note.noteId, note.version); // final + immutable from here
await onepath.visitNotes.addAddendum(userId, note.noteId, { practitionerId: "dr-smith-01", text: "Correction: BP was 120/80, not 128/84" });
const list = await onepath.visitNotes.list(userId);
const detail = await onepath.visitNotes.get(userId, note.noteId); // includes addendaonepath.appointments
Mirrors your own scheduling system (or telehealth tool) into StoneDock's FHIR store. Requires appointments.read/appointments.write and a registered practitioner.
const appt = await onepath.appointments.create(userId, {
practitionerId: "dr-smith-01",
scheduledStart: "2026-12-01T15:00:00Z",
durationMinutes: 30,
reason: "Follow-up",
});
const list = await onepath.appointments.list(userId);
const one = await onepath.appointments.get(userId, appt.fhirAppointmentId);
await onepath.appointments.updateStatus(userId, appt.fhirAppointmentId, "arrived");
await onepath.appointments.addNote(userId, appt.fhirAppointmentId, { practitionerId: "dr-smith-01", noteText: "Patient arrived on time" });onepath.conditions
Requires conditions.read/conditions.write.
const condition = await onepath.conditions.create(userId, { name: "Hypertension", diagnosedDate: "2026-01-15" });
const list = await onepath.conditions.list(userId);
const one = await onepath.conditions.get(userId, condition.conditionId);
await onepath.conditions.update(userId, condition.conditionId, { clinicalStatus: "resolved" });
await onepath.conditions.delete(userId, condition.conditionId); // soft deleteonepath.questionnaires
Questionnaire responses not tied to a medication order — see onepath.medications.submitProgressCheckin for the order-scoped equivalent. Requires questionnaires.read/questionnaires.write.
await onepath.questionnaires.submitResponse(userId, {
questionnaireCode: "phq-9",
answers: [{ code: "phq9-1", display: "Little interest or pleasure", value: "1" }],
});
const responses = await onepath.questionnaires.listResponses(userId, "phq-9"); // code filter optionalonepath.medications
Medication order/refill lifecycle — see the medication refill lifecycle guide for the full end-to-end flow. Requires medications.read/medications.write.
const order = await onepath.medications.createOrder(
userId,
{
externalOrderReference: "wellvi_order_9182",
medicationName: "Semaglutide",
medicationCategory: "peptide",
expectedSupplyDurationDays: 28,
startDate: "2026-08-18",
ehrPracticeConfigId: "5f2c1e3a-...", // optional — omit for no EHR sync
},
"wellvi_order_9182" // idempotency key
);
const orders = await onepath.medications.listOrders(userId);
const due = await onepath.medications.getRefillsDue({ withinDays: 5 });
await onepath.medications.submitProgressCheckin(userId, order.medicationRequestId, {
answers: [{ code: "wellvi-side-effects", value: "None reported" }],
});
const checkins = await onepath.medications.listProgressCheckins(userId, order.medicationRequestId);
// Refilled: call createOrder() again with renewsOrderReference set.
// Not refilled: close the loop instead —
await onepath.medications.discontinueOrder(userId, order.medicationRequestId, {
reason: "patient-discontinued",
});Not yet wrapped by this SDK
Two backend endpoints exist and are grantable today but don't have a resource class yet — call them directly over HTTP:
- Allergies (
allergies.read/allergies.write) —/partner/v1/users/{id}/allergies - Authored Notes (
notes.read/notes.write) —/partner/v1/users/{id}/authored-notes
onepath.questionnaires and onepath.appointments are also only partially wrapped — submitResponse/listResponses and create/list/get/updateStatus/addNote are covered, but amending a questionnaire response (PATCH .../questionnaire-responses/{responseGroupId}), adding a comment to one (POST .../comments), and rescheduling or editing appointment details (PATCH .../schedule, PATCH .../details) aren't yet — call those directly over HTTP too.
See the API Reference for all of the above. onepath.prescriptions also exists on the client (Wellvi pharmacy-submission integration) but is intentionally undocumented here — it's a bespoke capability for one partner integration, not a general-purpose resource.
Error Handling
import {
OnepathAuthError,
OnepathForbiddenError,
OnepathNotFoundError,
OnepathValidationError,
OnepathRateLimitError,
OnepathServerError,
} from "@onepathhealth/connect";
try {
const user = await onepath.users.onboard({ ... });
} catch (err) {
if (err instanceof OnepathAuthError) {
// 401 — API key or consent token invalid/expired
}
if (err instanceof OnepathForbiddenError) {
// 403 — valid credentials, but this scope isn't granted
}
if (err instanceof OnepathValidationError) {
console.error(err.details); // field-level errors: { externalId: ["required"] }
}
if (err instanceof OnepathRateLimitError) {
await sleep(err.retryAfter * 1000);
// then retry
}
if (err instanceof OnepathNotFoundError) {
// resource doesn't exist
}
if (err instanceof OnepathServerError) {
// 5xx — safe to retry with exponential backoff
}
}Idempotent Requests
The onboarding endpoint is idempotent by design — calling it twice with the same externalId returns the existing user. For other write operations that accept one, pass an idempotency key:
const key = `onboard-${userId}-${Date.now()}`;
const user = await onepath.users.onboard(params, key);TypeScript
The SDK ships .d.ts declaration files and is fully typed. Request and response shapes are exported from the package root — see src/types/index.ts in the SDK for the full list, e.g.:
import type {
OnboardUserParams,
GetInsightsResponse,
HealthInsight,
FhirObservation,
CreateConditionParams,
CreateVisitNoteParams,
} from "@onepathhealth/connect";