Velacent Bridge: beta December 2026, general availability early 2027. E-mail sales to request beta access.

Documentation menu

TypeScript SDK

Last updated . Documentation for the current release. Ask in the product.

@velacent/sdk is the official client for Node 20 or newer (tested on Node 26). It has no runtime dependencies and ships ESM and CommonJS builds with type declarations. The core also runs in modern browsers, but never put a client secret there (see Security below). Read the SDK overview first for what the SDKs do.

Install

Coming: the package will be published on npm as @velacent/sdk (npm install @velacent/sdk). Until it is, use the Data API over plain HTTP: each example below shows the raw HTTP next to the SDK call.

For typed FHIR resources, add the open-source FHIR R4 type definitions (npm install -D @types/fhir) and pass them as type arguments, for example fhir.read<fhir4.Patient>("Patient", id). They are an optional peer dependency; the SDK works without them and resources are plain FHIR JSON.

Quickstart and raw HTTP, side by side

import { Velacent } from "@velacent/sdk";

// Reads VELACENT_CLIENT_ID, VELACENT_CLIENT_SECRET and VELACENT_HOST.
// sandbox: true is the one-line switch to the developer sandbox (synthetic data only).
const client = new Velacent({ sandbox: true });
StepRaw HTTPSDK
Get a tokencurl -u "$ID:$SECRET" -d grant_type=client_credentials https://{host}/oauth/tokenautomatic on the first call, cached and refreshed
Send a messagePOST /sandbox/v1/messages with Idempotency-Keyawait client.messages.sendFhir(client.sandbox.syntheticPatient())
Read your first patienta _search POST on Patient with an identifier parameter, then GET .../fhir/Patient/{id}await client.fhir.findPatientByIdentifier(system, value)
Search, all pagesfollow each Bundle's next linkfor await (const o of client.fhir.searchAll("Observation", { patient, _count: 50 })) {}
Receive a webhookverify X-Velacent-Signature yourselfcreateWebhookHandler({ secret, onEvent })
Exportkick off, poll, download NDJSONclient.link(id).fhir.bulk (preview)

Authentication

// Client secret (server side)
new Velacent({ clientId, clientSecret, scopes: ["messages:send", "events:read"] });

// Private key (SMART Backend Services): the key never leaves your process
import { privateKeyAssertion } from "@velacent/sdk/private-key";
const tokenUrl = "https://{host}/oauth/token";
new Velacent({ clientId, assertion: privateKeyAssertion({ clientId, tokenUrl, privateKey: pemText, keyId: "k1" }) });

// Your own token source (for example in a browser, from your server)
new Velacent({ tokenProvider: async () => (await fetch("/my-server/velacent-token")).text() });

Secrets come from arguments or the environment (VELACENT_CLIENT_ID, VELACENT_CLIENT_SECRET, VELACENT_HOST, VELACENT_ENV, VELACENT_SCOPES). They are never logged or shown in an error. The token is cached for its lifetime and refreshed shortly before it ends; a revoked token is replaced once, automatically.

The Data API

Every operation of the OpenAPI description is a method on client.api (generated, typed). The ergonomic layer covers the common ones:

await client.messages.sendFhir(resource);                 // POST /messages, application/fhir+json
await client.messages.sendHl7("MSH|^~\\&|...");           // x-application/hl7-v2+er7
await client.messages.sendType("my_order", { ... });      // POST /messages/{type}

for await (const event of client.events.iterate()) { /* every event from the start */ }

// Pull mode with a stored cursor (at least once: de-duplicate by event.id)
await client.events.consume(handle, { cursor: saved, onCursor: save, signal });

await client.webhooks.create({ url: "https://your-app.example/velacent", eventTypes: ["message.received"] });
for await (const row of client.requests.iterate({ status: 422 })) { /* the request log, newest first */ }

An Idempotency-Key is generated for every POST that accepts one and reused on retries; pass your own with { idempotencyKey }. Retries follow Retry-After and RateLimit-Reset; tune them with retry: { maxRetries, baseDelayMs, maxServerWaitMs }. Errors are typed: RateLimitError, PermissionError, ValidationError, ConflictError, ServerError, OAuthError, ... each with status, code, requestId and retryable.

