PrivacyClient
Full API reference for the PrivacyClient class.
PrivacyClient is the main class in @secured-ai/core. It coordinates detection engines, sessions, file processing, text review, and the optional vault subsystem.
import { PrivacyClient } from '@secured-ai/core'Constructor
new PrivacyClient(config?: PrivacyClientConfig)PrivacyClientConfig
interface PrivacyClientConfig {
baseUrl: string
sdkAccessToken: string
engines?: {
regex?: boolean
nlp?: boolean
ml?: boolean
gliner?: boolean
custom?: boolean
}
confidenceThreshold?: number
maxProcessingTime?: number
disableGLiNERChunking?: boolean
replacementPools?: Partial<Record<EntityType, string[]>>
debug?: boolean
onInitProgress?: (event: InitProgressEvent) => void
vault?: PrivacyVaultConfig
}| Option | Type | Default | Description |
|---|---|---|---|
baseUrl | string | required in browser | Secured API base URL used to verify the SDK access token and bind backend-backed repositories |
sdkAccessToken | string | required in browser | Origin-restricted SDK access token created in the Secured platform |
engines.regex | boolean | true | Structured regex detection |
engines.nlp | boolean | true | compromise-based detection |
engines.ml | boolean | false | HuggingFace semantic detection |
engines.gliner | boolean | false | GLiNER semantic detection |
engines.custom | boolean | true | user-registered regex patterns |
confidenceThreshold | number | 0.8 | Minimum confidence to return |
maxProcessingTime | number | 30000 | Per-engine timeout in milliseconds |
disableGLiNERChunking | boolean | false | Runs GLiNER once against the full input instead of splitting long text into semantic chunks |
replacementPools | object | {} | Custom replacement values by entity type |
debug | boolean | false | Enables debug logging |
onInitProgress | function | undefined | Called during slow-engine initialization |
vault | PrivacyVaultConfig | undefined | Enables the vault subsystem |
const client = new PrivacyClient({
baseUrl: 'https://dev-api.securedai.com',
sdkAccessToken: import.meta.env.VITE_SECURED_SDK_ACCESS_TOKEN,
engines: {
regex: true,
nlp: true,
ml: false,
gliner: false,
custom: true,
},
confidenceThreshold: 0.85,
maxProcessingTime: 15000,
replacementPools: {
PERSON: ['Alex Taylor', 'Jordan Lee'],
},
debug: true,
})Create an SDK access token in Settings > SDK Access Tokens before using the browser SDK. initialize() verifies the token against the current browser origin before starting engines or backend-backed vault setup. See SDK Access Tokens.
Lifecycle and status
initialize()
initialize(): Promise<void>Initializes the configured engines and the vault subsystem. Fast engines initialize first. Slow engines like HuggingFace and GLiNER may continue warming in the background.
In browser environments, initialize() first verifies sdkAccessToken against baseUrl and the current request origin. If the token is missing, invalid, revoked, or the origin is not allowed, initialization rejects before loading engines.
getInitProgress()
getInitProgress(): InitProgressReturns per-engine and overall initialization progress.
clearModelCache()
clearModelCache(): voidClears cached semantic model state, resets readiness, and forces a future re-initialization.
isReady
get isReady(): booleantrue when at least one configured engine is ready.
isFullyReady
get isFullyReady(): booleantrue when every configured engine is ready.
readyEngines
get readyEngines(): string[]Returns the concrete engine names currently available.
Text detection and obfuscation
detect()
detect(text: string): Promise<PrivacyScanResult>Runs all currently ready engines, merges entities, filters by confidence, and returns both entities and sensitiveEntities.
obfuscate()
obfuscate(text: string, options?: ObfuscationOptions): Promise<ObfuscationResult>Detects sensitive entities, resolves replacements through the vault and replacement pools, creates a session, and returns the processed text.
interface ObfuscationOptions {
threadId?: string | null
}Pass threadId to scope replacement reuse even if you are not calling setThreadContext() globally.
restore()
restore(text: string, sessionId: string): Promise<RestorationResult>Restores original values using a previously created session.
Text review workflow
createTextReview()
createTextReview(
text: string,
entities: SensitiveEntity[],
resolveReplacement?: (entity: SensitiveEntity) => string,
): TextReviewCreates a grouped review model from detected entities.
setTextReviewReplacement()
setTextReviewReplacement(
review: TextReview,
itemId: string,
replacement: string,
): TextReviewremoveTextReviewItem()
removeTextReviewItem(review: TextReview, itemId: string): TextReviewrestoreTextReviewItem()
restoreTextReviewItem(review: TextReview, itemId: string): TextReviewaddTextReviewEntity()
addTextReviewEntity(
review: TextReview,
entity: SensitiveEntity,
replacement: string,
): TextReviewpreviewTextReview()
previewTextReview(
review: TextReview,
): Omit<FinalizedTextReview, 'sessionId' | 'session' | 'serializedSession'>Returns a processed-text preview without persisting a session.
finalizeTextReview()
finalizeTextReview(review: TextReview): FinalizedTextReviewCreates the processed text, mappings, and a persisted session in one step.
createSessionFromMappings()
createSessionFromMappings(
originalText: string,
processedText: string,
mappings: SessionMapping[],
): PrivacySessionCreates a session explicitly from a known mapping set.
File processing
detectInFile()
detectInFile(file: File): Promise<FileProcessingResult>Extracts text and scans supported files such as PDF, DOCX, XLSX, CSV, TXT, JSON, and images.
obfuscateFile()
obfuscateFile(
file: File,
entitiesOrOptions?: SensitiveEntity[] | FileObfuscationOptions,
): Promise<Blob>FileObfuscationOptions supports:
interface FileObfuscationOptions {
entities?: SensitiveEntity[]
extractedText?: string
}Use entities to reuse a reviewed entity list, or extractedText to skip a second extraction pass when your UI already has the source text.
Sessions
getSession()
getSession(sessionId: string): PrivacySession | undefinedexportSession()
exportSession(sessionId: string): SerializedPrivacySession | undefinedExports a session into a JSON-safe representation.
importSession()
importSession(session: PrivacySession | SerializedPrivacySession): PrivacySessionHydrates a session into the current client instance.
getSessions()
getSessions(): PrivacySession[]clearSession()
clearSession(sessionId: string): voidclearAllSessions()
clearAllSessions(): voidCustom patterns
addPattern()
addPattern(pattern: CustomPattern): voidremovePattern()
removePattern(name: string): booleanVault integration
vault
get vault(): VaultManagerGives direct access to the configured vault manager.
setThreadContext()
setThreadContext(threadId: string | null): Promise<void>Sets the active thread for vault-backed replacement reuse.
refreshVaultContext()
refreshVaultContext(): Promise<void>Re-resolves runtime vault inputs like masterKey and cacheNamespace.
clearVaultCache()
clearVaultCache(): Promise<void>Clears the vault cache and in-memory snapshot state.