A rigorous, open-source SDK that provides HIPAA compliance primitives for TypeScript backends. phivault-core enforces strict boundaries out of the box, ensuring that PHI (Protected Health Information) is appropriately explicitly flagged, boundary transitions are verified against Business Associate Agreements (BAAs), and comprehensive audit logging is built-in.
This repository holds version 0.0.0 as an internal foundational architecture.
The following example demonstrates how a consumer application integrates and uses @phivault/core and @phivault/nestjs.
First, explicit metadata decorators tag which fields map to PHI.
import { PHI } from '@phivault/core';
// Consumer's entity representing patient data
export class Patient {
@PHI()
name: string;
@PHI({ category: 'identifier' })
ssn: string;
email: string; // Not classified as PHI: no auditing boundary enforced automatically by framework
}Data entering or leaving the system via third-party systems requires an explicit destination vendor and tracked data flow.
import { Injectable } from '@nestjs/common';
import { PHIBoundary } from '@phivault/core';
import { Patient } from './patient.entity';
// Consumer's service interfacing with an external provider
@Injectable()
export class PaymentService {
@PHIBoundary({ vendor: 'stripe', dataFlow: ['name'] })
async charge(patient: Patient) {
// Logic bridging to Stripe API...
return patient.name;
}
}At the NestJS entry point, initialize the module. The HddModule automatically enforces strict boot-time BAA resolution checks on all @PHIBoundary methods before starting the application, avoiding runtime data leakages to unregistered vendors.
import { Module } from '@nestjs/common';
import { HddModule } from '@phivault/nestjs';
import { PaymentService } from './payment.service';
// Optionally define a custom slack webhook or tracking logger
const slack = {
send: (violation) => console.error('Violation reported to slack:', violation)
};
@Module({
imports: [
HddModule.forRoot({
// Ensures fast fail during bootstrap if an active BAA is missing for any referenced vendor.
mode: process.env.NODE_ENV === 'production' ? 'strict' : 'dev',
onViolation: (violation) => slack.send(violation),
}),
],
providers: [PaymentService],
})
export class AppModule {}By default, @phivault/nestjs looks for corresponding environment variables referencing BAA identifiers in the format HDD_BAA_<VENDOR>:
- e.g.,
HDD_BAA_STRIPE=baa_valid_reference_id_xyz.
If HDD_BAA_STRIPE is missing during bootstrap with a .mode of 'strict', the framework throws a fatal error causing Node to crash.