This file orients agents (Claude or others) working on hds-lib-js. It deliberately does not duplicate information that already lives in this repo — it links you to the right document for each concern. Read this first; then read the linked docs as you start a task.
Before touching code, read these in order:
- README.md — what the package is, public surface, dev commands. Also lists the badge URLs and the public docs site.
- docs/index.md plus the published site at https://healthdatasafe.github.io/hds-lib-js/ — full user-facing API documentation. The pages under
docs/are the source for that site. - docs/getting-started.md — install + bootstrap (
settings.setServiceInfoURL,initHDSModel). - docs/hds-model.md —
HDSModel,itemsDefs,streams,eventTypes,datasources,authorizations,conversions,converters,appStreams,Overload. - docs/app-templates.md + AppTemplates.md —
AppManagingAccount/AppClientAccount/Collector/CollectorClient/CollectorRequest/Contact. The legal/consent-flow shape used by every HDS app. - docs/settings.md — global library settings (
settings.setServiceInfoURL, init order). Distinct from per-userHDSSettings. - docs/localization.md —
localizableTextshape andlocalizeText(...)resolution rules. - docs/toolkit.md —
StreamsAutoCreate, reminders, duration parsing, event formatters. - docs/utilities.md —
HDSLibError, misc helpers. - CHANGELOG.md — every behaviour change worth knowing about, in reverse chronological order. Read the most recent entries before estimating an API.
Anything not covered above is either internal or new; in that case, read the source under ts/ and add docs as you go (do not let new public surface escape docs/).
hds-lib-js wraps and extends pryv JS lib. Most of what this library does is express HDS-specific patterns on top of standard Pryv objects. Before designing anything that touches Pryv data shapes, read the corresponding section of the Pryv API reference.
Authoritative sources:
- Data in Pryv (read this first if you've never worked with Pryv): https://pryv.github.io/data-in-pryv/ — narrated walk-through of streams, events, accesses, and how they fit together. The clearest mental model document Pryv publishes.
- Pryv concepts overview: https://pryv.github.io/concepts/
- Pryv API reference: https://pryv.github.io/reference/ (canonical home;
api.pryv.com/reference/redirects here). - Pryv event-types catalogue: https://pryv.github.io/event-types/
- Pryv guides — pick the relevant one, e.g. data-modelling, app-guidelines, webhooks, custom-auth, consent, audit-logs.
Key concepts you will encounter constantly here:
| Pryv concept | Why it matters in hds-lib | Reference |
|---|---|---|
| Service info | Discovery endpoint published by every Pryv platform. settings.setServiceInfoURL(url) is the only mandatory bootstrap. The HDS data-model URL is published as an assets.hds-model override on top of this. |
Service info |
| Streams | Tree of clinical-domain containers. The HDS data-model defines the stream tree; HDSModel.streams exposes it. Permissions are stream-scoped and inherit down the tree. |
Stream · methods |
| Events | The actual data points. Each event has streamIds, type, content, time, optional duration, integrity. HDS items map (streamId × type) → an HDSItemDef. |
Event · methods |
| Event types | Schema + unit. HDS event types live in data-model/definitions/eventTypes/; Pryv's catalogue of standard types is at the link. HDSModel.eventTypes.getEventTypeSymbol(type) resolves the unit. |
Event-types catalogue |
| Accesses & permissions | personal, app, shared. App auth produces an app access; Collector flows produce shared accesses. Levels: read / contribute / manage. Many HDS bugs come from confusing these. |
Access · methods |
| Authentication / app auth | app-web-auth3-hds drives the OAuth-like flow. The HDS Application / AppClientAccount / AppManagingAccount classes wrap pryv.Browser.AuthController. |
Auth request · authenticate-your-app |
Methods (events.get, events.create, ...) |
The API verbs. HDSConnection wraps pryv.Connection and adds apiOne(method, params). |
Methods · method-ids |
| WebSockets / Socket.io / monitor | Real-time event change feed. MonitorScope here is a thin wrapper around the Pryv socket layer. |
Call with WebSockets · Subscribe to changes (WebSockets) |
| Integrity | Per-event integrity: "EVENT:0:sha256-..." hash. Don't strip or recompute manually. |
Integrity |
| HF events | High-frequency event format (used by some bridges). Not common in HDS apps yet. | HF events · HF series |
If a piece of code seems to be reinventing one of the concepts above, stop and check whether the Pryv lib already exposes it. The right answer is almost always "use the Pryv primitive directly."
hds-lib-js sits at the centre of an ecosystem. Changes here ripple. Know the dependents before you change a public type.
- data-model (
@hds/data-model) — the YAML-defined items / streams / event types this library loads at runtime. The library never bundles the data-model; it fetchespack.jsonvia service-info. Design rules (item naming, scale-hook placement, stream tree, etc.) are indata-model/AGENTS.md, and the YAML lives underdata-model/definitions/. - hds-forms-js — React form renderers for
HDSItemDef. Re-exports several types fromhds-lib(e.g.appTemplates.ItemLabels,appTemplates.ItemCustomization). When you change those types, type-checkhds-forms-jstoo. - app-web-auth3-hds — auth flow used by every HDS app. Treat the public API surface as a contract.
- lib-bridge-js — base library for HDS server-side bridges; same compatibility concerns as any consumer.
These are short reminders. The detail lives in the linked source.
"type": "module","module": "nodenext". All imports use explicit.ts/.jsextensions.- TypeScript source under
ts/is the source of truth. Tests run directly from source (Node 24 type stripping);npm testdoes not need a build. - The package ships compiled output from
js/(built bynpm run prepare→tsc). Consumers pulling viagit+https://...hit thepreparehook on install. Never publish withoutjs/compiled. - Webpack bundle in
dist/(built bynpm run build) is for the browser test runner only. Do not import fromdist/in code. pryvis consumed viats/patchedPryv.ts— declaration merging (const + namespace) sopryvis both value and type namespace. Do not importpryvdirectly anywhere else; always go throughpatchedPryv.ts.
Every value/type intended for external consumption is exported from ts/index.ts. If a consumer needs something that is not there, add the export and document it under docs/ — do not let consumers reach into deep paths.
tests/— mocha + nodeassert. One file per concept (apptemplates.test.js,eventToShortText.test.js,itemLabels.test.js, ...). Most tests loadpack.jsonfrom the deployedmodel.datasafe.devover HTTP, so the test runner needs network access.tests-browser/— same suites compiled for the browser test runner. Run viabackloop.dev.- New tests go next to similar existing ones. New behaviour without a test is not done.
- Bump
versioninpackage.jsonfor every change that consumers can observe. - Add a
## [x.y.z] - YYYY-MM-DDblock in CHANGELOG.md. Group changes underAdded/Changed/Removed. Keep the wording concrete (one bullet = one observable change). - Consumers pin to git URLs, not npm versions, but the version + changelog is still how humans read the diff.
tscstale output:tscmay skip re-emitting a.jsfile if it already exists and didn't notice an internal change. Afternpm run prepare/npm run build:ts, verify the relevant file injs/actually contains your change before committing. If not, delete the stalejs/<path>.jsand re-run.- Vite cache in consumer apps: when you change a public type or export and a consumer app (Vite-based) doesn't pick it up, clear
<consumer>/node_modules/.viteand restart the dev server. - npm-link traps: when an HDS app is npm-linked to
hds-lib, both the app and any nested package (e.g.hds-forms-js'ssrc-test-app/) must link the samehds-libto avoid duplicate singletons (settings, model). If you see "two HDSModels" symptoms (e.g.getHDSModel()returning empty), this is the cause. Runcd _local && npm run check-links && npm run verify-live-sourceto diagnose. Full methodology:_claude-memory/conventions.md § Live cross-repo development — quickstart+_plans/49-local-dev-dependency-graph-done/PLAN.md. exports.importMUST point at TS source (./ts/index.tshere). Vite resolves theimportcondition in dev mode; pointing at compiled JS causes downstream libs (hds-forms-js, hds-react-timeline) to inline a second copy ofhds-lib→ duplicate-singleton bug. Verify withcd _local && npm run verify-live-source.- Initialization order: in apps that call
initBoiler(name, configDir)(server side) orpryv.Browser.AuthController(client side), do so before anygetHDSModel()/HDSSettingslookup.
When extending appTemplates/ for templates that declare custom fields,
system-stream features, or any clientData.hds*Field declarations, read
ts/appTemplates/CUSTOM-FIELDS-AND-SYSTEM.md
first. It covers the clientData schemas, parent-chain inheritance, sandbox
prefix rule, three stream-reference modes, and the helper API
(resolveStream*, streamCustomFieldToVirtualItem, loadTemplate).
- For a Pryv question: read the Pryv API reference, do not invent.
- For an HDS data-model question: read
AGENTS.mdand the YAML underdefinitions/in healthdatasafe/data-model. - For a forms / UI question: read
README.mdand thesrc/components/tree in healthdatasafe/hds-forms-js.
If the answer to a question is not in any of these places, that is a documentation bug — open an issue (or PR an addition to docs/) rather than guessing.