A TypeScript helper library for Microsoft Dataverse / Dynamics 365 Web API. Supports CRUD operations, Fetch XML, batch requests, Dataverse Search API (query/suggest/autocomplete), entity metadata, file fields, background operations, and actions/functions. Works in both Node.js and browser environments.
- Type: TypeScript library (
dynamics-web-apiv2.x) targeting Node.js and Browser - Entry:
src/dynamics-web-api.ts— exportsDynamicsWebApiclass with all types - Build output:
dist/(CJS, ESM, browser bundles +.d.ts),lib/(transpiled source for tests)
| Script | What |
|---|---|
npm test |
Build (tsc) → run Mocha tests. This is the full verification. |
npm run tsc |
Typecheck only (tsc --noEmit) |
npm run build |
Clean → transpile lib → bundle dist (CJS/ESM/browser) → generate types → copy .d.ts → add banner |
npm run coverage |
Clean coverage dir → build → run nyc mocha → LCOV report |
npm run format |
Prettier: src/**/*.ts + tests/**/*.js |
- Tests live in
tests/as.spec.tsfiles, run via Mocha +ts-node/register - Every test file sets
global.DWA_BROWSER = falsebefore running — this controls the runtime branch between XHR (browser) and Nodehttpclient - HTTP mocking: nock for Dataverse API endpoints
- Fixtures in
tests/stubs.ts— includes entity data, mock responses, URLs for all API versions (v8.0–v9.2 + search v1.0/v2.0) - Tests run in
lib/(transpiled fromsrc/), not raw.ts
DynamicsWebApiclass wraps an internalDataverseClient(private field)DataverseClientholds config +isBatchstate and delegates tomakeRequestinsrc/client/RequestClient.ts- Request execution splits on
global.DWA_BROWSER:- Browser:
src/client/xhr.ts(XMLHttpRequest) - Node:
src/client/http.ts(Nodehttp/httpsagents, proxy support)
- Browser:
src/requests/— one file per API operation (create, retrieve, update, delete, batch, search, metadata, etc.)src/requests/index.ts— barrel re-exports everything consumed by the main class- Build:
tsccompilessrc/→lib/;esbuildbundlessrc/dynamics-web-api.ts→dist/(multiple platforms) global.DWA_BROWSERis defined at build time byutils/bundle.mjsvia esbuilddefine
build-test-coverage.yml— main CI: runs ondevpush/PR. Tests across Node 18/20/22/24, coverage + Coveralls on Node 22 onlybranch-build-test-coverage.yaml— branch CI: runs onfeature/**,bugfix/**,hotfix/**push/PR. Same matrix, coverage on Node 22 only
- Prettier: 4-space indent (from
.prettierrc/ default) - Tests:
.spec.tsintests/,tests/requests/subfolder mirrorssrc/requests/structure - No lint step — only
tsctypecheck +prettier --write preversionrunsnpm test;versionrunsnpm run build
- Full API reference and usage examples:
.github/README.md(the rootREADME.mdis a minimal redirect)
- Never remove
global.DWA_BROWSER = falsefrom test files — the library branches on this at runtime src/types.tsis not included in the build output — all exported types live insrc/dynamics-web-api.tslib/exists only for tests (Mocha reads from there, not fromsrc/ordist/)- Build order matters:
clean → build:* → postbuild (copyfiles + banner). Don't reorder - Tests that call
executeBatch()expectstartBatch()to have been called first (stateful client)