import fs from "node:fs"; import { getApiKey } from "../zygonApi"; const API_ENDPOINT = process.env.API_ENDPOINT ?? "https://api.zygon.tech"; type Options = { app_column: string; default_app_name?: string; status_column?: string; role_column?: string; app_labels_column?: string; fuzzy_apps: boolean; create_unknown_apps: boolean; email_column: string; delimiter: string; }; export const commandUploadIdentities = async ( csv_path: string, options: Options, ) => { if (!fs.existsSync(csv_path)) throw new Error("This file doesn't exist."); try { const r = await fetch(`${API_ENDPOINT}/upload-identities`, { method: "POST", headers: { authorization: `Bearer ` + getApiKey(), "Content-Type": "application/json", credentials: "include", mode: "cors", }, body: JSON.stringify({ ...options, csv: fs.readFileSync(csv_path).toString(), }), }); console.log(await r.text()); } catch (e) { console.error( `We couldn't reach the Zygon server for the following reason:`, (e as { message: string }).message, ); } };