refactor(web): merge platform-api.ts into platform.ts
platform.ts and platform-api.ts both created PlatformClient instances. Merge all typed helpers (getUserSettings, updateUserSettings, listSessions, revokeSession, updateProfile) into platform.ts and delete the duplicate file. Use lazy singleton instead of eager.
This commit is contained in:
parent
bb6d77b1a4
commit
cce4ca610f
@ -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<UserSettings> {
|
||||
return getClient().get<UserSettings>("/settings");
|
||||
}
|
||||
|
||||
export async function updateUserSettings(settings: Partial<UserSettings>): Promise<UserSettings> {
|
||||
return getClient().put<UserSettings>("/settings", settings);
|
||||
}
|
||||
|
||||
export async function listSessions(): Promise<ActiveSession[]> {
|
||||
return getClient().get<ActiveSession[]>("/sessions");
|
||||
}
|
||||
|
||||
export async function revokeSession(sessionId: string): Promise<void> {
|
||||
await getClient().del(`/sessions/${sessionId}`);
|
||||
}
|
||||
|
||||
export async function updateProfile(updates: { displayName?: string }): Promise<void> {
|
||||
await getClient().put("/auth/profile", updates);
|
||||
}
|
||||
@ -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({
|
||||
let _client: PlatformClient | null = null;
|
||||
function getClient(): PlatformClient {
|
||||
if (!_client) {
|
||||
_client = createPlatformClient({
|
||||
baseUrl: PLATFORM_SERVICE_URL,
|
||||
productId: PRODUCT_ID,
|
||||
getAccessToken,
|
||||
refreshAccessToken: async () => false,
|
||||
});
|
||||
}
|
||||
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<UserSettings> {
|
||||
return getClient().get<UserSettings>("/settings");
|
||||
}
|
||||
|
||||
export async function updateUserSettings(settings: Partial<UserSettings>): Promise<UserSettings> {
|
||||
return getClient().put<UserSettings>("/settings", settings);
|
||||
}
|
||||
|
||||
export async function listSessions(): Promise<ActiveSession[]> {
|
||||
return getClient().get<ActiveSession[]>("/sessions");
|
||||
}
|
||||
|
||||
export async function revokeSession(sessionId: string): Promise<void> {
|
||||
await getClient().del(`/sessions/${sessionId}`);
|
||||
}
|
||||
|
||||
export async function updateProfile(updates: { displayName?: string }): Promise<void> {
|
||||
await getClient().put("/auth/profile", updates);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user