diff --git a/web/src/lib/platform-api.ts b/web/src/lib/platform-api.ts deleted file mode 100644 index e0c4f75..0000000 --- a/web/src/lib/platform-api.ts +++ /dev/null @@ -1,51 +0,0 @@ -"use client"; - -import { createPlatformClient, type PlatformClient } from "@bytelyst/platform-client"; -import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config"; -import { getAccessToken } from "@/lib/api-helpers"; - -let _client: PlatformClient | null = null; -function getClient(): PlatformClient { - if (!_client) { - _client = createPlatformClient({ - baseUrl: PLATFORM_SERVICE_URL, - productId: PRODUCT_ID, - getAccessToken, - }); - } - return _client; -} - -export interface UserSettings { - theme?: "dark" | "light" | "system"; - language?: string; - notificationsEnabled?: boolean; - [key: string]: unknown; -} - -export interface ActiveSession { - id: string; - deviceName: string; - lastActiveAt: string; - isCurrent: boolean; -} - -export async function getUserSettings(): Promise { - return getClient().get("/settings"); -} - -export async function updateUserSettings(settings: Partial): Promise { - return getClient().put("/settings", settings); -} - -export async function listSessions(): Promise { - return getClient().get("/sessions"); -} - -export async function revokeSession(sessionId: string): Promise { - await getClient().del(`/sessions/${sessionId}`); -} - -export async function updateProfile(updates: { displayName?: string }): Promise { - await getClient().put("/auth/profile", updates); -} diff --git a/web/src/lib/platform.ts b/web/src/lib/platform.ts index 5fc7d50..c00ccd8 100644 --- a/web/src/lib/platform.ts +++ b/web/src/lib/platform.ts @@ -1,12 +1,55 @@ "use client"; -import { createPlatformClient } from "@bytelyst/platform-client"; +import { createPlatformClient, type PlatformClient } from "@bytelyst/platform-client"; import { PLATFORM_SERVICE_URL, PRODUCT_ID } from "@/lib/product-config"; import { getAccessToken } from "@/lib/api-helpers"; -export const platformClient = createPlatformClient({ - baseUrl: PLATFORM_SERVICE_URL, - productId: PRODUCT_ID, - getAccessToken, - refreshAccessToken: async () => false, -}); +let _client: PlatformClient | null = null; +function getClient(): PlatformClient { + if (!_client) { + _client = createPlatformClient({ + baseUrl: PLATFORM_SERVICE_URL, + productId: PRODUCT_ID, + getAccessToken, + }); + } + return _client; +} + +export { getClient as platformClient }; + +// ── Typed API helpers ──────────────────────────────────────── + +export interface UserSettings { + theme?: "dark" | "light" | "system"; + language?: string; + notificationsEnabled?: boolean; + [key: string]: unknown; +} + +export interface ActiveSession { + id: string; + deviceName: string; + lastActiveAt: string; + isCurrent: boolean; +} + +export async function getUserSettings(): Promise { + return getClient().get("/settings"); +} + +export async function updateUserSettings(settings: Partial): Promise { + return getClient().put("/settings", settings); +} + +export async function listSessions(): Promise { + return getClient().get("/sessions"); +} + +export async function revokeSession(sessionId: string): Promise { + await getClient().del(`/sessions/${sessionId}`); +} + +export async function updateProfile(updates: { displayName?: string }): Promise { + await getClient().put("/auth/profile", updates); +}