fix(housekeeping): require reasons for destructive changes
This commit is contained in:
1 parent
50598472ad
commit
93367a239f
16 files changed
+323
-15
No files matched your search
@@ -1,4 +1,8 @@
|
||||
import { fail, type HousekeepingResult, ok } from "../contracts";
|
||||
import {
|
||||
normalizeHousekeepingReason,
|
||||
requiresHousekeepingReason,
|
||||
} from "./reason-policy";
|
||||
import type { HousekeepingCommand } from "./registry";
|
||||
|
||||
export interface HousekeepingCommandConfirmation {
|
||||
@@ -12,9 +16,14 @@ export function confirmHousekeepingCommand<I, O>(
|
||||
command: HousekeepingCommand<I, O>,
|
||||
reason: string | undefined,
|
||||
correlationId: string,
|
||||
input?: I,
|
||||
): HousekeepingResult<HousekeepingCommandConfirmation> {
|
||||
const normalizedReason = reason?.normalize("NFC").trim() || undefined;
|
||||
if (command.requiresReason && !normalizedReason) {
|
||||
const normalizedReason = normalizeHousekeepingReason(reason);
|
||||
const reasonRequired = requiresHousekeepingReason(
|
||||
command.requiresReason,
|
||||
input,
|
||||
);
|
||||
if (reasonRequired && !normalizedReason) {
|
||||
return fail("VALIDATION", "errors.housekeeping.validation", correlationId, {
|
||||
reason: ["errors.validation.required"],
|
||||
});
|
||||
@@ -24,7 +33,7 @@ export function confirmHousekeepingCommand<I, O>(
|
||||
{
|
||||
commandId: command.id,
|
||||
risk: command.risk,
|
||||
requiresReason: command.requiresReason,
|
||||
requiresReason: reasonRequired,
|
||||
...(normalizedReason === undefined ? {} : { reason: normalizedReason }),
|
||||
},
|
||||
correlationId,
|
||||
|
||||
Reference in new issue
Block a user