npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@truenorth-it/dataverse-client

v1.55.0

Published

**Unlock your Dataverse data.** Your CRM data is trapped behind OData queries, Azure AD service principals, and Microsoft SDK complexity. Your frontend team just wants JSON. This package is the key.

Readme

@truenorth-it/dataverse-client

Unlock your Dataverse data. Your CRM data is trapped behind OData queries, Azure AD service principals, and Microsoft SDK complexity. Your frontend team just wants JSON. This package is the key.

A type-safe JavaScript/TypeScript client that turns your Dataverse instance into clean REST endpoints. Secure by architecture — every request is authenticated, authorised, and scoped to the logged-in user. No Microsoft dependencies in your frontend. No Azure tokens in the browser.

Works with any deployment — generate TypeScript types specific to your Dataverse org, or use it untyped.

Installation

npm install @truenorth-it/dataverse-client

Quick start (no types)

The SDK works out of the box without any type generation. Response data is Record<string, unknown>:

import { createClient } from "@truenorth-it/dataverse-client";

const client = createClient({
  baseUrl: "https://api.dataverse-contact.tnapps.co.uk",
  scope: "default", // scope segment in API URLs (e.g. /api/v2/default/me/case)
  getToken: () => getAccessTokenSilently(), // any function returning a Bearer token (e.g. MSAL for Entra External ID)
});

const result = await client.me.list("case", {
  select: ["title", "ticketnumber", "statuscode", "createdon"],
  top: 20,
  orderBy: { field: "modifiedon", direction: "desc" },
});

for (const record of result.data) {
  console.log(record.ticketnumber, record.title);
}

Why this exists

Your Dataverse data is locked behind APIs designed for platform consultants — not for frontend teams building customer portals. Between your React app and the data sit Azure AD client credentials, OData entity navigation, MSAL token management, and GUID-based lookups.

This client eliminates all of that:

| You write | Instead of | |---|---| | client.me.list("case") | OData queries, $filter, $expand, GUID joins | | getAccessTokenSilently() | MSAL, client credentials, service principal config | | Nothing — it's automatic | Custom row-level security middleware | | npx dataverse-client generate | Manually typing Dataverse schemas |

Stop building middleware. Start building your portal.

Types are optional

Generated types are a developer experience convenience, not a requirement. The SDK works identically with or without them — every method accepts an optional generic, and defaults to Record<string, unknown> when none is provided.

  • No types: works out of the box, no setup needed
  • With types: add <Case> (or any generated interface) to calls where you want autocomplete
  • Mix freely: type the tables you work with most, leave the rest untyped
  • Stale types are fine: if your schema changes and you don't regenerate, your code still runs — you just lose autocomplete for new fields
// ✅ All three of these work in the same file
const cases    = await client.me.list<Case>("case");  // typed
const projects = await client.me.list("project");              // untyped — still works
const contacts = await client.me.lookup<Contact>("contact", { search: "jane" }); // typed

Generate types for your API

For full TypeScript autocomplete and type safety, generate interfaces from your own API deployment:

npx dataverse-client generate --url https://api.dataverse-contact.tnapps.co.uk --scope servicebuilder

generate runs a suite of generators and writes their combined output to one file (dataverse.generated.ts). Two are built in, and each only contributes what applies to the scope:

  • tables — for every table: a typed interface, const enums for choice fields, a <Table>Field union (for typed select/filter/orderBy), and <Table>CreateInput / <Table>UpdateInput (the writable subset).
  • service-forms — for a Service Builder scope, an interface per service's submitted form (lcc_requestdata), plus a ServiceRequestDataByType slug-to-type map and a ServiceType union. Services whose schema errors in Dataverse are skipped with a logged note; the rest still generate.

Both use public endpoints (no auth). Output is deterministic (sorted), so regenerating produces byte-identical files unless something actually changed and diffs stay clean.

CLI options

| Flag | Default | Description | |------|---------|-------------| | --url, -u | (required) | Base URL of your API deployment | | --output, -o | ./dataverse.generated.ts | Output file path | | --api-base | /api/v2 | API base path (before scope segment) | | --scope, -s | default | API scope segment | | --only <name> | (all) | Run just one generator (e.g. tables, service-forms) |

Add more generators

The suite is extensible. An npm package can implement the Generator contract and be registered so generate picks it up:

npx dataverse-client add @your-org/dataverse-zod-gen

This installs the package and appends it to dataverse.config.json:

{ "generators": ["@your-org/dataverse-zod-gen"] }

generate then dynamically imports each listed package (resolved from your node_modules) and runs it alongside the built-ins. A generator is just:

import type { Generator } from "@truenorth-it/dataverse-client";

const gen: Generator = {
  name: "zod",
  applies: (ctx) => ctx.scope === "servicebuilder",   // optional gate
  run: async (ctx) => {
    // ctx gives you: scope, baseUrl, apiBase, a ready `client`, and `fetchJson(path)`
    return "/* generated TypeScript source */";
  },
};
export default gen;

Built-in generators always run; the config only lists the extra ones. Package names are validated before install (no shell injection), and a package that can't be loaded is skipped with a log rather than failing the run.

Using generated types

import { createClient } from "@truenorth-it/dataverse-client";
import type { Case, Contact } from "./dataverse.generated";

const client = createClient({
  baseUrl: "https://api.dataverse-contact.tnapps.co.uk",
  scope: "default",
  getToken: () => getAccessTokenSilently(),
});

// Fully typed — result.data is Case[]
const result = await client.me.list<Case>("case", {
  select: ["title", "ticketnumber", "statuscode", "createdon"],
  top: 20,
});

for (const c of result.data) {
  console.log(c.ticketnumber, c.title, c.statuscode_label);
  //          ^ string        ^ string  ^ "In Progress" etc.
}

Using choice enums

The generated file also includes const objects for choice (picklist) fields, so you can compare values without magic numbers:

import { createClient } from "@truenorth-it/dataverse-client";
import type { Case } from "./dataverse.generated";
import { CaseStatuscode, CasePrioritycode } from "./dataverse.generated";

const cases = await client.me.list<Case>("case", {
  filter: { field: "statuscode", operator: "eq", value: CaseStatuscode.InProgress },
});

for (const c of cases.data) {
  if (c.statuscode === CaseStatuscode.OnHold) {
    console.log("Case is on hold:", c.title);
  }
  if (c.prioritycode === CasePrioritycode.High) {
    console.log("High priority:", c.title);
  }
}

Each choice const is also a type — use it for function signatures:

function handleStatus(status: CaseStatuscode) {
  // status is narrowed to 1 | 2 | 3 | 5 etc.
}

To skip choice generation (faster, interfaces only): npx dataverse-client generate --url ... --no-choices

Typed query options (catch field typos at compile time)

