mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 05:12:14 +00:00
The annual-blood-panel auto-resolve that findLatestLabResultForAnalytes was meant to feed never got wired into the Vorsorge reminder, so the export sits with zero callers and the labAnalyteTrend query-key has no consumer (the sparkline is prop-fed and there is no labs trend endpoint). Remove both so the knip gate is clean; the Vorsorge lab read-back can come back with the wiring that needs it.
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
/**
|
|
* v1.17.1 — server-side helpers for the structured lab-result store.
|
|
*
|
|
* The AES-256-GCM ↔ `Bytes` codec for `LabResult.noteEncrypted`. The
|
|
* free-text note is the only sensitive column on the model; it shares the
|
|
* `encrypt()` string format (`"<keyId>.<base64>"`) every other `*Encrypted`
|
|
* column uses, encoded as UTF-8 bytes.
|
|
*/
|
|
import { Buffer } from "node:buffer";
|
|
|
|
import { decrypt, encrypt } from "@/lib/crypto";
|
|
|
|
/** Encrypt a UTF-8 note into the `Bytes` payload the schema stores. */
|
|
export function encryptNoteToBytes(plaintext: string): Uint8Array<ArrayBuffer> {
|
|
const ciphertext = encrypt(plaintext);
|
|
const encoded = Buffer.from(ciphertext, "utf8");
|
|
// Prisma `Bytes` maps to `Uint8Array<ArrayBuffer>`; allocate a fresh
|
|
// ArrayBuffer-backed view so the structural type stays stable.
|
|
const out = new Uint8Array(new ArrayBuffer(encoded.byteLength));
|
|
out.set(encoded);
|
|
return out;
|
|
}
|
|
|
|
/** Decrypt a stored `Bytes` note back to plaintext. Throws on a bad key id. */
|
|
export function decryptNoteFromBytes(buf: Uint8Array): string {
|
|
return decrypt(Buffer.from(buf).toString("utf8"));
|
|
}
|