style: apply Biome formatting to enterprise files

This commit is contained in:
SnapOtter
2026-06-14 14:53:44 +08:00
parent 954cfb01a6
commit e7bef34918
23 changed files with 166 additions and 228 deletions
+1 -5
View File
@@ -16,11 +16,7 @@ export function computeHmac(data: Record<string, unknown>, key: Buffer): string
return createHmac("sha256", key).update(canonicalize(data)).digest("hex");
}
export function verifyHmac(
data: Record<string, unknown>,
hmac: string,
key: Buffer,
): boolean {
export function verifyHmac(data: Record<string, unknown>, hmac: string, key: Buffer): boolean {
const computed = computeHmac(data, key);
return computed === hmac;
}
+1 -4
View File
@@ -100,10 +100,7 @@ export async function auditLog(
requestId,
};
const integrity = computeHmac(rowData, hmacKey);
await db
.update(schema.auditLog)
.set({ integrity })
.where(eq(schema.auditLog.id, id));
await db.update(schema.auditLog).set({ integrity }).where(eq(schema.auditLog.id, id));
}
} catch {
logger.warn({ event }, "Failed to compute audit HMAC");
+1 -6
View File
@@ -1,9 +1,4 @@
import {
createCipheriv,
createDecipheriv,
randomBytes,
hkdf as hkdfCb,
} from "node:crypto";
import { createCipheriv, createDecipheriv, hkdf as hkdfCb, randomBytes } from "node:crypto";
import { promisify } from "node:util";
const hkdf = promisify(hkdfCb);
+6 -1
View File
@@ -50,7 +50,12 @@ export async function deliverWebhook(
lastError = `HTTP ${response.status}`;
// Don't retry 4xx errors (client errors = won't succeed on retry)
if (response.status >= 400 && response.status < 500) {
return { success: false, statusCode: response.status, error: lastError, attempts: attempt + 1 };
return {
success: false,
statusCode: response.status,
error: lastError,
attempts: attempt + 1,
};
}
} catch (err) {
lastError = err instanceof Error ? err.message : String(err);
+5 -1
View File
@@ -86,7 +86,11 @@ export async function apiKeyRoutes(app: FastifyInstance): Promise<void> {
return reply.status(409).send({ error: "Failed to create API key" });
}
await auditFromRequest(request)("API_KEY_CREATED", { userId: user.id, keyId: id, keyName: name });
await auditFromRequest(request)("API_KEY_CREATED", {
userId: user.id,
keyId: id,
keyName: name,
});
// Return the raw key ONCE — it cannot be retrieved again
return reply.status(201).send({
+10 -11
View File
@@ -35,9 +35,9 @@ export async function registerSiemRoutes(app: FastifyInstance): Promise<void> {
// Enterprise package not available
}
if (!featureEnabled) {
return reply
.status(403)
.send({ error: "SIEM forwarding requires an enterprise license with the siem_forwarding feature" });
return reply.status(403).send({
error: "SIEM forwarding requires an enterprise license with the siem_forwarding feature",
});
}
const [row] = await db
@@ -65,10 +65,7 @@ export async function registerSiemRoutes(app: FastifyInstance): Promise<void> {
// PUT /api/v1/enterprise/siem/config
app.put(
"/api/v1/enterprise/siem/config",
async (
request: FastifyRequest<{ Body: unknown }>,
reply: FastifyReply,
) => {
async (request: FastifyRequest<{ Body: unknown }>, reply: FastifyReply) => {
const user = await requirePermission("webhooks:manage")(request, reply);
if (!user) return;
@@ -81,14 +78,16 @@ export async function registerSiemRoutes(app: FastifyInstance): Promise<void> {
// Enterprise package not available
}
if (!featureEnabled) {
return reply
.status(403)
.send({ error: "SIEM forwarding requires an enterprise license with the siem_forwarding feature" });
return reply.status(403).send({
error: "SIEM forwarding requires an enterprise license with the siem_forwarding feature",
});
}
const parsed = configSchema.safeParse(request.body);
if (!parsed.success) {
return reply.status(400).send({ error: "Invalid SIEM config", details: parsed.error.issues });
return reply
.status(400)
.send({ error: "Invalid SIEM config", details: parsed.error.issues });
}
const config = { ...parsed.data };
+7 -4
View File
@@ -9,10 +9,10 @@
import { eq } from "drizzle-orm";
import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
import { z } from "zod";
import { env } from "../config.js";
import { db, schema } from "../db/index.js";
import { auditFromRequest } from "../lib/audit.js";
import { env } from "../config.js";
import { encrypt, decrypt, isEncrypted } from "../lib/encryption.js";
import { decrypt, encrypt, isEncrypted } from "../lib/encryption.js";
import { requirePermission } from "../permissions.js";
import { requireAuth } from "../plugins/auth.js";
@@ -37,8 +37,11 @@ async function decryptIfNeeded(value: string): Promise<string> {
if (!isEncrypted(value)) return value;
if (!env.DATA_ENCRYPTION_KEY) return value;
return (
(await decrypt(value, env.DATA_ENCRYPTION_KEY, env.DATA_ENCRYPTION_KEY_PREVIOUS || undefined)) ??
value
(await decrypt(
value,
env.DATA_ENCRYPTION_KEY,
env.DATA_ENCRYPTION_KEY_PREVIOUS || undefined,
)) ?? value
);
}