Skip to main content
This section provides detailed documentation for all Rehydra exports.

Core Functions

Storage

Utilities

Quick Reference

Main Entry Points

import { 
  // Factory function
  createAnonymizer,
  
  // Convenience functions
  anonymize,
  anonymizeRegexOnly,
  anonymizeWithNER,
  
  // Rehydration
  rehydrate,
  decryptPIIMap,
  
  // Key providers
  InMemoryKeyProvider,
  ConfigKeyProvider,
  
  // Storage providers
  InMemoryPIIStorageProvider,
  SQLitePIIStorageProvider,      // Node.js only
  IndexedDBPIIStorageProvider,   // Browser only
  
  // Types
  PIIType,
  type AnonymizationResult,
  type AnonymizationPolicy,
} from 'rehydra';

Result Structure

interface AnonymizationResult {
  // Text with PII replaced
  anonymizedText: string;
  
  // Detected entities (without originals)
  entities: Array<{
    type: PIIType;
    id: number;
    start: number;
    end: number;
    confidence: number;
    source: 'REGEX' | 'NER';
  }>;
  
  // Encrypted PII map
  piiMap: {
    ciphertext: string;
    iv: string;
    authTag: string;
  };
  
  // Statistics
  stats: {
    countsByType: Record<PIIType, number>;
    totalEntities: number;
    processingTimeMs: number;
    modelVersion: string;
    leakScanPassed?: boolean;
  };
}

Configuration

interface AnonymizerConfig {
  // NER model configuration
  ner?: {
    mode: 'disabled' | 'quantized' | 'standard' | 'custom';
    modelPath?: string;
    vocabPath?: string;
    autoDownload?: boolean;
    thresholds?: Partial<Record<PIIType, number>>;
    onStatus?: (status: string) => void;
    onDownloadProgress?: (progress: DownloadProgress) => void;
  };
  
  // Semantic enrichment
  semantic?: {
    enabled: boolean;
    autoDownload?: boolean;
    onStatus?: (status: string) => void;
    onDownloadProgress?: (progress: DownloadProgress) => void;
  };
  
  // Encryption key provider
  keyProvider?: KeyProvider;
  
  // Storage for sessions
  piiStorageProvider?: PIIStorageProvider;
  
  // Default anonymization policy
  defaultPolicy?: AnonymizationPolicy;
}

Policy Options

interface AnonymizationPolicy {
  // Types to detect
  enabledTypes: Set<PIIType>;
  regexEnabledTypes: Set<PIIType>;
  nerEnabledTypes: Set<PIIType>;
  
  // Confidence thresholds
  confidenceThresholds: Map<PIIType, number>;
  
  // Type priority for overlaps
  typePriority: PIIType[];
  
  // Allowlist (never anonymize)
  allowlistTerms: Set<string>;
  
  // ID reuse for repeated values
  reuseIdsForRepeatedPII: boolean;
  
  // Validation
  enableLeakScan: boolean;
  
  // Semantic attributes
  enableSemanticMasking: boolean;
}