@dynamic-labs/redaction

中文文档
1.1.1发布于 2026/10/23TypeScriptESM + CJS零依赖近 30 天下载 17.9万

Credential and key-material redaction shared across Dynamic services and browser clients: a key denylist, credential-shaped free-text patterns, a non-mutating deep redactor, and Datadog RUM/Logs beforeSend scrubbers. No pino, no node built-ins — browser-s

原始使用文档
文档目录3 节
  1. Public API
  2. Structured redaction
  3. Datadog browser SDKs

@dynamic-labs/redaction

Credential and key-material redaction shared by Dynamic backends and browser clients: a key denylist, credential-shaped free-text patterns, a non-mutating deep redactor, and Datadog RUM/Logs beforeSend scrubbers.

Imports nothing — no pino, no node built-ins — so it is safe in a browser bundle. @dyn-observability/logger applies these rules to every record it emits; use this package directly when the sink is not pino.

Public API

ExportPurpose
redact(value, keys?, options?)Non-mutating deep redaction of a structured value
redactSecretsFromText(text, extraPatterns?)Scrub credential-shaped runs from a string
DEFAULT_REDACT_KEYSKey substrings redacted at any depth
DEFAULT_REDACT_KEY_PATTERNSKey patterns a substring match misses (private keys, key shares, EACs, axios branches)
KEY_MATERIAL_TEXT_PATTERNSOpt-in text patterns for long hex / base58 runs
OPAQUE_RUN_TEXT_PATTERNSOpt-in text pattern for any 32+ run of [A-Za-z0-9+=_]
REDACTEDThe replacement token
RedactOptions, TextPatternOption and pattern types
scrubRumEvent, scrubLogEventDatadog RUM / Logs beforeSend scrubbers
BROWSER_REDACT_OPTIONSDefaults the scrubbers apply on the UI thread
redactSensitiveActionTargets, downgradeNetworkErrorsIndividual scrubber steps
isExtensionNoise, isNetworkErrorEvent classifiers for callers filtering events themselves
RedactableLogEvent, RedactableRumEventStructural event types the scrubbers accept

Structured redaction

import {
  DEFAULT_REDACT_KEYS,
  KEY_MATERIAL_TEXT_PATTERNS,
  redact,
} from '@dynamic-labs/redaction';

const safe = redact(context, DEFAULT_REDACT_KEYS, {
  textPatterns: KEY_MATERIAL_TEXT_PATTERNS,
  maxDepth: 4,
  maxArrayLength: 20,
});
  • Keys: case-insensitive substring match over DEFAULT_REDACT_KEYS — authorization, cookie, token, password, secret, api-key/apikey, jwt, passphrase, credential, mnemonic — at ANY depth. DEFAULT_REDACT_KEY_PATTERNS covers the shapes a substring misses: private_key/privateKey, seedPhrase, session-signature, encrypted*Share/*Backup/*Data, key-share and EAC material under any owner prefix (*keyShare(s), *eac(s) — end-anchored, so keyShareId and externalKeyShareId stay legible), and the config/headers/request branches an axios error carries.
  • Free text: surviving strings, error messages and stacks are scrubbed of credential-shaped runs — Authorization: values, Bearer/Basic credentials, JWTs and dyn_* keys.
  • Boolean values survive a matching key name: hasPassword, passwordEncrypted and friends stay queryable, since a boolean carries no credential material. An explicit paths rule still redacts them.
  • Errors become { type, message, stack } plus their redacted enumerable own-properties, matching pino's stdSerializers.err shape.
  • The input is never mutated; cycles collapse to [Circular].

RedactOptions beyond paths / allow / patterns:

  • textPatterns — extra free-text patterns. KEY_MATERIAL_TEXT_PATTERNS (long hex, base58) is opt-in: those shapes are also EVM addresses, tx hashes and block hashes, so they only pay off where chain identifiers are not logged. OPAQUE_RUN_TEXT_PATTERNS (any 32+ run of [A-Za-z0-9+=_]) is opt-in for the same reason: it catches credentials of unrecognized shape in untrusted text — a dependency's error string — and excludes separators so URLs, hostnames and UUIDs stay legible.
  • maxDepth — depth at which a nested value collapses to [REDACTED]. Unbounded by default.
  • maxArrayLength — number of array entries kept. Unbounded by default.

Datadog browser SDKs

scrubRumEvent and scrubLogEvent scrub an event in place for the beforeSend hooks, defaulting to BROWSER_REDACT_OPTIONS (key-material text patterns, depth 4, 20 array entries — the hook runs on the UI thread for every event).

import { scrubLogEvent, scrubRumEvent } from '@dynamic-labs/redaction';

datadogRum.init({ beforeSend: (event) => scrubRumEvent(event) });
datadogLogs.init({ beforeSend: (event) => scrubLogEvent(event) });

scrubRumEvent redacts action target names that carry key material and, for error events, the error message and stack. scrubLogEvent redacts the message, the error message and stack, and every caller-supplied attribute (Datadog's typed message/date/status are handled separately so their shape survives).

Both return false — dropping the event — for an error raised by a browser wallet extension, whose inpage script runs in the page and otherwise dominates a catch-all error monitor. scrubLogEvent also downgrades a transient network failure (blocked or aborted request, EIP-1193 provider disconnect) from error to warn instead of dropping it. isExtensionNoise, isNetworkError and downgradeNetworkErrors are exported for callers that classify events themselves.

版本与发布记录

@dynamic-labs/redaction 共发布 5 个版本,首次发布于 2026/09/11;过去 12 个月发布了 5 个版本。

版本发布日期距今
1.1.1latest2026/10/2321 天前
1.1.02026/09/122 个月前
1.0.02026/09/122 个月前
0.0.1-beta.0beta2026/09/112 个月前
0.0.02026/09/112 个月前

关于 @dynamic-labs/redaction 的常见问题

@dynamic-labs/redaction 是什么?

Credential and key-material redaction shared across Dynamic services and browser clients: a key denylist, credential-shaped free-text patterns, a non-mutating deep redactor, and Datadog RUM/Logs beforeSend scrubbers. No pino, no node built-ins — browser-s

如何安装 @dynamic-labs/redaction?

在项目目录运行 npm install @dynamic-labs/redaction,或使用 pnpm add / yarn add / bun add。

@dynamic-labs/redaction 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dynamic-labs/redaction 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dynamic-labs/redaction 可以商用吗?

@dynamic-labs/redaction 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@dynamic-labs/redaction 的下载量有多少?

根据 npm 官方下载统计,@dynamic-labs/redaction 在 2026/10/13 – 2026/11/11 这 30 天内被下载 179,147 次,日均约 5,972 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dynamic-labs/redaction 还在维护吗?

最新版本 1.1.1 发布于 2026/10/23(21 天前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/09/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。