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)", () => {
|
it("is append-only (update: () => false)", () => {
|
||||||
const access = auditLogsCollection.access as Record<string, () => boolean>;
|
const access = auditLogsCollection.access as Record<string, (() => boolean) | undefined>;
|
||||||
expect(access.update()).toBe(false);
|
expect(access["update"]?.()).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("has the required fields", () => {
|
it("has the required fields", () => {
|
||||||
|
|||||||
@@ -39,14 +39,15 @@ describe("bindAudit", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("validates AUDIT_PSEUDONYM_SALT in production", () => {
|
it("validates AUDIT_PSEUDONYM_SALT in production", () => {
|
||||||
const oldEnv = process.env.NODE_ENV;
|
const env = process.env as Record<string, string | undefined>;
|
||||||
const oldSalt = process.env.AUDIT_PSEUDONYM_SALT;
|
const oldEnv = env["NODE_ENV"];
|
||||||
process.env.NODE_ENV = "production";
|
const oldSalt = env["AUDIT_PSEUDONYM_SALT"];
|
||||||
delete process.env.AUDIT_PSEUDONYM_SALT;
|
env["NODE_ENV"] = "production";
|
||||||
|
delete env["AUDIT_PSEUDONYM_SALT"];
|
||||||
expect(() => bindAudit(new Container(), { sinks: ["stdout"] })).toThrow(
|
expect(() => bindAudit(new Container(), { sinks: ["stdout"] })).toThrow(
|
||||||
/AUDIT_PSEUDONYM_SALT/,
|
/AUDIT_PSEUDONYM_SALT/,
|
||||||
);
|
);
|
||||||
process.env.NODE_ENV = oldEnv;
|
env["NODE_ENV"] = oldEnv;
|
||||||
if (oldSalt) process.env.AUDIT_PSEUDONYM_SALT = oldSalt;
|
if (oldSalt) env["AUDIT_PSEUDONYM_SALT"] = oldSalt;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import type { Container } from "inversify";
|
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 { NoopAuditLog } from "../noop-audit-log";
|
||||||
import { PayloadAuditLog } from "../payload-audit-log";
|
import { PayloadAuditLog } from "../payload-audit-log";
|
||||||
import { StdoutJsonAuditLog } from "../stdout-json-audit-log";
|
import { StdoutJsonAuditLog } from "../stdout-json-audit-log";
|
||||||
@@ -42,7 +42,8 @@ export function bindAudit(
|
|||||||
const sinkList = opts.sinks ?? ["payload", "stdout"];
|
const sinkList = opts.sinks ?? ["payload", "stdout"];
|
||||||
const sinks: IAuditLog[] = [];
|
const sinks: IAuditLog[] = [];
|
||||||
if (sinkList.includes("payload") && opts.payloadConfig) {
|
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")) {
|
if (sinkList.includes("stdout")) {
|
||||||
sinks.push(new StdoutJsonAuditLog());
|
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", () => {
|
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(() => {
|
beforeEach(() => {
|
||||||
writeSpy = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
|
writeSpy = vi.spyOn(process.stdout, "write").mockImplementation(() => true);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user