@smals-belgium/shared-pseudo-tools-js
v0.0.4
Published
This document describes how to build, test, package and consume `@smals-belgium/shared-pseudo-tools-js`.
Readme
NPM package guide
This document describes how to build, test, package and consume @smals-belgium/shared-pseudo-tools-js.
Package purpose
@smals-belgium/shared-pseudo-tools-js is a framework-agnostic TypeScript/RxJS wrapper around @smals-belgium-shared/pseudo-helper.
It provides:
- pseudonymization and identification APIs
- automatic batching
- in-flight request deduplication
- TTL caching
Uint8Arraysupport- Jest-tested framework-agnostic services
Install from the registry
npm install @smals-belgium/shared-pseudo-tools-jsInstall the underlying helper expected by the package:
npm install @smals-belgium-shared/pseudo-helperLocal development workflow
Install dependencies
npm installRun tests
npm testRun coverage
npm run test:coverageBuild
npm run buildLocal package testing with npm pack
Use npm pack to test the exact package contents that would be published.
npm run build
npm packThis creates an archive such as:
smals-belgium-shared-pseudo-tools-js-0.0.1.tgzInstall it in a consuming project:
npm install ../path/to/smals-belgium-shared-pseudo-tools-js-0.0.1.tgzAngular consuming applications
When testing a local .tgz package in Angular, stop the dev server, reinstall the package, clear Angular's cache and restart the dev server:
npm install ../path/to/smals-belgium-shared-pseudo-tools-js-0.0.1.tgz
npx ng cache clean
npm startIf a change appears to have no effect, verify that the compiled file inside node_modules/@smals-belgium/shared-pseudo-tools-js contains the expected change, then clear Angular's cache again.
Pre-publish checklist
Before publishing a new version:
npm test
npm run test:coverage
npm run build
npm pack --dry-runCheck that the package contains only the expected build artifacts and documentation.
Recommended checks:
- no debug
console.warn/console.error - no framework-specific imports in the library services
- no Angular dependency in framework-agnostic code
- tests pass with Jest
- README examples still match the public API
CHANGELOG.mdcontains the release notes- package version has been bumped if publishing a new version
Publishing
Use your configured Smals/npm registry and access policy.
npm publishFor scoped packages, use the appropriate access level required by your registry setup.
npm publish --access restrictedor, if the package is intentionally public:
npm publish --access publicRecommended dependency model
The package is framework-agnostic. Angular should not be a dependency of this library.
The consuming application must provide the PseudonymisationHelper instance passed to PseudoService.
Recommended package expectations:
@smals-belgium-shared/pseudo-helpermust be available to the consumer- RxJS must be compatible with the library build
- Angular-specific integration should live in the consuming application, not inside this package
Minimal usage
import { PseudoService } from "@smals-belgium/shared-pseudo-tools-js";
import { PseudonymisationHelper } from "@smals-belgium-shared/pseudo-helper";
const helper = new PseudonymisationHelper("https://pseudo.example.be");
const service = new PseudoService(helper, {
domain: "patient",
curve: "secp256k1",
audience: "consumer",
bufferSize: 100,
});
service.toAsn1Compressed("12345678901").subscribe(console.log);Troubleshooting
Changes are visible in node_modules but not at runtime
In Angular consuming projects, the dependency optimizer/cache can serve a previous build. Stop the dev server and run:
npx ng cache cleanThen restart the application.
TTL cache tests are flaky
Do not enable Jest fake timers globally. Keep fake timers local to specs that test RxJS timing. TTL cache tests should either mock @isaacs/ttlcache or avoid testing the internals of the external dependency.
Observables stay pending in a consuming application
Check that the package version actually loaded by the app is the rebuilt version. Then verify that the batch service does not keep completed observables in a persistent internal cache. The stable implementation deduplicates only in-flight subjects and removes them after dispatch.