import fs from "node:fs"; import { getApiKey } from "../zygonApi"; const API_ENDPOINT = process.env.API_ENDPOINT ?? "https://api.zygon.tech"; type Options = { name_column: string; labels_column?: string; delimiter: string; }; export const commandUploadApps = async (csvPath: string, options: Options) => { if (!fs.existsSync(csvPath)) throw new Error(`No file found at the provided path (${csvPath})`); try { const response = await fetch(`${API_ENDPOINT}/upload-apps`, { method: "POST", headers: { authorization: `Bearer ` + getApiKey(), "Content-Type": "application/json", credentials: "include", mode: "cors", }, body: JSON.stringify({ ...options, csv: fs.readFileSync(csvPath).toString(), }), }); const { creatingApps, creatingPrivateApps, existingApps } = (await response.json()) as { creatingApps: Array; creatingPrivateApps: Array; existingApps: Array; }; console.log(`Apps to declare (${creatingPrivateApps.length}):`); creatingPrivateApps.forEach((app: string) => console.log(` ${app}`)); console.log(`Apps to create (${creatingApps.length}):`); creatingApps.forEach((app: string) => console.log(` ${app}`)); console.log(`Existing apps (${existingApps.length}):`); existingApps.forEach((app: string) => console.log(` ${app}`)); } catch (e) { console.error( "We couldn't reach the Zygon server for the following reason:", (e as { message: string }).message, ); } };