Skip to content

Latest commit

 

History

History
100 lines (75 loc) · 3.11 KB

node.mdx

File metadata and controls

100 lines (75 loc) · 3.11 KB
title Node.js
description Node.js functions, TypeScript types, JavaScript ranges, and the asynchronous PrivacyManager.
icon node-js
import {
  DataFogError,
  PrivacyManager,
  scan,
  scanAndTransform,
  transform,
} from "@datafog/node";

Synchronous functions

scan(text: string, config?: ScanConfig): Finding[]
transform(
  text: string,
  findings: FindingInput[],
  config: TransformationConfig,
): TransformResult
scanAndTransform(text: string, config: ScanAndTransformConfig): TransformResult

Findings and ranges

Node.js uses camelCase fields. Findings include byteRange, codepointRange, and utf16Range. Use the UTF-16 range with native JavaScript string slicing.

const finding = scan("👋 jane@example.com")[0];
console.assert(finding.utf16Range.start === 3);

Caller-supplied FindingInput objects do not require utf16Range.

Asynchronous manager

Use PrivacyManager for provider-backed pseudonymization, tokenization, and restoration:

new PrivacyManager(
  provider: KeyProvider | PrivacyManagerProviders,
  tokenProvider?: TokenProvider,
)
await manager.transform(text, findings, config, context?)
await manager.scanAndTransform(text, config, context?)
await manager.restore(text, context)

For recipient names and mailing addresses in prose, use EmbeddedCnnDetector.

Native distribution targets

The package build is configured for:

  • macOS Apple Silicon;
  • Linux x64 and ARM64;
  • Windows x64.

Intel macOS binaries remain available through 1.6.0. Subsequent releases omit @datafog/node-darwin-x64 and no longer qualify Intel source builds.

Errors

JavaScript operations throw DataFogError with stable code, optional reason, optional RFC 6901 path, and optional findingIndex properties.

Structured JSON and PERSON fields

Use discoverFields(data, config?), scanStructured(data, config?), transformStructured(data, findings, config), and scanAndTransformStructured(data, config). Scan returns { mappings, findings }; transformation returns { data, transformations }. Located findings contain path and finding; located records contain path and transformation. PrivacyManager adds asynchronous structured transform, scan-and-transform, and restore methods with the same provider and scope contracts as text calls.

Paths are JSON Pointers. All ranges, including JavaScript UTF-16 ranges, address the decoded string at that path. See person-field discovery for aliases, policy configuration, input limits, and examples.

German locale routing and the seven additional entity labels are documented in the German entity reference.

This SDK shares the Rust detector registry. See the rule inventory for activation settings.

Email source context

Use the optional scan format setting ("text", "env", or "sql") to delimit emails in environment assignments or standard SQL quoted strings. See email boundaries for examples and syntax limits.