@nocobase/audit 0.1.0-beta.0 → 0.1.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -4
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +35 -3
- package/dist/config.js.map +1 -1
- package/dist/file-output.d.ts +26 -0
- package/dist/file-output.d.ts.map +1 -0
- package/dist/file-output.js +269 -0
- package/dist/file-output.js.map +1 -0
- package/dist/file-transport.d.ts +4 -2
- package/dist/file-transport.d.ts.map +1 -1
- package/dist/file-transport.js +76 -109
- package/dist/file-transport.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/redact.d.ts +9 -8
- package/dist/redact.d.ts.map +1 -1
- package/dist/redact.js +29 -3
- package/dist/redact.js.map +1 -1
- package/dist/repository.d.ts.map +1 -1
- package/dist/repository.js +0 -1
- package/dist/repository.js.map +1 -1
- package/dist/request.d.ts +9 -8
- package/dist/request.d.ts.map +1 -1
- package/dist/request.js +46 -39
- package/dist/request.js.map +1 -1
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +3 -1
- package/dist/runtime.js.map +1 -1
- package/dist/service.d.ts +3 -0
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +8 -5
- package/dist/service.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -4,30 +4,68 @@
|
|
|
4
4
|
|
|
5
5
|
## Configuration
|
|
6
6
|
|
|
7
|
-
Add the `audit` section to the application's `config.
|
|
7
|
+
Add the `audit` section to the application's `config.yml`:
|
|
8
8
|
|
|
9
9
|
```yaml
|
|
10
10
|
audit:
|
|
11
|
+
captureBody: false
|
|
12
|
+
redact:
|
|
13
|
+
fields:
|
|
14
|
+
- identityNumber
|
|
15
|
+
paths:
|
|
16
|
+
- profile.mobile
|
|
11
17
|
transports:
|
|
12
18
|
localFile:
|
|
13
19
|
driver: file
|
|
14
20
|
options:
|
|
15
21
|
path: logs/audit.jsonl
|
|
22
|
+
maxFileSizeMB: 50
|
|
23
|
+
retentionDays: 180
|
|
16
24
|
```
|
|
17
25
|
|
|
18
|
-
With at least one destination, `audit.enabled` defaults to `true` and the app records explicitly declared operations. `audit.enabled: false` disables collection and delivery. `audit.autoDetect` defaults to `false`. Enable it to also record documented POST, PATCH, PUT, and DELETE operations that have an operation ID and are visible in the API document. An explicit `describeAudit(false)` excludes a route. A dynamic declaration that returns `undefined` leaves the route eligible for automatic detection. The audit provider reads generated Repository endpoint metadata before guards, records mutations, and excludes queries.
|
|
26
|
+
An application without destinations collects no audit events. With at least one destination, `audit.enabled` defaults to `true` and the app records explicitly declared operations. `audit.enabled: false` disables collection and delivery. `audit.autoDetect` defaults to `false`. Enable it to also record documented POST, PATCH, PUT, and DELETE operations that have an operation ID and are visible in the API document. An explicit `describeAudit(false)` excludes a route. A dynamic declaration that returns `undefined` leaves the route eligible for automatic detection. The audit provider reads generated Repository endpoint metadata before guards, records mutations, and excludes queries.
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
The app validates capture settings at startup. Restart it after changing them. Body capture requires an explicit `true` on the application or the route. An explicit `false` at either level always takes precedence. Leave both settings unset to collect events without request or response bodies. With body capture off, audit does not clone, read, or parse the bodies.
|
|
29
|
+
|
|
30
|
+
Use `redact: { fields: ['identityNumber'], paths: ['profile.mobile'] }` in app configuration or a route declaration. Fields match the exact name at any depth. Paths match from the root of each snapshot or structured target key. A named segment crosses array elements, as in `members.mobile`. An index such as `members.0.mobile` matches one position. Built-in credential masking and all additional rules apply before dispatch.
|
|
21
31
|
|
|
22
32
|
Audit uses `auth.advanced.ipAddress.trustedProxies` and `auth.advanced.ipAddress.ipAddressHeaders`. For a trusted socket peer, it tries the configured headers in order, defaulting to `X-Forwarded-For`, and walks each chain from right to left to its first untrusted address. Invalid proxy entries are skipped with a startup warning. An untrusted peer, an empty allowlist, or a chain with no usable client address results in the socket peer address.
|
|
23
33
|
|
|
34
|
+
### Rolling file output
|
|
35
|
+
|
|
36
|
+
The `path` sets a filename prefix. Use a `.jsonl` basename with letters, digits, underscores or hyphens before the extension. Relative paths must stay under application storage after resolving directory symlinks. Absolute paths are supported. The driver creates directories with mode `0700` and files with mode `0600` on POSIX, subject to the process umask. Use a private log directory owned exclusively by the application. Keep its parent paths out of the control of untrusted users and run the application with least privilege.
|
|
37
|
+
|
|
38
|
+
`rotating-file-stream` 4.0.0 appends JSON Lines and rolls segments by UTC date and size, independently of application logging. For `logs/audit.jsonl`, the first segment on November 26 UTC is `logs/audit.2026-11-26.000000.jsonl`. At startup the stream only considers the highest number for that date. A full segment advances the number. An incomplete tail triggers a warning and the next number, leaving the damaged segment in place until its retention period expires. Lower numbers stay archived on subsequent restarts. `maxFileSizeMB` defaults to 50 (50 × 1,048,576 bytes). A record that reaches or exceeds the limit stays whole in the current segment, and the stream then opens the next segment. Size and midnight rotation can leave an empty segment, even while the application is idle.
|
|
39
|
+
|
|
40
|
+
The library provides retention by count or total size. Audit uses the file's last modification time to keep each archive for at least `retentionDays`, which defaults to 180 days of 24 hours. Both options accept positive finite numbers. Cleanup runs in the background on startup and after rotation, including idle midnight rotation. It only removes expired, private regular files whose names match the target's prefix and segment format. It skips the current UTC day's segments, active files, links, other targets, and the legacy unsegmented file. Cleanup may occur after the retention threshold. Point readers at the new segmented names after upgrading. Configure each output path for one writer process. Destinations in that process that resolve to the same prefix share a stream and use the longest retention and smallest size limit registered while the output is open.
|
|
41
|
+
|
|
42
|
+
The library opens the path for append before audit checks that it is a regular file with one hard link and private POSIX permissions. This check is weaker than `O_NOFOLLOW`. For example, a symlink can cause the open to create an empty file outside the directory. The stream keeps its file handle open between writes. The directory and its parent paths must stay under trusted control while the handle is open.
|
|
43
|
+
|
|
44
|
+
Each shared stream takes one record at a time. A write settles after the stream callback and a byte-length check. The library hands bytes to the operating system without a disk sync. A failed or short write can leave an incomplete tail. Audit reports the failure, closes the stream, and recovers on a later write without replaying the failed record. The library can surface an idle rotation failure on the next write or during shutdown. The coordinator allows up to 64 pending writes per destination and uses a one-second delivery and shutdown deadline. Cancellation skips queued writes before submission. A submitted filesystem operation can finish after its deadline. Shutdown asks the stream to finish and waits for the handle and scheduled cleanup within the coordinator's deadline.
|
|
45
|
+
|
|
24
46
|
## Routes and transports
|
|
25
47
|
|
|
26
48
|
Audit events store the operation's declared name or its English default, with API summary and action as fallbacks. The name is independent of the request language. JSON Lines contains the event as recorded, including any `operationNameI18n` namespace and key.
|
|
27
49
|
|
|
28
50
|
The official templates contribute the lazy loader from `@nocobase/audit/locales` as a locales-only entry in their client plugin list. Custom applications can add the same entry with `defineClientPlugin({ packageName: '@nocobase/audit', locales: auditLocales })()` before client initialization. Installed business plugins provide their labels through their own locale contributions. Resolve `operationNameI18n` in the viewer's language, falling back to the stored `operationName`, then `action` for older events. The audit provider also registers the Repository labels on the server for localized exports.
|
|
29
51
|
|
|
30
|
-
Import `describeAudit` from `@nocobase/audit` and declare it alongside the route. Set an action, resource, and optional operation name for display. Use `target` for identifiers available before guards and `resolveTargets` for identifiers derived from a successful handler result.
|
|
52
|
+
Import `describeAudit` from `@nocobase/audit` and declare it alongside the route. Set an action, resource, and optional operation name for display. Use `target(context)` for identifiers available before guards and `resolveTargets(result, context)` for identifiers derived from a successful handler result. With body capture off, the resolver still receives the context and any in-process `value` the handler provides. Its `request` and `response` are then `undefined`. Even with capture on, content type or read and size bounds can make a JSON body unavailable. Use `auditRecordKey` to read optional values and return `undefined` when the target is unknown. Resolver errors leave the event with the pre-handler target, if available.
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { auditRecordKey, describeAudit } from '@nocobase/audit';
|
|
56
|
+
|
|
57
|
+
const auditCustomerCreation = describeAudit({
|
|
58
|
+
action: 'customer.create',
|
|
59
|
+
captureBody: true,
|
|
60
|
+
redact: { fields: ['identityNumber'], paths: ['profile.mobile'] },
|
|
61
|
+
resolveTargets: ({ response }) => {
|
|
62
|
+
const id = auditRecordKey(response, 'data', 'id');
|
|
63
|
+
return id === undefined ? undefined : { collection: 'customers', key: id };
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
With the YAML example above, the application's `captureBody: false` keeps this route's bodies unavailable, and the resolver returns no target.
|
|
31
69
|
|
|
32
70
|
In a service provider's `register` or `boot`, resolve `auditServiceToken` and register the transport with `registerDriver({ name, createTransport })`. Configure each named destination under `audit.transports` with its driver and driver-specific options. The synchronous factory receives the options and `{ name, paths }`, with the application storage directory available as `paths.storageDir`. The transport implements `write(event, { signal })` and can implement `close()` to release resources. The application validates active destination names, drivers, and factory options at startup. The commercial audit plugin supplies the `database` driver, which can be configured alongside `file`.
|
|
33
71
|
|
package/dist/config.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import { type AuditRedactRules } from './redact.js';
|
|
2
|
+
export type AuditFileOptions = {
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly maxFileSizeMB?: number;
|
|
5
|
+
readonly retentionDays?: number;
|
|
6
|
+
};
|
|
1
7
|
export interface AuditDestinationConfig {
|
|
2
8
|
readonly driver: string;
|
|
3
9
|
readonly options?: Readonly<Record<string, unknown>>;
|
|
@@ -5,6 +11,10 @@ export interface AuditDestinationConfig {
|
|
|
5
11
|
export interface AuditConfig {
|
|
6
12
|
readonly enabled?: boolean;
|
|
7
13
|
readonly autoDetect?: boolean;
|
|
14
|
+
/** Opt in to bounded JSON snapshots. A route can opt out, and false disables them for every route. */
|
|
15
|
+
readonly captureBody?: boolean;
|
|
16
|
+
/** Applied in addition to built-in credential masking and route rules. */
|
|
17
|
+
readonly redact?: AuditRedactRules;
|
|
8
18
|
readonly transports?: Readonly<Record<string, AuditDestinationConfig>>;
|
|
9
19
|
}
|
|
10
20
|
export declare const auditDefaults: Required<Pick<AuditConfig, 'enabled' | 'autoDetect'>>;
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAA4B,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE9E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACtD;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,sGAAsG;IACtG,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,0EAA0E;IAC1E,QAAQ,CAAC,MAAM,CAAC,EAAE,gBAAgB,CAAC;IACnC,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC;CACxE;AAED,eAAO,MAAM,aAAa,EAAE,QAAQ,CAClC,IAAI,CAAC,WAAW,EAAE,SAAS,GAAG,YAAY,CAAC,CAI5C,CAAC;AAIF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE3D;AAmCD,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,GAC7C,IAAI,CAuDN;AAED,wBAAgB,iBAAiB,CAC/B,QAAQ,GAAE,WAAgB,GACzB,kBAAkB,CAQpB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,WAAW,CAAC;IAChB,QAAQ,CAAC,KAAK,EAAE;QACd,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;QACnC,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC,OAAO,eAAe,CAAC,EAAE,CAAC;KAC1D,CAAC;CACH;AAED,iBAAS,eAAe,CACtB,KAAK,EAAE,OAAO,EACd,OAAO,EAAE;IAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACtD,IAAI,CAEN"}
|
package/dist/config.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { validateAuditRedactRules } from './redact.js';
|
|
1
3
|
export const auditDefaults = {
|
|
2
4
|
enabled: true,
|
|
3
5
|
autoDetect: false,
|
|
@@ -6,6 +8,24 @@ const validName = /^[a-zA-Z0-9][a-zA-Z0-9_.-]{0,63}$/u;
|
|
|
6
8
|
export function isAuditName(value) {
|
|
7
9
|
return typeof value === 'string' && validName.test(value);
|
|
8
10
|
}
|
|
11
|
+
function validateAuditFileOptions(options, error) {
|
|
12
|
+
const value = options.path;
|
|
13
|
+
if (typeof value !== 'string' ||
|
|
14
|
+
value.includes('\0') ||
|
|
15
|
+
/[/\\]$/.test(value) ||
|
|
16
|
+
!/^[a-zA-Z0-9_-]+\.jsonl$/.test(path.basename(value)))
|
|
17
|
+
error('path', 'must name a .jsonl file with letters, numbers, underscores or hyphens.');
|
|
18
|
+
for (const key of Object.keys(options)) {
|
|
19
|
+
if (key !== 'path' && key !== 'maxFileSizeMB' && key !== 'retentionDays')
|
|
20
|
+
error(key, 'is not a file audit option.');
|
|
21
|
+
}
|
|
22
|
+
for (const key of ['maxFileSizeMB', 'retentionDays']) {
|
|
23
|
+
const value = options[key];
|
|
24
|
+
if (value !== undefined &&
|
|
25
|
+
(typeof value !== 'number' || !Number.isFinite(value) || value <= 0))
|
|
26
|
+
error(key, 'must be a positive finite number.');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
9
29
|
function isMapping(value) {
|
|
10
30
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
11
31
|
}
|
|
@@ -15,13 +35,21 @@ export function validateAuditConfig(value, error) {
|
|
|
15
35
|
return;
|
|
16
36
|
}
|
|
17
37
|
for (const key of Object.keys(value)) {
|
|
18
|
-
if (![
|
|
38
|
+
if (![
|
|
39
|
+
'enabled',
|
|
40
|
+
'autoDetect',
|
|
41
|
+
'captureBody',
|
|
42
|
+
'redact',
|
|
43
|
+
'transports',
|
|
44
|
+
].includes(key))
|
|
19
45
|
error(key, 'is not an audit setting.');
|
|
20
46
|
}
|
|
21
|
-
for (const key of ['enabled', 'autoDetect']) {
|
|
47
|
+
for (const key of ['enabled', 'autoDetect', 'captureBody']) {
|
|
22
48
|
if (value[key] !== undefined && typeof value[key] !== 'boolean')
|
|
23
49
|
error(key, 'must be a boolean.');
|
|
24
50
|
}
|
|
51
|
+
if (value.redact !== undefined)
|
|
52
|
+
validateAuditRedactRules(value.redact, (path, message) => error(path ? `redact.${path}` : 'redact', message));
|
|
25
53
|
if (value.transports === undefined)
|
|
26
54
|
return;
|
|
27
55
|
if (!isMapping(value.transports)) {
|
|
@@ -40,8 +68,12 @@ export function validateAuditConfig(value, error) {
|
|
|
40
68
|
}
|
|
41
69
|
if (Object.keys(destination).some((key) => key !== 'driver' && key !== 'options'))
|
|
42
70
|
error(path, 'accepts only driver and options.');
|
|
43
|
-
if (destination.options !== undefined && !isMapping(destination.options))
|
|
71
|
+
if (destination.options !== undefined && !isMapping(destination.options)) {
|
|
44
72
|
error(`${path}.options`, 'must be a mapping.');
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (value.enabled !== false && destination.driver === 'file')
|
|
76
|
+
validateAuditFileOptions(destination.options ?? {}, (key, message) => error(`${path}.options.${key}`, message));
|
|
45
77
|
}
|
|
46
78
|
}
|
|
47
79
|
export function defineAuditConfig(defaults = {}) {
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,wBAAwB,EAAyB,MAAM,aAAa,CAAC;AAuB9E,MAAM,CAAC,MAAM,aAAa,GAEtB;IACF,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,KAAK;CAClB,CAAC;AAEF,MAAM,SAAS,GAAG,oCAAoC,CAAC;AAEvD,MAAM,UAAU,WAAW,CAAC,KAAc;IACxC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,wBAAwB,CAC/B,OAA0C,EAC1C,KAA6C;IAE7C,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAC3B,IACE,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;QACpB,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAErD,KAAK,CACH,MAAM,EACN,wEAAwE,CACzE,CAAC;IACJ,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,IAAI,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,eAAe,IAAI,GAAG,KAAK,eAAe;YACtE,KAAK,CAAC,GAAG,EAAE,6BAA6B,CAAC,CAAC;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QACX,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,KAAK,KAAK,IAAI,WAAW,CAAC,MAAM,KAAK,MAAM;YAC1D,wBAAwB,CAAC,WAAW,CAAC,OAAO,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CACnE,KAAK,CAAC,GAAG,IAAI,YAAY,GAAG,EAAE,EAAE,OAAO,CAAC,CACzC,CAAC;IACN,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,WAAwB,EAAE;IAE1B,MAAM,MAAM,GAAG,EAAE,GAAG,aAAa,EAAE,GAAG,QAAQ,EAAE,CAAC;IACjD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE;QACjC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC;YACnB,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YACzB,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,CAAC;SAC7C,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAUD,SAAS,eAAe,CACtB,KAAc,EACd,OAAuD;IAEvD,mBAAmB,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type Report = (message: string) => void;
|
|
2
|
+
export declare class FileAuditOutput {
|
|
3
|
+
private readonly directory;
|
|
4
|
+
private readonly name;
|
|
5
|
+
private readonly reports;
|
|
6
|
+
private readonly pattern;
|
|
7
|
+
private retentionDays;
|
|
8
|
+
private limit;
|
|
9
|
+
private output?;
|
|
10
|
+
private pending;
|
|
11
|
+
private cleanup?;
|
|
12
|
+
constructor(directory: string, name: string);
|
|
13
|
+
attach(report: Report, maxFileSizeMB: number, retentionDays: number): void;
|
|
14
|
+
start(): void;
|
|
15
|
+
write(line: Buffer, signal: AbortSignal): Promise<void>;
|
|
16
|
+
detach(report: Report, onLastClose: () => void): Promise<void>;
|
|
17
|
+
private run;
|
|
18
|
+
private stopStream;
|
|
19
|
+
private report;
|
|
20
|
+
private openStream;
|
|
21
|
+
private firstSegment;
|
|
22
|
+
private scheduleCleanup;
|
|
23
|
+
private pruneArchives;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=file-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-output.d.ts","sourceRoot":"","sources":["../src/file-output.ts"],"names":[],"mappings":"AAoBA,KAAK,MAAM,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AA+CxC,qBAAa,eAAe;IAUxB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,IAAI;IAVvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,MAAM,CAAC,CAAe;IAC9B,OAAO,CAAC,OAAO,CAAuC;IACtD,OAAO,CAAC,OAAO,CAAC,CAAgB;gBAGb,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM;IAO/B,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,IAAI;IAS1E,KAAK,IAAI,IAAI;IAIb,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IA6CvD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB9D,OAAO,CAAC,GAAG;YAMG,UAAU;IAQxB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,UAAU;IAiFlB,OAAO,CAAC,YAAY;IAmBpB,OAAO,CAAC,eAAe;YAQT,aAAa;CAiC5B"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { once } from 'node:events';
|
|
2
|
+
import { closeSync, lstatSync, openSync, readSync, readdirSync, realpathSync, unlinkSync, } from 'node:fs';
|
|
3
|
+
import { lstat, readdir } from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { createStream } from 'rotating-file-stream';
|
|
6
|
+
const dayMs = 86_400_000;
|
|
7
|
+
const maxSegment = 999_999;
|
|
8
|
+
function utcDate(time) {
|
|
9
|
+
return time.toISOString().slice(0, 10);
|
|
10
|
+
}
|
|
11
|
+
function isPrivateFile(info) {
|
|
12
|
+
return (info.isFile() &&
|
|
13
|
+
info.nlink === 1 &&
|
|
14
|
+
(process.platform === 'win32' || (info.mode & 0o077) === 0));
|
|
15
|
+
}
|
|
16
|
+
function assertPrivateFile(info) {
|
|
17
|
+
if (!isPrivateFile(info))
|
|
18
|
+
throw new Error('Audit destination must be a private regular file.');
|
|
19
|
+
}
|
|
20
|
+
function endsWithNewline(file, size) {
|
|
21
|
+
if (size === 0)
|
|
22
|
+
return true;
|
|
23
|
+
const handle = openSync(file, 'r');
|
|
24
|
+
try {
|
|
25
|
+
const last = Buffer.alloc(1);
|
|
26
|
+
if (readSync(handle, last, 0, 1, size - 1) !== 1)
|
|
27
|
+
throw new Error('Could not read the audit file tail.');
|
|
28
|
+
return last[0] === 10;
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
closeSync(handle);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export class FileAuditOutput {
|
|
35
|
+
directory;
|
|
36
|
+
name;
|
|
37
|
+
reports = new Set();
|
|
38
|
+
pattern;
|
|
39
|
+
retentionDays = 0;
|
|
40
|
+
limit = Number.MAX_SAFE_INTEGER;
|
|
41
|
+
output;
|
|
42
|
+
pending = Promise.resolve();
|
|
43
|
+
cleanup;
|
|
44
|
+
constructor(directory, name) {
|
|
45
|
+
this.directory = directory;
|
|
46
|
+
this.name = name;
|
|
47
|
+
this.pattern = new RegExp(`^${name}\\.(\\d{4}-\\d{2}-\\d{2})\\.(\\d{6})\\.jsonl$`);
|
|
48
|
+
}
|
|
49
|
+
attach(report, maxFileSizeMB, retentionDays) {
|
|
50
|
+
this.reports.add(report);
|
|
51
|
+
this.retentionDays = Math.max(this.retentionDays, retentionDays);
|
|
52
|
+
this.limit = Math.min(this.limit, Math.max(1, Math.floor(maxFileSizeMB * 1024 ** 2)));
|
|
53
|
+
}
|
|
54
|
+
start() {
|
|
55
|
+
this.output ??= this.openStream();
|
|
56
|
+
}
|
|
57
|
+
write(line, signal) {
|
|
58
|
+
// Admit one record at a time. The coordinator bounds the waiting writes
|
|
59
|
+
// and aborts them at the deadline before they can enter the stream.
|
|
60
|
+
return this.run(async () => {
|
|
61
|
+
signal.throwIfAborted();
|
|
62
|
+
if (this.output &&
|
|
63
|
+
(this.output.stream.destroyed || this.output.limit !== this.limit))
|
|
64
|
+
await this.stopStream();
|
|
65
|
+
signal.throwIfAborted();
|
|
66
|
+
this.start();
|
|
67
|
+
const output = this.output;
|
|
68
|
+
const write = {};
|
|
69
|
+
output.write = write;
|
|
70
|
+
try {
|
|
71
|
+
// During idle rotation the library can queue a write before the next
|
|
72
|
+
// open event. Wait for our file checks before submitting any bytes.
|
|
73
|
+
if (!output.active)
|
|
74
|
+
await once(output.stream, 'open', { signal });
|
|
75
|
+
const segment = output.active;
|
|
76
|
+
if (!segment)
|
|
77
|
+
throw output.error ?? new Error('Audit segment is not open.');
|
|
78
|
+
signal.throwIfAborted();
|
|
79
|
+
write.segment = segment;
|
|
80
|
+
await new Promise((resolve, reject) => {
|
|
81
|
+
output.stream.write(line, (error) => error ? reject(error) : resolve());
|
|
82
|
+
});
|
|
83
|
+
if (output.error)
|
|
84
|
+
throw output.error;
|
|
85
|
+
// The pinned stream ignores FileHandle.write's byte count. Detect a
|
|
86
|
+
// short append before allowing another record into that segment.
|
|
87
|
+
if ((await lstat(segment.file)).size !== segment.size + line.length)
|
|
88
|
+
throw new Error('Audit record was not written in full.');
|
|
89
|
+
segment.size += line.length;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
output.stream.destroy();
|
|
93
|
+
await output.closed;
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
output.write = undefined;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
detach(report, onLastClose) {
|
|
102
|
+
return this.run(async () => {
|
|
103
|
+
if (this.reports.size > 1) {
|
|
104
|
+
this.reports.delete(report);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
await this.stopStream();
|
|
109
|
+
await this.cleanup;
|
|
110
|
+
}
|
|
111
|
+
finally {
|
|
112
|
+
this.reports.delete(report);
|
|
113
|
+
if (this.reports.size === 0)
|
|
114
|
+
onLastClose();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
run(operation) {
|
|
119
|
+
const result = this.pending.then(operation);
|
|
120
|
+
this.pending = result.catch(() => undefined);
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
async stopStream() {
|
|
124
|
+
const output = this.output;
|
|
125
|
+
if (!output)
|
|
126
|
+
return;
|
|
127
|
+
output.stream.end();
|
|
128
|
+
await output.closed;
|
|
129
|
+
this.output = undefined;
|
|
130
|
+
}
|
|
131
|
+
report(message) {
|
|
132
|
+
for (const report of this.reports)
|
|
133
|
+
report(message);
|
|
134
|
+
}
|
|
135
|
+
openStream() {
|
|
136
|
+
let day;
|
|
137
|
+
let offset = 0;
|
|
138
|
+
let lastOpened;
|
|
139
|
+
let number = 0;
|
|
140
|
+
const limit = this.limit;
|
|
141
|
+
let probed = false;
|
|
142
|
+
const stream = createStream((args) => {
|
|
143
|
+
if (!args)
|
|
144
|
+
return `${this.name}.jsonl`;
|
|
145
|
+
const date = utcDate(args.time);
|
|
146
|
+
// createStream probes distinct names before it schedules the open.
|
|
147
|
+
if (!probed)
|
|
148
|
+
return `${this.name}.${date}.${args.index}.jsonl`;
|
|
149
|
+
if (realpathSync.native(this.directory) !== this.directory)
|
|
150
|
+
throw new Error('Audit directory must remain at its resolved path.');
|
|
151
|
+
if (date !== day) {
|
|
152
|
+
offset = this.firstSegment(date, lastOpened === undefined);
|
|
153
|
+
day = date;
|
|
154
|
+
}
|
|
155
|
+
else if (args.index === 1 && lastOpened !== undefined) {
|
|
156
|
+
offset = lastOpened + 1;
|
|
157
|
+
}
|
|
158
|
+
number = offset + args.index - 1;
|
|
159
|
+
if (number > maxSegment)
|
|
160
|
+
throw new Error('Audit segment sequence is exhausted for this date.');
|
|
161
|
+
const file = `${this.name}.${date}.${String(number).padStart(6, '0')}.jsonl`;
|
|
162
|
+
output.opening = path.join(this.directory, file);
|
|
163
|
+
return file;
|
|
164
|
+
}, {
|
|
165
|
+
path: this.directory,
|
|
166
|
+
mode: 0o600,
|
|
167
|
+
size: `${limit}B`,
|
|
168
|
+
immutable: true,
|
|
169
|
+
interval: '1d',
|
|
170
|
+
intervalBoundary: true,
|
|
171
|
+
intervalUTC: true,
|
|
172
|
+
});
|
|
173
|
+
// Read standard events through Node's Writable types. The library's
|
|
174
|
+
// event overloads omit close and error with this workspace's Node types.
|
|
175
|
+
const writable = stream;
|
|
176
|
+
const closed = new Promise((resolve) => writable.once('close', resolve));
|
|
177
|
+
const output = { stream: writable, closed, limit };
|
|
178
|
+
probed = true;
|
|
179
|
+
stream.on('rotation', () => {
|
|
180
|
+
output.active = undefined;
|
|
181
|
+
});
|
|
182
|
+
stream.on('open', (file) => {
|
|
183
|
+
try {
|
|
184
|
+
const info = lstatSync(file);
|
|
185
|
+
assertPrivateFile(info);
|
|
186
|
+
// Immutable rotation opens with a zero size counter. Only the initial
|
|
187
|
+
// open can resume a populated segment.
|
|
188
|
+
if (lastOpened !== undefined && info.size > 0)
|
|
189
|
+
throw new Error('Audit rotation selected a populated segment.');
|
|
190
|
+
const segment = { file, size: info.size };
|
|
191
|
+
output.active = segment;
|
|
192
|
+
output.opening = undefined;
|
|
193
|
+
lastOpened = number;
|
|
194
|
+
this.scheduleCleanup();
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
// Initial open is emitted outside the library's rejection handler.
|
|
198
|
+
// Destroy through Writable so the handle closes and writes settle.
|
|
199
|
+
output.error =
|
|
200
|
+
error instanceof Error ? error : new Error(String(error));
|
|
201
|
+
stream.destroy(output.error);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
writable.on('error', (error) => {
|
|
205
|
+
output.error = error;
|
|
206
|
+
if (!output.write)
|
|
207
|
+
this.report('Could not open or rotate audit files.');
|
|
208
|
+
});
|
|
209
|
+
stream.on('warning', () => this.report('Audit file stream reported a warning.'));
|
|
210
|
+
return output;
|
|
211
|
+
}
|
|
212
|
+
firstSegment(date, resume) {
|
|
213
|
+
let highest = -1;
|
|
214
|
+
for (const name of readdirSync(this.directory)) {
|
|
215
|
+
const match = this.pattern.exec(name);
|
|
216
|
+
if (match?.[1] === date)
|
|
217
|
+
highest = Math.max(highest, Number(match[2]));
|
|
218
|
+
}
|
|
219
|
+
if (highest < 0 || !resume)
|
|
220
|
+
return highest + 1;
|
|
221
|
+
const file = path.join(this.directory, `${this.name}.${date}.${String(highest).padStart(6, '0')}.jsonl`);
|
|
222
|
+
const info = lstatSync(file);
|
|
223
|
+
assertPrivateFile(info);
|
|
224
|
+
if (endsWithNewline(file, info.size))
|
|
225
|
+
return highest;
|
|
226
|
+
this.report('Audit file ends with an incomplete line.');
|
|
227
|
+
return highest + 1;
|
|
228
|
+
}
|
|
229
|
+
scheduleCleanup() {
|
|
230
|
+
this.cleanup ??= this.pruneArchives()
|
|
231
|
+
.catch(() => this.report('Could not clean up audit files.'))
|
|
232
|
+
.finally(() => {
|
|
233
|
+
this.cleanup = undefined;
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
async pruneArchives() {
|
|
237
|
+
const files = await readdir(this.directory);
|
|
238
|
+
for (const name of files) {
|
|
239
|
+
const match = this.pattern.exec(name);
|
|
240
|
+
if (!match)
|
|
241
|
+
continue;
|
|
242
|
+
const date = match[1];
|
|
243
|
+
const parsed = new Date(date);
|
|
244
|
+
if (!Number.isFinite(parsed.getTime()) || utcDate(parsed) !== date)
|
|
245
|
+
continue;
|
|
246
|
+
if (date === utcDate(new Date()))
|
|
247
|
+
continue;
|
|
248
|
+
const file = path.join(this.directory, name);
|
|
249
|
+
try {
|
|
250
|
+
const info = await lstat(file);
|
|
251
|
+
if (isPrivateFile(info) &&
|
|
252
|
+
Date.now() - info.mtimeMs > this.retentionDays * dayMs &&
|
|
253
|
+
date !== utcDate(new Date()) &&
|
|
254
|
+
file !== this.output?.opening &&
|
|
255
|
+
file !== this.output?.active?.file &&
|
|
256
|
+
file !== this.output?.write?.segment?.file)
|
|
257
|
+
// Unlink in the same turn as the final active-file check.
|
|
258
|
+
unlinkSync(file);
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
if (!(error instanceof Error) ||
|
|
262
|
+
!('code' in error) ||
|
|
263
|
+
error.code !== 'ENOENT')
|
|
264
|
+
this.report('Could not clean up audit files.');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
//# sourceMappingURL=file-output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-output.js","sourceRoot":"","sources":["../src/file-output.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,EACL,SAAS,EACT,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,YAAY,EACZ,UAAU,GAEX,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MA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AC,CAAC;YACnD,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
package/dist/file-transport.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import type { AuditTransportDriver } from './
|
|
2
|
-
export declare
|
|
1
|
+
import type { AuditTransportDriver } from './service.js';
|
|
2
|
+
export declare function createFileAuditDriver(): AuditTransportDriver & {
|
|
3
|
+
prepare(): Promise<void>;
|
|
4
|
+
};
|
|
3
5
|
//# sourceMappingURL=file-transport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-transport.d.ts","sourceRoot":"","sources":["../src/file-transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file-transport.d.ts","sourceRoot":"","sources":["../src/file-transport.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAGV,oBAAoB,EACrB,MAAM,cAAc,CAAC;AAatB,wBAAgB,qBAAqB,IAAI,oBAAoB,GAAG;IAC9D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B,CAsBA"}
|