feat(frontend): add client routes

This commit is contained in:
Nicholas Tindle
2025-02-14 01:08:38 -06:00
parent 182b858963
commit 6272e3f652
3 changed files with 41 additions and 1 deletions

View File

@@ -117,7 +117,7 @@ async def get_or_create_user_route(user_data: dict = Depends(auth_middleware)):
"/auth/user/email", tags=["auth"], dependencies=[Depends(auth_middleware)]
)
async def update_user_email_route(
user_id: Annotated[str, Depends(get_user_id)], email: str
user_id: Annotated[str, Depends(get_user_id)], email: str = Body(...)
) -> dict[str, str]:
await update_user_email(user_id, email)

View File

@@ -32,7 +32,9 @@ import {
StoreReview,
TransactionHistory,
User,
NotificationPreferenceDTO,
UserPasswordCredentials,
NotificationPreference,
} from "./types";
import { createBrowserClient } from "@supabase/ssr";
import getServerSupabase from "../supabase/getServerSupabase";
@@ -81,6 +83,10 @@ export default class BackendAPI {
return this._request("POST", "/auth/user", {});
}
updateUserEmail(email: string): Promise<{ email: string }> {
return this._request("POST", "/auth/user/email", { email });
}
getUserCredit(page?: string): Promise<{ credits: number }> {
try {
return this._get(`/credits`, undefined, page);
@@ -89,6 +95,16 @@ export default class BackendAPI {
}
}
getUserPreferences(): Promise<NotificationPreference> {
return this._get("/auth/user/preferences");
}
updateUserPreferences(
preferences: NotificationPreferenceDTO,
): Promise<NotificationPreference> {
return this._request("POST", "/auth/user/preferences", preferences);
}
getAutoTopUpConfig(): Promise<{ amount: number; threshold: number }> {
return this._get("/credits/auto-top-up");
}

View File

@@ -346,6 +346,30 @@ export type UserPasswordCredentials = BaseCredentials & {
password: string;
};
// Mirror of backend/backend/data/notifications.py:NotificationType
export type NotificationType =
| "agent_run"
| "zero_balance"
| "low_balance"
| "block_execution_failed"
| "continuous_agent_error"
| "daily_summary"
| "weekly_summary"
| "monthly_summary";
// Mirror of backend/backend/data/notifications.py:NotificationPreference
export type NotificationPreferenceDTO = {
email: string;
preferences: { [key in NotificationType]: boolean };
daily_limit: number;
};
export type NotificationPreference = NotificationPreferenceDTO & {
user_id: string;
emails_sent_today: number;
last_reset_date: Date;
};
/* Mirror of backend/data/integrations.py:Webhook */
export type Webhook = {
id: string;