Add Velum project workflow and standalone migration tool
This commit is contained in:
65
src/velum.ts
65
src/velum.ts
@@ -108,6 +108,7 @@ export async function pseudonymize(
|
||||
text: string,
|
||||
mapping: PlaceholderMapping,
|
||||
entityTypes?: EntityType[],
|
||||
forceMasks?: Record<string, string[]>,
|
||||
): Promise<PseudonymizeResponse> {
|
||||
const response = await fetchWithAuth(apiUrl("/api/pseudonymize"), {
|
||||
method: "POST",
|
||||
@@ -119,12 +120,76 @@ export async function pseudonymize(
|
||||
mapping,
|
||||
entity_types:
|
||||
entityTypes && entityTypes.length > 0 ? entityTypes : undefined,
|
||||
force_masks: forceMasks,
|
||||
}),
|
||||
});
|
||||
|
||||
return parseJsonResponse<PseudonymizeResponse>(response);
|
||||
}
|
||||
|
||||
export type DocumentHit = {
|
||||
id: string;
|
||||
source: string;
|
||||
context: string;
|
||||
start: number;
|
||||
end: number;
|
||||
type: string;
|
||||
score: number;
|
||||
placeholder: string;
|
||||
original: string;
|
||||
};
|
||||
|
||||
export async function requireProjectCapabilities(): Promise<void> {
|
||||
const response = await fetchWithAuth(apiUrl("/api/project-capabilities"));
|
||||
if (!response.ok) throw new Error("Die Velum-API muss für die Projektfunktionen aktualisiert werden.");
|
||||
const capabilities = await parseJsonResponse<Record<string, boolean>>(response);
|
||||
if (!capabilities.request_force_masks || !capabilities.document_hit_review || !capabilities.document_restoration) {
|
||||
throw new Error("Die Velum-API unterstützt die Projektfunktionen noch nicht vollständig.");
|
||||
}
|
||||
}
|
||||
|
||||
export type DocumentResult = {
|
||||
filename: string;
|
||||
content_type: string;
|
||||
file_base64: string;
|
||||
mapping: PlaceholderMapping;
|
||||
active_placeholders: string[];
|
||||
hits: DocumentHit[];
|
||||
};
|
||||
|
||||
export async function pseudonymizeDocument(
|
||||
filename: string,
|
||||
data: Buffer,
|
||||
mapping: PlaceholderMapping,
|
||||
forceMasks: Record<string, string[]>,
|
||||
acceptedHitIds?: string[],
|
||||
): Promise<DocumentResult> {
|
||||
const form = new FormData();
|
||||
form.set("file", new Blob([new Uint8Array(data)]), filename);
|
||||
form.set("mapping", JSON.stringify(mapping));
|
||||
form.set("force_masks", JSON.stringify(forceMasks));
|
||||
if (acceptedHitIds) form.set("accepted_hit_ids", JSON.stringify(acceptedHitIds));
|
||||
const response = await fetchWithAuth(apiUrl("/api/pseudonymize-document"), {
|
||||
method: "POST", body: form,
|
||||
});
|
||||
return parseJsonResponse<DocumentResult>(response);
|
||||
}
|
||||
|
||||
export async function depseudonymizeDocument(
|
||||
filename: string,
|
||||
data: Buffer,
|
||||
mapping: PlaceholderMapping,
|
||||
): Promise<Buffer> {
|
||||
const form = new FormData();
|
||||
form.set("file", new Blob([new Uint8Array(data)]), filename);
|
||||
form.set("mapping", JSON.stringify(mapping));
|
||||
const response = await fetchWithAuth(apiUrl("/api/depseudonymize-document"), {
|
||||
method: "POST", body: form,
|
||||
});
|
||||
const result = await parseJsonResponse<{ file_base64: string }>(response);
|
||||
return Buffer.from(result.file_base64, "base64");
|
||||
}
|
||||
|
||||
export async function depseudonymize(
|
||||
text: string,
|
||||
mapping: PlaceholderMapping,
|
||||
|
||||
Reference in New Issue
Block a user