
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@aismarttalk/anondocs-sdk
Advanced tools
TypeScript SDK for AnonDocs API - Privacy-first text and document anonymization
TypeScript/JavaScript SDK for AnonDocs - Privacy-first text and document anonymization powered by LLMs.
Made with ❤️ by AI SmartTalk
npm install @aismarttalk/anondocs-sdk
import { AnonDocsClient } from '@aismarttalk/anondocs-sdk';
const client = new AnonDocsClient({
baseUrl: 'http://localhost:3000',
defaultProvider: 'ollama'
});
// Anonymize text
const result = await client.anonymizeText('My name is John Smith and my email is john@example.com');
console.log(result.anonymizedText);
// Output: "My name is [NAME] and my email is [EMAIL]"
console.log(result.piiDetected);
// Output: { names: ['John Smith'], emails: ['john@example.com'], ... }
console.log(result.replacements);
// Output: [
// { original: 'John Smith', anonymized: '[NAME]' },
// { original: 'john@example.com', anonymized: '[EMAIL]' }
// ]
replacements arrayconst client = new AnonDocsClient({
baseUrl: 'http://localhost:3000', // Optional, defaults to localhost
defaultProvider: 'ollama', // Optional: 'openai' | 'anthropic' | 'ollama'
timeout: 30000 // Optional, defaults to 30s
});
const health = await client.health();
// Returns: { status: 'ok', timestamp: '2025-11-04T...' }
const result = await client.anonymizeText(
'John Smith lives at 123 Main St and his email is john@example.com',
{ provider: 'ollama' } // Optional, uses defaultProvider if not specified
);
console.log(result.anonymizedText);
console.log(result.piiDetected);
console.log(result.processingTimeMs);
console.log(result.wordsPerMinute);
console.log(result.chunksProcessed);
Node.js:
import { readFileSync } from 'fs';
const fileBuffer = readFileSync('./document.pdf');
const result = await client.anonymizeDocument(fileBuffer, {
provider: 'ollama'
});
// For DOCX files: formatting is preserved!
if (result.downloadUrl) {
console.log('Download anonymized DOCX:', result.downloadUrl);
console.log('Original filename:', result.originalFilename);
}
// Access replacement mappings
result.replacements.forEach(r => {
console.log(`"${r.original}" → "${r.anonymized}"`);
});
Browser:
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0];
const result = await client.anonymizeDocument(file, {
provider: 'openai'
});
// Download DOCX with preserved formatting
if (result.downloadUrl) {
window.open(result.downloadUrl, '_blank');
}
Get real-time progress updates for long texts or documents:
await client.streamAnonymizeText(longText, {
provider: 'ollama',
onProgress: (event) => {
console.log(`${event.progress}% - ${event.message}`);
// Progress: 0-100
// Types: 'started', 'chunk_processing', 'chunk_completed', 'completed', 'error'
},
onComplete: (result) => {
console.log('Done!', result.anonymizedText);
},
onError: (error) => {
console.error('Error:', error.message);
}
});
await client.streamAnonymizeDocument(file, {
provider: 'ollama',
onProgress: (event) => {
updateProgressBar(event.progress);
},
onComplete: (result) => {
displayResults(result);
},
onError: (error) => {
showError(error);
}
});
interface AnonymizationResult {
anonymizedText: string;
piiDetected: {
names: string[];
addresses: string[];
emails: string[];
phoneNumbers: string[];
dates: string[];
organizations: string[];
other: string[];
};
replacements: Array<{
original: string; // Exact original PII text
anonymized: string; // What it was replaced with (e.g., "[NAME]")
}>;
chunksProcessed: number;
wordsPerMinute: number;
processingTimeMs: number;
// DOCX only: present when document is DOCX with preserved formatting
downloadUrl?: string;
filename?: string;
originalFilename?: string;
}
What's New:
replacements - Precision mapping of original → anonymized textdownloadUrl - Download link for DOCX files with preserved formattingfilename - Generated filename for the anonymized documentoriginalFilename - Original document filenameinterface ProgressEvent {
type: 'started' | 'chunk_processing' | 'chunk_completed' | 'completed' | 'error';
progress: number; // 0-100
message: string;
currentChunk?: number; // 1-indexed
totalChunks?: number;
data?: AnonymizationResult; // Only on 'completed'
}
The SDK provides typed error classes:
import {
AnonDocsError,
AnonDocsApiError,
AnonDocsNetworkError,
AnonDocsValidationError,
AnonDocsStreamError
} from '@aismarttalk/anondocs-sdk';
try {
await client.anonymizeText('');
} catch (error) {
if (error instanceof AnonDocsValidationError) {
console.error('Validation error:', error.message);
} else if (error instanceof AnonDocsApiError) {
console.error('API error:', error.statusCode, error.message);
} else if (error instanceof AnonDocsNetworkError) {
console.error('Network error:', error.message);
}
}
application/vnd.openxmlformats-officedocument.wordprocessingml.document
downloadUrlapplication/pdf
text/plain
Max file size: 10MB
See the examples/ directory for complete usage examples:
basic-usage.ts - Simple text anonymizationstreaming-usage.ts - Real-time progress trackingdocument-usage.ts - File upload for Node.js and BrowserThe SDK is written in TypeScript and includes full type definitions. All types are exported:
import type {
LLMProvider,
PIIDetected,
PIIReplacement,
AnonymizationResult,
ProgressEvent,
ClientConfig
} from '@aismarttalk/anondocs-sdk';
fetch, FormData, Blob)fetch and ReadableStream supportMIT
FAQs
TypeScript SDK for AnonDocs API - Privacy-first text and document anonymization
The npm package @aismarttalk/anondocs-sdk receives a total of 12 weekly downloads. As such, @aismarttalk/anondocs-sdk popularity was classified as not popular.
We found that @aismarttalk/anondocs-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.