@defra/cdp-auditing

中文文档
0.6.3发布于 2026/11/04OGL-UK-3.0ES Module构建来源已验证近 30 天下载 4.6万

A hapi plugin for sending audit messages to the CDP audit pipeline

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Basic auditing
  4. Auditing structured data
  5. How auditing works on the CDP Platform

CDP Auditing

This package allows services to write audit messages to the CDP audit stream.

Installation

npm i @defra/cdp-auditing

Usage

The cdp-auditing library is not very complex.

Basic auditing

To send a message to the audit stream, simply import the audit library and call the audit() function.

import { audit } from '@defra/cdp-auditing'
audit('This is a test of auditing')
// {"log.level":"audit","time":"2025-07-04T11:46:33.278Z","msg":"This is a test of auditing"}

Auditing structured data

You can also write structured data to the audit stream. Values passed in should be serializable as json.

audit({ id: '1234', event: 'login', outcome: 'denied' }, 'Login failed')
// {"log.level":"audit","time":"2025-07-04T11:46:33.278Z","id":"1234","event":"login","outcome":"denied","msg":"Login failed"}

audit({ id: '1234', event: 'login', outcome: 'denied' })
// {"log.level":"audit","time":"2025-07-04T11:46:33.278Z","id":"1234","event":"login","outcome":"denied"}

When running locally, the audit messages will be printed to the console allowing you see what data will be auditing.

Auditing is enabled by default. To turn auditing on or off you can call:

import { audit, enableAuditing } from '@defra/cdp-auditing'

// Turn auditing off
enableAuditing(false)

// Re-enable auditing
enableAuditing()
// or
enableAuditing(true)

How auditing works on the CDP Platform

Auditing is basically just standard logger pre-configured to do the following:

  • write to console/stdout
  • write all messages as JSON
  • ensures all messages include an ECS style log.level field set to audit

Services running on the CDP Platform are deployed with a log collection sidecar (FluentBit).

The log sidecar filters messaged based on their log.level field. Messages with "log.level": "audit" are filtered out and sent to the audit stream, while all other log levels are sent to the OpenSearch pipeline.

版本与发布记录

@defra/cdp-auditing 共发布 10 个版本,首次发布于 2025/07/04;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.3latest2026/11/048 天前
0.6.22026/10/051 个月前
0.6.12026/05/275 个月前
0.6.02025/11/2811 个月前
0.5.02025/11/071 年前
0.4.02025/10/011.1 年前

关于 @defra/cdp-auditing 的常见问题

@defra/cdp-auditing 是什么?

A hapi plugin for sending audit messages to the CDP audit pipeline

如何安装 @defra/cdp-auditing?

在项目目录运行 npm install @defra/cdp-auditing,或使用 pnpm add / yarn add / bun add。

@defra/cdp-auditing 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/defra__cdp-auditing 是否存在。

@defra/cdp-auditing 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@defra/cdp-auditing 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@defra/cdp-auditing 可以商用吗?

@defra/cdp-auditing 使用 OGL-UK-3.0 许可。声明的许可为 OGL-UK-3.0,请阅读许可原文确认使用条件。以上为概括,不构成法律意见,请以许可原文为准。

@defra/cdp-auditing 的下载量有多少?

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

@defra/cdp-auditing 还在维护吗?

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