import { LogLevel, Method } from "./models"; export default class Utils { host: string; constructor(host: string) { this.host = host; } async request(method: Method, path: string, data?: unknown | null): Promise { const req: Response = await fetch(`${this.host}${path}`, { method: Method[method], mode: "cors", credentials: "same-origin", headers: { "Content-Type": "application/json" }, redirect: "follow", referrerPolicy: "no-referrer", body: data ? JSON.stringify(data) : null, }); return req.json(); } static log(message: string, level = LogLevel.INFO) { switch (level) { case 0: console.log(`%cⓘ SDK INFO: ${message}`, "background: #183fdb; color: #ffffff"); break; case 1: console.log(`%c❗SDK WARNING: ${message}`, "background: #c46a10; color: #ffffff"); break; case 2: console.log(`%c⛔SDK ERROR: ${message}`, "background: #c41010; color: #ffffff"); break; default: console.log("default"); } } }