feat(admin): pulse day-mean dry run, apply step and admin card

This commit is contained in:
Marc-André Bombeck committed 2026-10-16 00:58:48 +02:00
1 parent 877920f5f7
commit 9f17cef8e4
17 files changed
+915 -16

No files matched your search

-14
View File
@@ -63,9 +63,6 @@ export interface PulseDayMeanPayload {
action: "dry_run" | "rebuild";
}
/** How old a finished dry run may be for the apply step to accept it. */
export const DRY_RUN_FRESH_MS = 7 * 24 * 60 * 60 * 1000;
const DAY_MS = 24 * 60 * 60 * 1000;
/** Days of one account's pulse a dry-run statement covers. */
const DRY_RUN_WINDOW_DAYS = 90;
@@ -131,17 +128,6 @@ export async function readPulseDayMeanStatus(): Promise<PulseDayMeanStatus> {
};
}
/** A finished dry run from the last seven days, the apply step's condition. */
export function hasFreshDryRun(
status: PulseDayMeanStatus,
now: Date = new Date(),
): boolean {
const run = status.lastDryRun;
if (!run || run.status !== "done" || run.finishedAt === null) return false;
const finished = Date.parse(run.finishedAt);
return Number.isFinite(finished) && now.getTime() - finished <= DRY_RUN_FRESH_MS;
}
/** The only write a dry run makes. */
export async function writeDryRun(run: PulseDayMeanDryRun): Promise<void> {
await prisma.appSettings.upsert({
+2
View File
@@ -53,6 +53,8 @@ export const adminKeys = {
adminEncryptionStatus: () => ["admin", "encryption", "status"] as const,
adminMeasurementMaintenance: () =>
["admin", "maintenance", "measurements"] as const,
/** v1.43 — the pulse day-mean method, its dry run and apply step. */
adminPulseDayMean: () => ["admin", "maintenance", "pulse-day-mean"] as const,
/** v1.40.0 — the "Back up your encryption key" step (admin + dashboard banner). */
adminEncryptionKeyBackup: () =>
["admin", "encryption", "key-backup"] as const,
+19
View File
@@ -56,3 +56,22 @@ export interface PulseDayMeanStatus {
appliedAt: string | null;
lastDryRun: PulseDayMeanDryRun | null;
}
/** How old a finished dry run may be for the apply step to accept it. */
const DRY_RUN_FRESH_MS = 7 * 24 * 60 * 60 * 1000;
/**
* A finished dry run from the last seven days: the apply step's condition,
* enforced by the route and mirrored by the admin card's button.
*/
export function hasFreshDryRun(
status: Pick<PulseDayMeanStatus, "lastDryRun">,
now: Date = new Date(),
): boolean {
const run = status.lastDryRun;
if (!run || run.status !== "done" || run.finishedAt === null) return false;
const finished = Date.parse(run.finishedAt);
return (
Number.isFinite(finished) && now.getTime() - finished <= DRY_RUN_FRESH_MS
);
}