Build private multi-hotel web foundation with MongoDB, Gmail import and Linux deployment

This commit is contained in:
wolf-demon
2026-09-09 14:16:34 +01:00
parent dec97954c9
commit 49d02be623
37 changed files with 2598 additions and 2 deletions
+18
View File
@@ -0,0 +1,18 @@
export type User = { id: string; name: string; role: string; hotelId: string };
export type Session = { preview: boolean; csrfToken: string; user: User | null };
export type Hotel = { id: string; name: string; timezone: string; signature: string; replyMode: string; version: number };
export type Conversation = { id: string; from: string; subject: string; body: string; receivedAt: string; status: string; draft: string; category: string; note: string; providerThreadId: string; version: number };
export type Knowledge = { id: string; title: string; category: string; answer: string; keywords: string; approved: boolean; version: number };
export type Activity = { id: string; at: string; userName: string; action: string };
export type Mailboxes = { configured: boolean; items: { id: string; email: string; status: string; lastSyncAt: string | null; syncError: string }[] };
let csrf = '';
export async function api<T>(path: string, method = 'GET', body?: unknown): Promise<T> {
const response = await fetch('/api' + path, { method, credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf }, body: body === undefined ? undefined : JSON.stringify(body) });
const data = await response.json().catch(() => null);
if (!response.ok) {
if (response.status === 401 && path !== '/auth/login') window.dispatchEvent(new Event('session-expired'));
throw new Error(data?.error || (response.status === 429 ? 'Too many attempts. Please wait a minute.' : response.status === 403 ? 'Only the hotel owner can change this.' : 'We couldn’t complete that request. Please try again.'));
}
return data as T;
}
export async function session() { const value = await api<Session>('/session'); csrf = value.csrfToken; return value; }