Partner FHIR access

const fhir = client.link("lnk_...").fhir;        // a provider's grant to your client
const cs = await fhir.metadata();                // what this link can do, nothing more

const patient = await fhir.findPatientByIdentifier("urn:oid:1.2.3.4", "MRN-001");
// or an exact demographic match: family, given and a FULL birth date; more than one match throws MultiplePatientsError
const same = await fhir.findPatientByDemographics({ family: "Smith", given: "Ann", birthdate: "1980-01-01" });

const bundle = await fhir.search("Observation", { patient: patient.id!, category: "laboratory" });
const post = await fhir.searchPost("Observation", { patient: patient.id! });   // POST _search: parameters stay out of URLs
for await (const obs of fhir.searchAll("Observation", { patient: patient.id!, _count: 50 })) { /* all pages */ }

const again = await fhir.readIfChanged("Observation", "o1", 'W/"3"');          // 304 handled

Paging follows the Bundle's next link, up to the published 50 pages, and refuses a link that leaves the API host. A page holds at most 100 resources (the SDK refuses a larger _count).

Write, and retry a create safely

await fhir.create(observation);
await fhir.update({ ...observation, id: "o1" });

// Idempotency-Key is not supported on FHIR writes (the platform keeps no copy of the provider's answers):
// the SDK throws UnsupportedOptionError and explains. Use conditional create instead:
const r = await fhir.createIfNoneExist(observation, { system: "https://your-app.example/accession", value: "A-1001" });
// r.created === true (201), or false (200): an earlier attempt already went through. 412 throws PreconditionFailedError.

A conditional create is safe to send again after a timeout or a 503; the SDK retries it for you after Retry-After, one request at a time. When metadata() says the conditional create is emulated by Velacent Bridge it is not atomic: do not send two identical creates at the same moment (FhirClient.supportsConditionalCreate(cs, "Observation") tells you the type supports it).

Bulk export (preview)

The bulk export is written against the standard FHIR Bulk Data flow and marked preview until the Velacent Bridge export is released: it may change, and it is tested only against a local mock.

const job = await fhir.bulk.start({ types: ["Patient", "Observation"], since: "2026-01-01T00:00:00Z" });
const manifest = await job.wait({ onProgress: console.log });      // honors Retry-After
for await (const resource of fhir.bulk.stream(manifest)) { /* NDJSON, line by line */ }
await job.cancel();

Webhooks

import { createWebhookHandler, constructEvent, verifySignature } from "@velacent/sdk/webhooks";

// Node http, or Express with express.raw({ type: "*/*" }) (never express.json())
const handler = createWebhookHandler({ secret, onEvent: async (event) => { /* handled once per event id */ } });
http.createServer((req, res) => void handler(req, res)).listen(8443);

// Or by hand, framework-neutral. rawBody must be the exact bytes received.
const event = constructEvent(rawBody, headers["x-velacent-signature"], secret);

The handler answers the verification challenge, checks the signature in constant time against every secret you pass (two during a rotation), refuses a timestamp more than 5 minutes off, ignores a redelivered event id, and answers 500 when your handler throws so Velacent Bridge retries. Event kinds are typed (message.received, test.ping, webhook.verification); an unknown kind arrives as it is, so ignore it.

Security

  • Keep the client secret and the private key on a server. The SDK refuses a client secret when it detects a browser. In a browser, mint tokens on your server and pass tokenProvider.
  • The SDK never logs secrets, tokens, bodies or query strings, refuses redirects, and sends your token only to the API host.
  • Use searchPost when search parameters contain identifiers. The sandbox takes synthetic data only.

Develop

npm run lint, npm test (unit tests against a mock server built from the OpenAPI description, every operation exercised), npm run check:drift (fails when the description changed and the client was not regenerated) and npm run smoke (loads the built package as ESM and CommonJS).


Something unclear or missing? Ask Help in the Velacent Bridge console; answers link to the right screen. How support works.