Each table also gets a <Table>Field union. Pair it with QueryOptionsFor<Field> to have select, orderBy.field, and filter.field checked against the real field names — a typo becomes a compile error instead of a 400 at runtime. It's opt-in: plain QueryOptions still works untyped.

import type { Case, CaseField } from "./dataverse.generated";
import type { QueryOptionsFor } from "@truenorth-it/dataverse-client";

const opts: QueryOptionsFor<CaseField> = {
  select: ["title", "statuscode"],          // "titel" → compile error
  orderBy: { field: "createdon", direction: "desc" },
  filter: { field: "statuscode", operator: "eq", value: 1 },
  // parent.<field> cross-entity filters on child tables are still allowed, as are
  // <lookupField>.<field> filters on a configured expand's declared fields,
  // e.g. { field: "primarycontactid.fullname", operator: "eq", value: "Jane" }
};
const page = await client.me.list<Case>("case", opts);

Typed create / update payloads

<Table>CreateInput and <Table>UpdateInput describe just the writable fields. CreateInput also omits lookups the API auto-binds from your identity (via the table's create defaults), so you only pass what you actually set:

import type { CaseCreateInput } from "./dataverse.generated";

const input: CaseCreateInput = { title: "VPN down", description: "Site B offline" };
// customerid / primarycontactid are auto-bound — not part of CaseCreateInput
const created = await client.me.create<Case>("case", input);

CI / build integration

Add to your package.json to regenerate types when your schema changes:

{
  "scripts": {
    "generate:types": "dataverse-client generate --url $API_URL --output src/dataverse-types.ts",
    "prebuild": "npm run generate:types"
  }
}

Programmatic usage

The codegen function is also exported for use in custom build scripts:

import { generateTableTypes } from "@truenorth-it/dataverse-client";

const response = await fetch("https://api.dataverse-contact.tnapps.co.uk/api/v2/default/schema");
const schema = await response.json();
const tsSource = generateTableTypes(schema);
// Write tsSource to a file, pipe it, etc.

Usage with React + MSAL (Entra External ID)

import { useMemo } from "react";
import { useMsal } from "@azure/msal-react";
import { createClient } from "@truenorth-it/dataverse-client";

function useApiClient() {
  const { instance, accounts } = useMsal();

  return useMemo(
    () =>
      createClient({
        baseUrl: import.meta.env.VITE_API_BASE_URL,
        scope: "default",
        getToken: async () => {
          const { accessToken } = await instance.acquireTokenSilent({
            // Application ID URI of your API's Entra app registration
            scopes: [`${import.meta.env.VITE_API_SCOPE}/access_as_user`],
            account: accounts[0],
          });
          return accessToken;
        },
      }),
    [instance, accounts],
  );
}

The SDK is identity-provider-agnostic — getToken just needs to return a Bearer string. Swap MSAL for any other OIDC client if your deployment uses a different provider.

Client configuration

createClient({
  baseUrl: string;                     // API deployment URL
  getToken?: () => Promise<string>;    // Returns a Bearer token (optional for public-only access)
  apiBase?: string;                    // Defaults to "/api/v2"
  scope?: string;                      // Defaults to "default" — inserted after apiBase in URLs
  companyId?: string;                  // Act as a specific company (sends X-Company-Id). See "Multiple companies".
  contactId?: string;                  // Older alias (sends X-Contact-Id). Equivalent in the classic model.
  onResponse?: (info) => void;         // Observability hook — see below
  signal?: AbortSignal;                // Cancel every request this client makes — see below
});

Observability: onResponse

Called after every HTTP response the client receives (success and error alike) with { url, method, status, cache, durationMs, receivedAt }. cache is the server response-cache result ("HIT" / "MISS" from the X-Cache header, null when the cache is off). Hook errors are swallowed — they can never break a request. Useful for a debug overlay or telemetry:

const lastResponse = new Map<string, ResponseInfo>();
const client = createClient({
  baseUrl,
  getToken,
  onResponse: (info) => lastResponse.set(new URL(info.url).pathname, info),
});
// e.g. render "cache HIT · 42ms · 14:02:11" on a dashboard tile

Cancelling requests (AbortSignal)

Every method accepts a signal. Aborting cancels the underlying HTTP request — the connection is dropped, so no bandwidth, no serverless invocation and no Dataverse API quota is spent on a result nobody is waiting for.

Methods with an options bag take signal inline; the rest take it as a trailing argument:

const controller = new AbortController();

client.me.list("case", { search: term, signal: controller.signal });
client.me.get("case", id, { signal: controller.signal });
client.me.create("case", data, { signal: controller.signal });
client.me.whoami({ signal: controller.signal });
client.choices("case", "statuscode", { signal: controller.signal });

controller.abort();

Search as you type

This is the case the signal exists for. With TanStack Query, pass through the signal its queryFn already receives — each keystroke cancels the request the previous one started:

useQuery({
  queryKey: ["case-search", term],
  queryFn: ({ signal }) => client.me.list<Case>("case", { search: term, signal }),
});

Without a signal, TanStack still discards the stale result, but the request itself runs to completion against Dataverse. On a busy typeahead that is most of your request volume.

Client-wide cancellation

ClientConfig.signal applies to every request a client makes — useful for tearing down all in-flight work at once (sign-out, tenant switch):

const teardown = new AbortController();
const client = createClient({ baseUrl, getToken, signal: teardown.signal });
// ...later
teardown.abort();

A per-call signal does not replace the client-wide one: the two are composed, and whichever aborts first cancels the request.

Cancelling a drain

eachPage() and changes({ drain: true }) issue several sequential requests. The signal is checked between pages, so aborting stops the drain instead of running it to the end:

for await (const page of client.me.eachPage<Case>("case", { top: 50, signal })) {
  render(page.data);
}

Catching it

An aborted call rejects with AbortError, never ApiError — no HTTP exchange completed, so there is no status to inspect. Its name is "AbortError", so existing err.name === "AbortError" checks keep working, and reason carries whatever you passed to abort():

import { AbortError } from "@truenorth-it/dataverse-client";

try {
  await client.me.list("case", { signal });
} catch (err) {
  if (err instanceof AbortError) return;   // expected — not an error worth reporting
  throw err;
}

Route cancellations away from your error reporting, or a busy typeahead will fill it with noise.

Access scopes

The client exposes four scopes, each backed by server-side authorization:

| Scope | Description | Operations | |-------|-------------|------------| | client.me | Your own records (contact-scoped) | list, get, update, lookup, create, whoami, register, companies, claimableCompanies | | client.team | Records belonging to your team/account | list, get, update, lookup | | client.all | All records (requires elevated permissions) | list, get, update, lookup | | client.public | Public tables (no authentication) | list, get |

Multiple companies

A person can act as more than one company. Most users have exactly one. When they have more, client.me.companies() lists them and client.withCompany(companyId) returns a client that acts as the chosen one — it sends the X-Company-Id header on every request; the server verifies the company belongs to you. With no selection, the API uses the default company.

Each company carries a stable companyId — the value to pass to withCompany(). (Depending on how the backing scope is configured, this is either the Dataverse contact id or the account id; you don't need to care which — just pass companyId back.) The older client.withContact(contactid) still works.

const { companies, hasMultiple } = await client.me.companies();
if (hasMultiple) {
  const globex = companies.find((c) => c.companyName === "Globex Inc")!;
  const globexClient = client.withCompany(globex.companyId);
  const cases = await globexClient.me.list("case"); // scoped to Globex
}

// whoami also reports the companies and a hasMultipleCompanies flag:
const me = await client.me.whoami();
console.log(me.dataverseContact?.companyName, me.hasMultipleCompanies);

Operations

List records

const result = await client.me.list("case", {
  select: ["title", "ticketnumber", "statuscode", "prioritycode", "createdon"],
  top: 50,
  orderBy: { field: "createdon", direction: "desc" },
  filter: { field: "statuscode", operator: "eq", value: 1 },
});

// result.data — Record<string, unknown>[] (or Case[] if you pass a generic)
// result.page — { top, next } — use fetchPage(page.next) for subsequent pages

for (const c of result.data) {
  console.log(c.ticketnumber, c.title);
  console.log(c.statuscode, c.statuscode_label);     // 1, "In Progress"
  console.log(c.prioritycode, c.prioritycode_label); // 2, "Normal"
}

With types: client.me.list<Case>("case", ...) — gives full autocomplete on result.data.

List one parent's children

A child table (one whose /schema entry has a parentTable, e.g. casenotes under case) can be listed for one parent record:

const notes = await client.me.list("casenotes", { parent: caseId });

The API checks the case is one you can see (a 404 ApiError otherwise), then returns its notes, with every other option (filter, orderBy, top, …) applied as usual. It's the same request as GET /me/case/{caseId}/casenotes.

Deprecated: list("casenotes", { filter: { field: "_objectid_value", operator: "eq", value: caseId } }) still works exactly as before, but the API now marks it with a Deprecation header. Use { parent: caseId } instead: it also tells you when the case isn't yours, where the filter just returns nothing.

List activity records by subtype

Activity tables (caseactivities, contactactivities) support subtype filtering to retrieve specific activity types:

// List all phone calls for your cases
const phoneCalls = await client.me.list("caseactivities", {
  subtype: "phonecall",
  select: ["activityid", "subject", "activitytypecode"],
  top: 20,
});

// List all activity types at once
const allActivities = await client.me.list("caseactivities", {
  subtype: "all",
  orderBy: { field: "createdon", direction: "desc" },
});

// Each record includes a _link to its canonical URL
for (const activity of allActivities.data) {
  console.log(activity._link); // "/api/v2/default/me/caseactivities/phonecall/a1b2c3d4-..."
}

Paging through results

The API uses cursor-based paging. Each list response includes a page object:

{
  data: [...],           // records for this page
  page: {
    top: 25,             // page size
    next: "/api/v2/..." // full URL for next page (null on last page)
  }
}

Important: The page.next URL holds an opaque cursor (the position, including Dataverse's paging cookie). Always use page.next to advance — don't build a skip yourself, as Dataverse needs the cursor for correct positioning. It also carries your filter, select, expand, filterLogic and quick date filters, so later pages are filtered and shaped like the first. Follow it as given: don't append your query to it. (fetchPage() and eachPage() already do this.)

Fetch next page

Use fetchPage() to follow a page.next URL. It attaches your token, so it only follows URLs on the client's baseUrl origin — pass it the page.next the API returned, never a URL from anywhere else:

let page = await client.me.list<Case>("case", { top: 25 });
console.log(`Page 1: ${page.data.length} records`);

while (page.page.next) {
  page = await client.me.fetchPage<Case>(page.page.next);
  console.log(`Next page: ${page.data.length} records`);
}

Iterate all pages

Use eachPage() for a clean async iterator over every page:

for await (const page of client.me.eachPage<Case>("case", { top: 50 })) {
  for (const record of page.data) {
    console.log(record.ticketnumber, record.title);
  }
}

Collect all records

const allCases: Case[] = [];
for await (const page of client.all.eachPage<Case>("case", { top: 100 })) {
  allCases.push(...page.data);
}
console.log(`Total: ${allCases.length} cases`);

Get a single record

const result = await client.me.get("case", caseId, {
  select: ["title", "description", "statuscode", "customerid"],
});

const c = result.data;
console.log(c.title);             // "Network outage in building 3"
console.log(c._customerid_value); // GUID of the linked customer
console.log(c.statuscode_label);  // "In Progress"

Create a record (me scope only)

const result = await client.me.create("casenotes", {
  subject: "Follow-up call",
  notetext: "Spoke with customer — issue resolved.",
  objectid_incident: incidentId, // link to parent case
});

console.log(result.data.annotationid); // new note GUID

The API automatically binds contact and account relationship fields when creating records. For tables with auto-binding configured (like incident), you only need to provide content fields:

// Create a case — contact and account are auto-bound from your identity
const newCase = await client.me.create("case", {
  title: "VPN not connecting",
  description: "Getting timeout errors when connecting to corporate VPN.",
});

console.log(newCase.data.incidentid);   // new case GUID
console.log(newCase.data.ticketnumber); // auto-generated case number

You do not need to set primarycontactid or customerid_account — the API resolves these from your authenticated identity and binds them automatically.

Update a record

Available on all scopes (me, team, all):

const result = await client.me.update("case", caseId, {
  description: "Updated with latest findings",
});

console.log(result.data.modifiedon); // "2026-02-13T10:30:00Z"

Lookup (summary search)

Returns only summary fields (ID + display name) — no addresses, phone numbers, or sensitive details. Use for listing names, finding record IDs, or populating references safely.

const result = await client.me.lookup("contact", {
  search: "john",
  top: 10,
});

// Returns names and IDs only — no full contact details
for (const contact of result.data) {
  console.log(contact.fullname);
}

With types: any operation accepts a generic — client.me.lookup<Contact>("contact", ...), client.me.get<Case>("case", ...), etc.

Change tracking (cheap refetches)

Stay fresh without re-fetching whole lists — receive a delta of what changed (including edits made directly in Dataverse). The delta token lives on the client; the server holds no state.

changes() is the whole API. Call it with no token to seed (full current set + a token), then send the token back to get only what changed since:

// Seed once — drain: true follows a chunked large seed to completion for you
const seed = await client.me.changes("case", { drain: true });
// seed.changed = your current records, seed.deltaToken = save this

// Later — one small call returns only the delta
const delta = await client.me.changes("case", { deltaToken: seed.deltaToken, drain: true });
// delta.changed = created/updated records, delta.removed = deleted ids

Apply a delta to rows you already hold with the bundled pure helper:

import { mergeChanges } from "@truenorth-it/dataverse-client";
rows = mergeChanges(rows, delta, "incidentid"); // upserts changed, drops removed

Without drain, a large pull is delivered in chunks: keep calling with the returned deltaToken while hasMore is true. Requires the table to have change tracking enabled server-side. me/team are scoped to your records; multi-step tables serve all only. Available on client.me, client.team, client.all.

Recipe: delta-powered TanStack Query

Don't poll, and don't fight TanStack — let it decide when to fetch (mount, window focus, reconnect, invalidateQueries after a mutation) and use the delta to make every one of those refetches cheap. The query's data holds the rows and the token together; each refetch sends the token back, merges the delta into the previous rows, and stores the new token. Alt-tab back to the browser: the cached list renders instantly, and TanStack's normal focus refetch is a tiny delta call in the background — picking up external Dataverse edits (Power Automate, plugins, the DV UI) too.

import { useQuery, useQueryClient } from "@tanstack/react-query";
import { mergeChanges, ApiError } from "@truenorth-it/dataverse-client";

interface DeltaList<T> { rows: T[]; deltaToken: string }

function useDeltaList<T extends Record<string, unknown>>(
  table: string, queryKey: readonly unknown[], idKey: string,
) {
  const qc = useQueryClient();
  return useQuery({
    queryKey,
    queryFn: async ({ signal }): Promise<DeltaList<T>> => {
      const prev = qc.getQueryData<DeltaList<T>>(queryKey);
      try {
        const delta = await client.me.changes<T>(table, { deltaToken: prev?.deltaToken, drain: true, signal });
        return { rows: mergeChanges(prev?.rows ?? [], delta, idKey), deltaToken: delta.deltaToken };
      } catch (err) {
        // Delta tokens expire (Dataverse change-tracking retention) — reseed from scratch.
        if (prev && err instanceof ApiError && err.status >= 400 && err.status < 500) {
          const seed = await client.me.changes<T>(table, { drain: true, signal });
          return { rows: mergeChanges([], seed, idKey), deltaToken: seed.deltaToken };
        }
        throw err;
      }
    },
    select: (d) => d.rows,
  });
}

// Usage — refetches are deltas, so let TanStack refetch as eagerly as it likes:
const { data: cases } = useDeltaList<Case>("case", ["cases"], "incidentid");

That's the entire integration — no effects, no subscriptions, no cleanup. Because it's a plain useQuery, everything else composes as usual: errors surface on query.error, multiple components sharing the queryKey are deduped to one fetch, and mutations just call queryClient.invalidateQueries({ queryKey: ["cases"] }).

Notes:

  • Live while viewing? Add refetchInterval: 30_000 to the useQuery — still TanStack's decision, just configured. Skip it if focus/mutation freshness is enough.
  • Ordering: merged rows are not in server order — sort in select if the UI needs one (e.g. select: (d) => [...d.rows].sort(byCreatedOnDesc)).
  • Filtered views (["cases", { status: "open" }]): a delta row may not match the filter — keep one canonical per-table key like ["cases"] and derive filtered views from it in select or memos.
  • Persistence: with persistQueryClient, the token is persisted with the rows, so a returning session resumes with a delta instead of a full reload.
  • Already using SignalR? Don't double up — SignalR gives instant in-app updates; use the delta queryFn where external Dataverse edits need to show up on TanStack's refetch cadence.
  • This hook belongs in your app — the SDK stays framework-agnostic and just exposes changes() + mergeChanges().

Files and attachments

A note's attachment and an email's attachments are files. Their content never comes back in a response: list the files on a record, then ask for a short-lived link to one and navigate to it. Tables that support this have files: true in /schema.

const { value: files } = await client.me.files("emails", emailId);
// [{ fileId, fileName: "letter.pdf", mimeType: "application/pdf", size: 48213 }]

async function download(fileId: string) {
  const link = await client.me.fileLink("emails", emailId, fileId);
  window.location.assign(link.url); // downloads from storage; the link expires in minutes
}
  • Ask for the link when the user clicks, not ahead of time. Don't store it or keep it in a query cache: it stops working at link.expiresOn.
  • The file downloads as an attachment, straight from storage. Don't fetch it into the page or render it inline.
  • ApiError.status === 413 means the file is over the deployment's download limit. A 503 with code: "downloads_not_configured" means the deployment has no download storage, and code: "downloads_unavailable" means its storage is set up but failing. Show the citizen the same "downloads aren't available right now" message for both.
  • The same pair is on client.team and client.all. A note's own id is its fileId.

SharePoint documents

Tables whose /schema entry has documents: true keep a SharePoint folder per record. List what's in it:

const { data, page } = await client.me.documents("case", caseId);
// [{ id, name: "invoice.pdf", folder: "", isFolder: false, mimeType: "application/pdf",
//    size: 48213, createdon, modifiedon, ...the table's document columns }]

const photos = await client.me.documents("case", caseId, {
  folder: "Photos",
  filter: { field: "name", operator: "endswith", value: ".jpg" },
  orderBy: { field: "modifiedon", direction: "desc" },
});
  • It needs the table's documents permission (schema.documentsPermission, e.g. casedocuments), not just read on the record. A record you can't see is a 404.
  • Folders come back first, with isFolder: true; pass their path as folder to list them. Follow page.next with fetchPage for more.
  • ApiError.status === 503 with code: "sharepoint_unavailable" means SharePoint couldn't be read right now.
  • The same method is on client.team and client.all.

To download one, ask for a link when the user clicks and navigate to it at once:

const link = await client.me.documentLink("case", caseId, doc.id);
// { url, expiresOn, name, mimeType, size }
window.location.assign(link.url);

The link is a read-only storage URL for a copy of that one file, valid for a few minutes. It needs no sign-in and downloads as an attachment, so never store it, cache it or render the file inline. A document the list wouldn't show you (another record's, a folder, one the table's filters hide) is a 404. 503 comes with code: "sharepoint_unavailable", "downloads_not_configured" or "downloads_unavailable"; show the same "not available right now" message for all three.

To upload, on a table whose schema has documentsUpload:

const doc = await client.me.uploadDocument("case", caseId, file, { name: file.name, folder: "Photos" });
// the new document, in the documents() shape

file is a Blob (a File from an <input type="file">), an ArrayBuffer or a Uint8Array. uploadDocument makes three requests: the API checks the name, size and permission and answers a storage URL; the bytes go straight to that URL, never through the API and never with your token; then the API puts the file in SharePoint. So the API's request size limit doesn't apply, only the table's own (schema.documentsUpload.maxBytes).

  • It needs the documents create permission (casedocuments:create), which reading doesn't give, nor creating reading.
  • The name must have one of schema.documentsUpload.extensions and be a name, not a path. An existing file is never overwritten: SharePoint renames the new one, so use the answer's name.
  • Columns the table fixes for uploads (e.g. ShowOnPortal: true) are set by the API; you can't send them. For an upload invite's values (API 1.55.0), schema.documentsUpload gives columns ({ name, type }[], type null when untyped, without the fixed ones), libraries (names library may take; [] when it can't choose) and folderFixed / libraryFixed (the route sets that, so the invite can't).
  • A bad name or size is 400 / 413; a record you can't see 404; a table that takes no uploads 405; 409 documents_not_set_up when the record has no SharePoint folder and none can be made; ApiError.code === "upload_put_failed" when storage refused the bytes (often its CORS rule).
  • startDocumentUpload(table, id, { name, size, contentType, folder }) and completeDocumentUpload(table, id, uploadId) are the first and last steps, for callers that send the bytes themselves (PUT to url with headers, no Authorization).
  • All of these are on client.team and client.all too.

Invite links (one action, once, without an account)

Send someone a link that lets them do one thing, once, without signing up:

| To let them… | Call | The route must allow it | Sending needs | |---|---|---|---| | log a new case | createInvite("case", { operation: "create", contactId }) | schema.invites has create | case:invite + case:create | | update a case | createInvite("case", { operation: "update", id, fields }) | schema.invites has update | case:invite + case:write | | add a note to a case | createInvite("case", { operation: "create", id, target: "casenotes" }) | casenotes schema's invites has create | casenotes:invite + casenotes:create | | upload a document to a case | createInvite("case", { operation: "upload", id }) | schema.documentsUpload.invites | casedocuments:invite + casedocuments:create | | run a custom API action once | createInvite("rebook", { operation: "invoke", id, contactId, values }) | the action's definition has invites: true | rebook:invite + rebook:invoke |

Sending needs both permissions at the client's tier: add :team or :all to each (e.g. case:invite:team and case:write:team to send an update invite on client.team). The second is what you'd need to do it yourself, because a link never lets anyone do more than its sender could. values presets columns the invitee can't send: on the new row or the record (a note's subject, a flag on an update), or on an uploaded document's library columns (its title or type). An update invite must name its fields (a 400 otherwise); columns that decide who gets in (a contact's sign-in column, an account's join domain) are never offered. A new case is logged as contactId's, so the contact must be one you can see on that tier: yourself on /me, a contact of your company on /team.

const { link, token } = await client.team.createInvite("case", {
  id: caseId,
  operation: "create",       // "create" | "update" | "upload"
  target: "casenotes",       // a create on a record: the child table
  // fields: ["telephone1"], // an update: the columns they may change (required)
  // contactId,              // logging a new case: whose it is
  values: { subject: "Blue Badge" }, // optional preset values: set for them, they can't change them
  message: "Please add the photos you mentioned",
  email: "[email protected]", // optional: they must sign in as this address
  expiresInDays: 7,          // default 7, at most 30 (or the deployment's lower limit)
});

link is the scope's inviteUrl with the token in it (null when the scope has none). You get it only here: Dataverse keeps a hash of the secret, never the link, so send it on now. Set inviteUrl to put the token in the fragment (https://portal.example.gov.uk/invite#token={token}), so it never reaches server logs, Referer headers or analytics. On the page it opens, use the token:

const invite = createClient({ baseUrl: "https://api.dataverse-contact.tnapps.co.uk" })
  .invite(new URLSearchParams(location.hash.slice(1)).get("token")!);

const asked = await invite.describe(); // { operation, route, recordId, record, child, message, expiresOn, requiresSignIn, fields | upload }
if (asked.operation === "upload") {
  await invite.uploadDocument(asked.route, asked.recordId!, file, { name: file.name });
} else if (asked.operation === "update") {
  await invite.update(asked.route, asked.recordId!, { telephone1: "01632 960123" });
} else if (asked.operation === "invoke") {
  // asked.parameters lists what to send; asked.values were preset by the sender.
  const { data } = await invite.invoke(asked.route, { Slot: "2026-12-01T09:00:00Z" }, { id: asked.recordId });
} else if (asked.child) {
  await invite.create(asked.child, { subject: "Photos", notetext: "Attached as asked" },
    { parent: { table: asked.route, id: asked.recordId! } });
} else {
  await invite.create(asked.route, { title: "Broken streetlight", description: "Outside no. 12" });
}

The token goes in the X-Invite-Token header; the bearer token goes too when the client has getToken (needed when requiresSignIn). Send only the fields describe() lists; values are the ones the sender preset (show them, don't send them). An update's carry their current value, except on a requiresSignIn invite when the client isn't signed in as its address: sign in first to show them. record (API 1.38.0) names the record it acts on as a lookup does (a case's reference and title), on the same terms. Lookups are never accepted. A link works at most once: if the call fails with an error the link can be tried again, and an upload invite stages one file at a time. Errors carry ApiError.code: invite_not_found (wrong, expired or withdrawn, or not what the link is for), invite_used (already done), invite_sign_in_required, invite_wrong_account.

Invite batches (several asks, one link)

To ask one person for several things at once (a photo, a document, a note, their phone number), send them behind one link (API 1.49.0). Each step is what createInvite would send, plus a title the person sees; who it's for and when it expires are the whole batch's. Every step needs the permissions its own invite would, and if any step can't be sent, nothing is:

const { link } = await client.team.createInviteBatch({
  contactId,
  title: "Damp and mould repair: what we need",
  message: "To book the repair we need a few things from you.",
  steps: [
    { table: "case", id: caseId, operation: "upload", title: "Photo of the damp" },
    { table: "case", id: caseId, operation: "create", target: "casenotes", title: "When you're in" },
    { table: "contact", id: contactId, operation: "update", fields: ["telephone1"], title: "Best phone number" },
  ],
  expiresInDays: 14,
});

link is the scope's inviteBatchUrl with the token in it (e.g. https://portal.example.gov.uk/invite#batch={token}). On that page, inviteBatch(token) lists the steps, and step(id) is an ordinary invite client for one, so the code above serves each step:

const batch = createClient({ baseUrl: "https://api.dataverse-contact.tnapps.co.uk" })
  .inviteBatch(new URLSearchParams(location.hash.slice(1)).get("batch")!);

const { title, steps } = await batch.describe(); // each step: id, step, title, state ("open" | "done" | "unavailable")
const next = steps.find((s) => s.state === "open");
if (next?.operation === "upload") {
  await batch.step(next.id).uploadDocument(next.route, next.recordId!, file, { name: file.name });
}

An open step carries everything describe() gives for one invite. Each step works once (invite_used afterwards, perhaps from another tab: describe again), and the link keeps working for the rest until it expires. The requests send X-Invite-Batch-Token and X-Invite-Step instead of X-Invite-Token.

Public (unauthenticated) access

Tables with publicRead: true are available without authentication via client.public. Only list and get are supported — no writes, lookups, or aggregates.

// No getToken needed for public-only usage
const client = createClient({
  baseUrl: "https://api.dataverse-contact.tnapps.co.uk",
});

const result = await client.public.list("case", {
  select: ["title", "ticketnumber", "statuscode"],
  top: 10,
});

const record = await client.public.get("case", caseId);

Paging works the same as authenticated scopes:

for await (const page of client.public.eachPage("case", { top: 50 })) {
  for (const record of page.data) {
    console.log(record.title);
  }
}

client.public never sends an Authorization header, even if getToken is configured on the client. The other scopes (me, team, all) still require authentication.

Who am I

const me = await client.me.whoami();
console.log(me.fullname);   // "Jane Developer"
console.log(me.email);      // "[email protected]"
console.log(me.contactid);  // Dataverse contact GUID
console.log(me.accountid);  // Dataverse account GUID (if linked)

Register (self-service contact)

For a signed-in user who has no Dataverse contact yet, register() provisions their own. The email is taken from the verified token (never the arguments) — only name fields are accepted — and the call is idempotent. Requires the scope to have self-registration enabled (otherwise the API returns 403).

const { created, dataverseContact } = await client.me.register({
  firstname: "Jane",
  lastname: "Developer",
});
// created === true on first call; false (existing contact returned) thereafter

To let a joiner also pick which companies they work with, list the ones on their email domain and pass the chosen accountIds. Each becomes one contact (the parent-account model uses one contact per company), and every id is re-verified server-side to be on the caller's domain:

const { companies } = await client.me.claimableCompanies();
// companies → [{ accountId, name, websiteurl?, city? }, ...]

const joined = await client.me.register({
  firstname: "Jane",
  lastname: "Developer",
  accountIds: companies.map((c) => c.accountId),
});
// joined.companies → every company the caller is now linked to

Choices (option sets)

Choice fields (picklists) have their values managed in Dataverse. Fetch them for building dropdowns:

// All choice fields for a table
const allChoices = await client.choices("case");
// allChoices.fields.statuscode → [{ value: 1, label: "In Progress" }, ...]
// allChoices.fields.prioritycode → [{ value: 1, label: "High" }, ...]

// Single field
const statusChoices = await client.choices("case", "statuscode");
// statusChoices.choices → [{ value: 1, label: "In Progress" }, ...]

Schema

// All table schemas
const schemas = await client.schema();

// Single table
const caseSchema = await client.schema("case");
console.log(caseSchema.fields);       // field definitions with types + descriptions
console.log(caseSchema.defaultFields); // fields returned when no `select` is specified

Custom APIs (actions & functions)

Functions are read-only (invokeFunction, GET), actions have side effects (invokeAction, POST). Call one on the tier its definition lists — the tier decides what the server checks:

| Call it with | Route | The server checks | |---|---|---| | client.public.invokeFunction / invokeAction | /public/actions/{name} | nothing — no token is sent | | client.me.invokeFunction / invokeAction | /me/actions/{name} | {name}:invoke, and that the record is yours | | client.team.invokeFunction / invokeAction | /team/actions/{name} | {name}:invoke:team, and that the record is your company's | | client.all.invokeFunction / invokeAction | /all/actions/{name} | {name}:invoke:all |

Pass the record as recordId — for a bound API and an unbound one alike. The server writes it into the right parameter itself, and refuses the call if the body names a different record. A 404 on a tier means the API doesn't answer there (or the record isn't yours); a 401 from client.public.invoke* means the API isn't public — use the signed-in tier, don't make the API public.

// CloseIncident on one of my cases. The case id goes in recordId; the server
// writes it into [email protected].
await client.me.invokeAction("close-incident", {
  recordId: caseId,
  body: {
    IncidentResolution: { subject: "Resolved online" },
    Status: 5, // Problem Solved
  },
});

// The same for a case of my company
await client.team.invokeAction("close-incident", { recordId: caseId, body: { IncidentResolution: { subject: "Done" }, Status: 5 } });

// A caller-scoped function: no record — the server tells it who is asking
const upcoming = await client.me.invokeFunction<{ Bookings: string }>("my-upcoming-bookings");

// An API whose target has a recordKey also takes the record's reference number —
// here a case's ticket number. The server checks the case is mine and writes
// the ticket number (or the GUID, if that's what the API takes) itself.
await client.me.invokeAction("add-case-note", { recordId: "CAS-01234-X1Y2", body: { Note: "Called back" } });
// Invoke a public function with query parameters
const result = await client.public.invokeFunction<{ result: TimeInfo[] }>(
  "expand-calendar",
  { recordId: calendarId, params: { Start: startIso, End: endIso } },
);
console.log(result.data?.result); // TimeInfo[]
console.log(result.apiType);      // "function"

A definition can also supply values itself (API 1.30.0+). A parameter with a default can be left out of body / params, and the server sends the default. A parameter in the definition's fixedParameters is always sent with the fixed value: anything your client sends for it is overwritten. The API's OpenAPI description lists them ("Always sent as: …").

Custom APIs defined before tiers existed still accept a signed-in call on /public/actions/{name}, but that route is deprecated — move those calls to client.me / client.team / client.all. Until such an API's definition adds tiers, an unbound one still reads its record from the body (e.g. "[email protected]": "/incidents(<id>)"), not from recordId.

A public custom API needs no token at all, so a client without getToken is enough:

const client = createClient({
  baseUrl: "https://api.dataverse-contact.tnapps.co.uk",
  scope: "citizenbooking",
});

const result = await client.public.invokeFunction("expand-calendar", {
  recordId: calendarId,
  params: { Start: start, End: end },
});

Schema-driven field model (toFieldModel)

Some tables store a whole submitted form as one JSON blob (e.g. Service Builder's lcc_requestdata). Rather than have every front-end parse that raw JSON, pair it with its JSON Schema and let the SDK produce a clean, labelled tree.

toFieldModel(schema, value) is a generic, pure function — hand it any JSON Schema and any matching JSON value. It walks the schema's properties alongside the value and returns a FieldNode[] you can render field-by-field.

import { toFieldModel } from "@truenorth-it/dataverse-client";

// 1. Fetch the JSON Schema (a custom API returns it, e.g. lcc_GetServiceSchema)
const schema = await client.public.invokeAction("service-schema", {
  body: { ServiceType, Version },
});

// 2. Transform the raw record data against it (a JSON string is parsed for you)
const fields = toFieldModel(schema.data, row.lcc_requestdata);

Each FieldNode is:

interface FieldNode {
  key: string;              // property key, e.g. "email-address"
  label: string;            // schema title/description, else a prettified key
  type: "string" | "number" | "integer" | "boolean" | "date" | "date-time"
      | "choice" | "object" | "array" | "unknown";
  value?: unknown;          // scalar value (absent for object/array)
  displayValue?: string;    // ready-to-show string (booleans as "Yes"/"No", etc.)
  required?: boolean;       // marked required by the parent schema
  options?: string[];       // for choice: the allowed labels (from `enum`)
  children?: FieldNode[];   // for object: nested field nodes
  items?: FieldNode[][];    // for array: one FieldNode[] per element
}

How shapes map:

  • scalar → { type, value, displayValue } (label from the schema description).
  • nested object (contact, location) → type: "object" with children.
  • array (location-list, metadata) → type: "array" with items — one node-set per element.
  • enum → type: "choice"; the value is already the label, and options lists the choices.
  • data key not in the schema → kept and rendered (object/array expanded, scalar as-is) rather than dropped.

Rendering is left to you — walk the tree and emit labels + values, recursing into children and items. Nodes come back in the schema's declared property order, then any extra data keys.

Generate a TypeScript type from a service form (generate-service)

toFieldModel is the runtime side (shape any value for generic rendering). Its compile-time twin generates a typed interface for a specific service, so a bespoke single-service UI gets autocomplete + type-checking on JSON.parse(lcc_requestdata).

# one service → stdout (redirect where you want it)
npx dataverse-client generate-service --url https://api.dataverse-contact.tnapps.co.uk \
    --scope servicebuilder --service report-a-flickering-street-light > src/services.generated.ts

# every service in the scope → one file with all interfaces + a lookup map
npx dataverse-client generate-service --url https://api.dataverse-contact.tnapps.co.uk \
    --scope servicebuilder --all -o src/services.generated.ts

The CLI fetches the form's JSON Schema from the scope's service-schema custom API (lcc_GetServiceSchema, public — no auth), then emits:

export interface ReportAFlickeringStreetLight {
  /** Your contact details */
  "primary-contact"?: {
    /** Email address */
    "email-address": string;              // required → non-optional
    "preferred-contact-method"?: "Email" | "Phone" | "Post";  // enum → union
  };
  /** What is wrong? */
  "fault-type": "Flickering" | "Always on" | "Not working" | "Damaged";
  /** Photos */
  photos?: Array<string>;
}

With --all you also get a slug→type lookup and a ServiceType union, so a generic list can narrow by service type:

export interface ServiceRequestDataByType {
  "report-a-flickering-street-light": ReportAFlickeringStreetLight;
  "missed-bin": MissedBin;
}
export type ServiceType = keyof ServiceRequestDataByType;

const data = JSON.parse(row.lcc_requestdata) as ServiceRequestDataByType[typeof row.lcc_servicetype];

Progress logs go to stderr, the generated TypeScript to stdout — so > file.ts captures only the types. Programmatic equivalent (no fetch): schemaToInterface(schema, name) and generateServiceTypes(services).

Query options

Used by list():

| Option | Type | Description | |--------|------|-------------| | select | string[] | Fields to return | | top | number | Page size (1-100) | | skip | number | Initial offset (rarely needed). For paging through results, always use fetchPage(page.next) or eachPage() instead — Dataverse requires the cursor from page.next, not just a skip offset. | | orderBy | OrderBy | Sort field and direction — { field: "createdon", direction: "desc" }. Direction defaults to "asc". | | filter | FilterCondition \| FilterCondition[] | Typed filter conditions — { field, operator, value }. Operators: eq, ne, gt, ge, lt, le, contains, startswith, endswith. | | filterLogic | "and" \| "or" | How to combine multiple filters (default: "and") | | expand | string | Expand related lookups | | subtype | string | Activity subtype filter (e.g. "phonecall", "email", "task", "all") — only for activity tables | | created | string | Quick filter on creation date — e.g. "today", "7d", "thismonth", "2026-01-01..2026-02-01" | | modified | string | Quick filter on last-modified date (same formats as created) | | parent | string | A parent record's GUID: only its children, for child tables (list() / eachPage() only) — see List one parent's children |

documents() takes select, top, skip, orderBy, filter, filterLogic, created, modified and folder.

lookup() accepts the same options plus:

| Option | Type | Description | |--------|------|-------------| | search | string | Search term to filter by name/title |

get() accepts only select and expand.

Quick date filter values

| Format | Examples | Description | |--------|----------|-------------| | Named period | today, yesterday, thisweek, lastweek, thismonth, lastmonth, thisyear | Human-friendly period presets | | Relative | 1h, 24h, 7d, 30d, 90d | Sliding window from now | | Date range | 2026-01-01..2026-02-01, 2026-01-01.., ..2026-02-01 | Explicit date range (inclusive start, exclusive end) |

// Cases created in the last 7 days
const recent = await client.me.list<Case>("case", { created: "7d" });

// Cases modified today
const updated = await client.me.list<Case>("case", { modified: "today" });

// Combine with regular filters
const urgentRecent = await client.me.list<Case>("case", {
  created: "thismonth",
  filter: { field: "prioritycode", operator: "eq", value: 1 },
});

The SDK resolves these client-side — dates are converted into standard filter conditions before the request is sent. This means quick dates work with any server version, even older deployments that don't support the created/modified parameters natively.

Standalone utility

The resolution logic is also exported for direct use:

import { resolveQuickDate, quickDateToFilters } from "@truenorth-it/dataverse-client";

resolveQuickDate("7d");
// → { ge: "2026-02-08T12:00:00.000Z" }

resolveQuickDate("today");
// → { ge: "2026-02-15T00:00:00.000Z", lt: "2026-02-16T00:00:00.000Z" }

quickDateToFilters("createdon", "thisweek");
// → ["createdon ge 2026-02-09T00:00:00.000Z"]

Error handling

import { ApiError } from "@truenorth-it/dataverse-client";

try {
  await client.me.list("case");
} catch (err) {
  if (err instanceof ApiError) {
    console.error(err.status);  // HTTP status code
    console.error(err.body);    // Error response body
    console.error(err.code);    // Stable reason, when there is one (see below)
  }
}

| Status | Meaning | |--------|---------| | 401 | Missing or invalid token | | 403 | Insufficient permissions | | 404 | Unknown table or contact not found |

Some 403s say why the person can't get in, with a stable code so you can show your own wording instead of matching on message:

| code | Meaning | |--------|---------| | access_withdrawn | Their contact was deactivated by an administrator. | | contact_not_enabled | Their contact exists but doesn't meet the scope's contact filters, so it isn't set up for online access yet. |

if (err instanceof ApiError && err.code === "contact_not_enabled") {
  showMessage("Your account isn't set up for online access yet. Please contact us.");
}

A cancelled request rejects with AbortError instead — see Cancelling requests.

Real-time notifications

The SDK includes a React hook that connects to Azure SignalR and automatically invalidates TanStack Query caches when data changes on the server. When another user (or an MCP client) creates or updates a record, your portal's UI refreshes instantly — no polling required.

Prerequisites

Install the SignalR client as a peer dependency:

npm install @microsoft/signalr

The API must have SIGNALR_CONNECTION_STRING configured. When it's not set, negotiate() returns a 404 and the hook gracefully does nothing.

Negotiate

The client exposes a negotiate() method that exchanges your Bearer token for a SignalR connection token:

const { url, accessToken } = await client.negotiate();

You don't usually call this directly — the useRealtime hook handles it.

useRealtime hook

import { useCallback } from "react";
import { useQueryClient } from "@tanstack/react-query";
import { createClient, useRealtime } from "@truenorth-it/dataverse-client";

function App() {
  const client = useApiClient();
  const queryClient = useQueryClient();

  const negotiate = useCallback(() => client.negotiate(), [client]);

  const { connected, error } = useRealtime({
    negotiate,
    queryClient,
  });

  // connected: true when the SignalR connection is active
  // error: last error message, or null
}

That's all you need. When a dataChanged event arrives (e.g. for table "case"), the hook automatically calls queryClient.invalidateQueries() for the matching query keys. TanStack Query refetches in the background and your UI updates.

Options

interface RealtimeOptions {
  negotiate: () => Promise<{ url: string; accessToken: string }>;
  queryClient: QueryClient;
  tableQueryKeys?: Record<string, readonly (readonly unknown[])[]>;
  onEvent?: (event: DataChangeEvent) => void;
  enabled?: boolean; // default: true
}

| Option | Description | |--------|-------------| | negotiate | Function that returns a SignalR token (from client.negotiate()) | | queryClient | TanStack React Query client instance | | tableQueryKeys | Custom mapping of table names to query key prefixes (see below) | | onEvent | Optional callback for every data change event | | enabled | Set to false to disable the connection |

Default table-to-query-key mapping

The hook ships with sensible defaults:

{
  case:            [["cases"], ["aggStats"]],
  casenotes:       [["caseNotes"]],
  caseactivities:  [["caseActivities"]],
  caseemails:      [["caseActivities"]],
  casephonecalls:  [["caseActivities"]],
  casetasks:       [["caseActivities"]],
  caseappointments:[["caseActivities"]],
}

Override or extend for your own tables:

useRealtime({
  negotiate,
  queryClient,
  tableQueryKeys: {
    // Keep defaults
    case: [["cases"], ["aggStats"]],
    casenotes: [["caseNotes"]],
    // Add your custom tables
    invoice: [["invoices"]],
    project: [["projects"], ["projectStats"]],
  },
});

DataChangeEvent

Events received from the server:

interface DataChangeEvent {
  table: string;                              // e.g. "case", "casenotes"
  action: "created" | "updated" | "deleted";
  recordId: string;                           // GUID of the affected record
  timestamp: string;                          // ISO 8601
  actor?: string;                             // email of the user who made the change
}

Response field patterns

These patterns apply to all API responses, whether or not you use generated types.

Choice and lookup field siblings

Choice fields (picklists) include a _label sibling with the display text:

record.statuscode        // 1 (numeric value)
record.statuscode_label  // "In Progress" (display text from Dataverse)

Lookup fields include a _value sibling with the referenced record's GUID:

record._customerid_value      // "a1b2c3d4-..." (GUID of linked customer)
record._primarycontactid_value // "e5f6g7h8-..." (GUID of linked contact)

Stage progress (RecordProgress)

A table whose schema declares a business process (schema.progress[]) returns, on every row, a progress object (or null) saying where the record is in its Dataverse business process flow. It is derived by the API, always present, read-only and not selectable — so it is not part of <Table>Field — and the generated interface types it as RecordProgress | null:

import type { RecordProgress } from "@truenorth-it/dataverse-client";

const { data } = await client.me.list<Case>("case");
for (const c of data) {
  const p: RecordProgress | null | undefined = c.progress;
  if (!p) continue;                       // no process, or a record that predates it
  const current = p.activeStage?.name;    // officer wording — map it to your own
  const done = p.stages.filter((s) => s.reached).length;
  console.log(`${c.title}: ${current} (${done}/${p.stages.length})`);
}

Regenerate types after the API starts declaring progress — the property only appears when the schema carries a binding.

TableName union (generated types only)

If you use codegen, the generated file includes a TableName union of all valid table names and aliases:

import type { TableName } from "./dataverse.generated";

// Type-safe table parameter — accepts "case", "case", "contact", etc.
function fetchRecords(table: TableName) {
  return client.me.list(table);
}

Exported types

All types are importable from the main package:

import type {
  // Client & scope interfaces
  DataverseClient, ScopeClient, MeScopeClient, PublicScopeClient, ClientConfig,
  // Query types
  QueryOptions, LookupOptions, OrderBy, FilterOperator, FilterCondition,
  // Response types
  PaginatedResponse, SingleResponse, ActionResponse, WhoamiResponse,
  // Schema & choices
  TableSchema, SchemaField, ExpandSchema, ProgressSchema, Choice,
  FieldChoicesResponse, TableChoicesResponse,
  // Stage progress (business process flows)
  RecordProgress, RecordProgressStage, RecordProgressState,
  // Codegen types (for programmatic usage)
  SchemaResponse, SchemaTableInput,
  // Field model (toFieldModel)
  JsonSchema, FieldNode, FieldType,
  // Service-schema type generator (schemaToInterface / generateServiceTypes)
  ServiceSchemaInput,
  // Errors
  ApiErrorBody,
  // Real-time notifications
  NegotiateResponse, DataChangeEvent, RealtimeOptions, RealtimeState,
} from "@truenorth-it/dataverse-client";

// Pure transformers (tree-shakeable)
import {
  toFieldModel, mergeChanges, generateTableTypes,
  schemaToInterface, generateServiceTypes,
} from "@truenorth-it/dataverse-client";

// React hook (requires @microsoft/signalr peer dependency)
import { useRealtime } from "@truenorth-it/dataverse-client";

Table-specific types come from your generated file:

import type { Case, Contact, TableName } from "./dataverse.generated";

Requirements

  • Node.js 18+
  • An async function that returns a Bearer token — typically MSAL for Entra External ID, but any OIDC client works (optional if using only client.public)
  • Access to a deployed Dataverse Contact API instance

License

ISC