feat(core-audit): package barrel exports
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,8 +7,8 @@ describe("auditLogsCollection", () => {
|
||||
});
|
||||
|
||||
it("is append-only (update: () => false)", () => {
|
||||
const access = auditLogsCollection.access as Record<string, () => boolean>;
|
||||
expect(access.update()).toBe(false);
|
||||
const access = auditLogsCollection.access as Record<string, (() => boolean) | undefined>;
|
||||
expect(access["update"]?.()).toBe(false);
|
||||
});
|
||||
|
||||
it("has the required fields", () => {
|
||||
|
||||
@@ -39,14 +39,15 @@ describe("bindAudit", () => {
|
||||
});
|
||||
|
||||
it("validates AUDIT_PSEUDONYM_SALT in production", () => {
|
||||
const oldEnv = process.env.NODE_ENV;
|
||||
const oldSalt = process.env.AUDIT_PSEUDONYM_SALT;
|
||||
process.env.NODE_ENV = "production";
|
||||
delete process.env.AUDIT_PSEUDONYM_SALT;
|
||||
const env = process.env as Record<string, string | undefined>;
|
||||
const oldEnv = env["NODE_ENV"];
|
||||
const oldSalt = env["AUDIT_PSEUDONYM_SALT"];
|
||||
env["NODE_ENV"] = "production";
|
||||
delete env["AUDIT_PSEUDONYM_SALT"];
|
||||
expect(() => bindAudit(new Container(), { sinks: ["stdout"] })).toThrow(
|
||||
/AUDIT_PSEUDONYM_SALT/,
|
||||
);
|
||||
process.env.NODE_ENV = oldEnv;
|
||||
if (oldSalt) process.env.AUDIT_PSEUDONYM_SALT = oldSalt;
|
||||
env["NODE_ENV"] = oldEnv;
|
||||
if (oldSalt) env["AUDIT_PSEUDONYM_SALT"] = oldSalt;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import "reflect-metadata";
|
||||
import type { Container } from "inversify";
|
||||
import { getPayload, type SanitizedConfig } from "payload";
|
||||
import { getPayload as _getPayload, type SanitizedConfig } from "payload";
|
||||
import { NoopAuditLog } from "../noop-audit-log";
|
||||
import { PayloadAuditLog } from "../payload-audit-log";
|
||||
import { StdoutJsonAuditLog } from "../stdout-json-audit-log";
|
||||
@@ -42,7 +42,8 @@ export function bindAudit(
|
||||
const sinkList = opts.sinks ?? ["payload", "stdout"];
|
||||
const sinks: IAuditLog[] = [];
|
||||
if (sinkList.includes("payload") && opts.payloadConfig) {
|
||||
sinks.push(new PayloadAuditLog(opts.payloadConfig, getPayload));
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
sinks.push(new PayloadAuditLog(opts.payloadConfig, _getPayload as any));
|
||||
}
|
||||
if (sinkList.includes("stdout")) {
|
||||
sinks.push(new StdoutJsonAuditLog());
|
||||
|
||||
9
packages/core-audit/src/index.ts
Normal file
9
packages/core-audit/src/index.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export type { IAuditLog } from "./audit-log.interface";
|
||||
export type { AuditEntry, AuditAction, AuditFrom } from "@repo/core-shared/audit";
|
||||
export { NoopAuditLog } from "./noop-audit-log";
|
||||
export { StdoutJsonAuditLog } from "./stdout-json-audit-log";
|
||||
export { PayloadAuditLog } from "./payload-audit-log";
|
||||
export { MultiSinkAuditLog } from "./multi-sink-audit-log";
|
||||
export { auditLogsCollection } from "./audit-logs-collection";
|
||||
export { bindAudit, type BindAuditOpts } from "./di/bind-audit";
|
||||
export { AUDIT_SYMBOLS } from "./di/symbols";
|
||||
@@ -16,7 +16,8 @@ const sample: AuditEntry = {
|
||||
};
|
||||
|
||||
describe("StdoutJsonAuditLog", () => {
|
||||
let writeSpy: ReturnType<typeof vi.spyOn>;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let writeSpy: ReturnType<typeof vi.spyOn<any, any>>;
|
||||
beforeEach(() => {
|
||||
writeSpy = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user