Mechanical rename produced by scripts/msd-rename.cjs: gsd/Gsd/GSD -> msd/Msd/MSD across contents and paths, upstream package/repo coordinates -> @golem15/msd-core and golem15com/msd-core. Deep links into upstream history, sibling upstream packages, the GSD-2 import feature, CHANGELOG.md and .changeset/ are kept as-is. Hand edits on top: MSD block-letter banner and logos, LICENSE copyright line, package/plugin identity, regenerated lockfile, install-tree fixtures, derived registries and benchmark baseline; migration checksum baseline re-locked (MSD keeps its own install state, so no install had applied the old sums); sort-order and regex-escaped expectations in tests adjusted.
53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
/**
|
|
* Arg redaction policy — issue #177 (ADR-457 build-at-publish: the
|
|
* hand-written bin/lib/observability/redaction.cjs collapsed to a TypeScript
|
|
* source of truth). Behaviour is preserved byte-for-behaviour from the prior
|
|
* hand-written .cjs; only types are added.
|
|
*
|
|
* Privacy default: args are OMITTED from every emitted event (both stderr
|
|
* and file audit). Opt-in: set MSD_AUDIT_ARGS=1 to include args verbatim.
|
|
*
|
|
* This module is deliberately simple and has no side effects — redaction
|
|
* decisions are stateless reads of process.env at call time so that tests
|
|
* can toggle the env var without module-level caching issues.
|
|
*/
|
|
|
|
/**
|
|
* A DispatchEvent (frozen or plain). Must be an object; `args` is optional.
|
|
*/
|
|
export type DispatchEvent = Record<string, unknown>;
|
|
|
|
/**
|
|
* Returns true when the caller has opted in to including args in events.
|
|
* Only MSD_AUDIT_ARGS === '1' enables inclusion; any other value (including
|
|
* empty string, 'true', 'yes') keeps the default of omitting args.
|
|
*/
|
|
export function shouldIncludeArgs(): boolean {
|
|
return process.env.MSD_AUDIT_ARGS === '1';
|
|
}
|
|
|
|
/**
|
|
* Return a redacted copy of a DispatchEvent.
|
|
*
|
|
* If args should be omitted (default), strips the `args` field entirely.
|
|
* If args should be included (MSD_AUDIT_ARGS=1), passes the event through
|
|
* unchanged (args were already set by makeDispatchEvent with includeArgs:true,
|
|
* or absent — in which case they stay absent).
|
|
*
|
|
* The original event object is never mutated (it is frozen by makeDispatchEvent).
|
|
*
|
|
* @param event - A DispatchEvent (frozen or plain).
|
|
* @returns A new plain object with the same fields, minus args when redacted.
|
|
*/
|
|
export function redactEvent(event: DispatchEvent): DispatchEvent {
|
|
if (shouldIncludeArgs()) {
|
|
// Include path: return a shallow copy with args preserved if present
|
|
const copy = Object.assign({}, event);
|
|
return copy;
|
|
}
|
|
|
|
// Exclude path: build a copy omitting `args`
|
|
const { args: _dropped, ...rest } = event;
|
|
return rest;
|
|
}
|