diff --git a/src/lib/api.ts b/src/lib/api.ts index 42fe10a1e..85d4ccf26 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -1,9 +1,15 @@ -async function send({ method, path, data = {}, headers, timeout = 30000 }) { +async function send({ + method, + path, + data = {}, + headers, + timeout = 30000 +}): Promise> { const controller = new AbortController(); const id = setTimeout(() => controller.abort(), timeout); const opts = { method, headers: {}, body: null, signal: controller.signal }; if (Object.keys(data).length > 0) { - let parsedData = data; + const parsedData = data; for (const [key, value] of Object.entries(data)) { if (value === '') { parsedData[key] = null; @@ -43,18 +49,33 @@ async function send({ method, path, data = {}, headers, timeout = 30000 }) { return responseData; } -export function get(path, headers = {}): Promise { +export function get( + path: string, + headers: Record +): Promise> { return send({ method: 'GET', path, headers }); } -export function del(path, data = {}, headers = {}): Promise { +export function del( + path: string, + data: Record, + headers: Record +): Promise> { return send({ method: 'DELETE', path, data, headers }); } -export function post(path, data, headers = {}): Promise { +export function post( + path: string, + data: Record, + headers: Record +): Promise> { return send({ method: 'POST', path, data, headers }); } -export function put(path, data, headers = {}): Promise { +export function put( + path: string, + data: Record, + headers: Record +): Promise> { return send({ method: 'PUT', path, data, headers }); }