Node.js SDK — Resources
The Node.js SDK organizes API endpoints into six resource classes, each accessible as a property on the client.
RedactResource
Accessible via client.redact. Provides methods for inline text redaction and URI-based file redaction.
text()
Redact PII from a text string. Returns the redacted text and a list of findings.
const result = await client.redact.text({
text: "John Smith's SSN is 123-45-6789",
piiTypes: ['PERSON', 'US_SSN'], // optional: filter entity types
confidenceThreshold: 0.5, // optional: minimum confidence
language: 'en', // optional: language code
policyId: 'pol_abc123', // optional: apply a saved policy
});
console.log(result.redactedText);
// "[PERSON]'s SSN is [US_SSN]"
for (const finding of result.findings) {
console.log(` ${finding.entityType}: '${finding.text}' (score=${finding.score})`);
}uri()
Submit a file or URI for asynchronous redaction. Returns a job that can be polled for completion.
const job = await client.redact.uri({
inputUri: 's3://my-bucket/document.pdf',
outputUri: 's3://my-bucket/document-redacted.pdf', // optional
piiTypes: ['PERSON', 'EMAIL_ADDRESS'], // optional
policyId: 'pol_abc123', // optional
});
console.log(`Job ID: ${job.id}`);
console.log(`Status: ${job.status}`); // "pending" or "processing"JobsResource
Accessible via client.jobs. Manage asynchronous redaction jobs.
list()
List all jobs, with optional filtering.
const jobs = await client.jobs.list({
status: 'completed', // optional: filter by status
limit: 10, // optional: max results
offset: 0, // optional: pagination offset
});
for (const job of jobs) {
console.log(`${job.id}: ${job.status} (${job.progressPct}%)`);
}get()
Get detailed information about a specific job, including findings.
const job = await client.jobs.get('job_abc123');
console.log(`Status: ${job.status}`);
console.log(`Progress: ${job.progressPct}%`);
console.log(`Input: ${job.inputUri}`);
console.log(`Output: ${job.outputUri}`);
if (job.findings) {
for (const finding of job.findings) {
console.log(` ${finding.entityType}: score=${finding.score}`);
}
}download()
Download the redacted output of a completed job.
const content = await client.jobs.download('job_abc123');
// content is an ArrayBufferdelete()
Delete a job and its associated data.
await client.jobs.delete('job_abc123');BatchResource
Accessible via client.batch. Submit and monitor batch redaction operations.
create()
Submit multiple URIs for batch redaction.
const batch = await client.batch.create({
inputUris: [
's3://bucket/doc1.pdf',
's3://bucket/doc2.pdf',
's3://bucket/doc3.pdf',
],
piiTypes: ['PERSON', 'EMAIL_ADDRESS'], // optional
policyId: 'pol_abc123', // optional
});
console.log(`Batch ID: ${batch.id}`);
console.log(`Total jobs: ${batch.total}`);get()
Check the status of a batch operation.
const batch = await client.batch.get('batch_abc123');
console.log(`Status: ${batch.status}`);
console.log(`Completed: ${batch.completed}/${batch.total}`);
console.log(`Failed: ${batch.failed}`);
for (const job of batch.jobs) {
console.log(` ${job.id}: ${job.status}`);
}PoliciesResource
Accessible via client.policies. Manage reusable redaction policies.
create()
const policy = await client.policies.create({
name: 'HIPAA Compliance',
description: 'Redact all PHI entities',
piiTypes: ['PERSON', 'EMAIL_ADDRESS', 'PHONE_NUMBER', 'US_SSN', 'ADDRESS'],
confidenceThreshold: 0.4,
language: 'en',
});
console.log(`Policy ID: ${policy.id}`);list()
const policies = await client.policies.list();
for (const policy of policies) {
console.log(`${policy.id}: ${policy.name} (${policy.piiTypes.length} types)`);
}get()
const policy = await client.policies.get('pol_abc123');
console.log(`Name: ${policy.name}`);
console.log(`Types: ${policy.piiTypes}`);
console.log(`Threshold: ${policy.confidenceThreshold}`);update()
const policy = await client.policies.update('pol_abc123', {
name: 'Updated HIPAA Policy',
piiTypes: ['PERSON', 'EMAIL_ADDRESS', 'PHONE_NUMBER', 'US_SSN', 'ADDRESS', 'DATE_OF_BIRTH'],
});delete()
await client.policies.delete('pol_abc123');ApiKeysResource
Accessible via client.apiKeys. Manage API keys for your account.
create()
const key = await client.apiKeys.create({
name: 'Production Key',
scopes: ['redact:text', 'redact:uri', 'jobs:read'], // optional
});
console.log(`Key ID: ${key.id}`);
console.log(`API Key: ${key.key}`); // only shown once at creation
console.log(`Name: ${key.name}`);list()
const keys = await client.apiKeys.list();
for (const key of keys) {
console.log(`${key.id}: ${key.name} (created: ${key.createdAt})`);
}revoke()
await client.apiKeys.revoke('key_abc123');AuditResource
Accessible via client.audit. Query the audit log for API activity.
list()
const logs = await client.audit.list({
startDate: '2026-01-01T00:00:00Z', // optional
endDate: '2026-02-01T00:00:00Z', // optional
action: 'redact.text', // optional: filter by action
limit: 50, // optional
offset: 0, // optional
});
console.log(`Total entries: ${logs.total}`);
for (const entry of logs.items) {
console.log(` ${entry.timestamp}: ${entry.action} by ${entry.apiKeyId}`);
}waitForJob Utility
The SDK exports a waitForJob helper function that polls a job until it reaches a terminal state (completed or failed).
import { PiiRedactor, waitForJob } from '@pii-redactor/sdk';
const client = new PiiRedactor({ apiKey: 'pk_live_...' });
// Submit a file for redaction
const job = await client.redact.uri({
inputUri: 's3://my-bucket/document.pdf',
});
// Poll until completion
const completed = await waitForJob(client, job.id, {
intervalMs: 2000, // poll every 2 seconds (default: 1000)
timeoutMs: 60000, // give up after 60 seconds (default: 300000)
});
console.log(`Job completed: ${completed.status}`);
console.log(`Output: ${completed.outputUri}`);Options
| Option | Type | Default | Description |
|---|---|---|---|
intervalMs | number | 1000 | Milliseconds between poll requests |
timeoutMs | number | 300000 | Maximum milliseconds to wait before throwing PollingTimeoutError |