first commit

This commit is contained in:
debu-2 2026-10-03 21:14:44 +05:30
commit cce9a8c9ba
73 changed files with 8665 additions and 0 deletions

106
frontend/src/api.js Normal file
View file

@ -0,0 +1,106 @@
const API_BASE = "/api/v1";
function basicAuthHeader({ username, password }) {
return `Basic ${btoa(`${username}:${password}`)}`;
}
async function request(path, { method = "GET", payload, token, basicAuth } = {}) {
const response = await fetch(`${API_BASE}${path}`, {
method,
headers: {
...(payload ? { "Content-Type": "application/json" } : {}),
...(token ? { Authorization: `Bearer ${token}` } : {}),
...(basicAuth
? { Authorization: basicAuthHeader(basicAuth) }
: {}),
},
...(payload ? { body: JSON.stringify(payload) } : {}),
});
const data = await response.json().catch(() => ({}));
if (!response.ok) {
const message = Array.isArray(data.detail)
? data.detail[0]?.msg
: data.detail;
throw new Error(message || "Something went wrong. Please try again.");
}
return data;
}
export const login = (payload) =>
request("/auth/login", { method: "POST", payload });
export const register = (payload) =>
request("/auth/register", { method: "POST", payload });
export const getCurrentAccount = (token) =>
request("/auth/me", { token });
export const getMyCompanyDomain = (token) =>
request("/domains/me", { token });
export const verifyCompanyDns = (token) =>
request("/domains/me/verify-dns", { method: "POST", token });
export const sendEmail = (payload, token) =>
request("/emails", { method: "POST", payload, token });
function emailQuery(parameters = {}) {
const query = new URLSearchParams();
Object.entries(parameters).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== "") {
query.set(key, String(value));
}
});
const encoded = query.toString();
return encoded ? `?${encoded}` : "";
}
export const listEmails = (parameters, token) =>
request(`/emails${emailQuery(parameters)}`, { token });
export const getEmail = (emailId, token) =>
request(`/emails/${encodeURIComponent(emailId)}`, { token });
export const setEmailRead = (emailId, isRead, token) =>
request(`/emails/${encodeURIComponent(emailId)}/read`, {
method: "PATCH",
payload: { is_read: isRead },
token,
});
export const setEmailStar = (emailId, isStarred, token) =>
request(`/emails/${encodeURIComponent(emailId)}/star`, {
method: "PATCH",
payload: { is_starred: isStarred },
token,
});
export const trashEmail = (emailId, token) =>
request(`/emails/${encodeURIComponent(emailId)}`, {
method: "DELETE",
token,
});
export const restoreEmail = (emailId, token) =>
request(`/emails/${encodeURIComponent(emailId)}/restore`, {
method: "POST",
token,
});
export const permanentlyDeleteEmail = (emailId, token) =>
request(`/emails/${encodeURIComponent(emailId)}/permanent`, {
method: "DELETE",
token,
});
export const listStickyNotes = (token) =>
request("/sticky-notes", { token });
export const createStickyNote = (payload, token) =>
request("/sticky-notes", { method: "POST", payload, token });
export const updateStickyNote = (noteId, payload, token) =>
request(`/sticky-notes/${encodeURIComponent(noteId)}`, {
method: "PATCH",
payload,
token,
});
export const deleteStickyNote = (noteId, token) =>
request(`/sticky-notes/${encodeURIComponent(noteId)}`, {
method: "DELETE",
token,
});
export const previewDnsSetup = (payload, basicAuth) =>
request("/dns-setup/preview", {
method: "POST",
payload,
basicAuth,
});