learning_ai_notes/mobile/src/api/notes.ts

55 lines
1.4 KiB
TypeScript

import { createPlatformClient } from '@bytelyst/platform-client';
import { API_CONFIG } from './config';
import { getAuthClient } from './auth';
import { getApiClient } from './client';
export type MobileNote = {
id: string;
title: string;
body: string;
workspaceName: string;
};
const FALLBACK_NOTES: MobileNote[] = [
{
id: 'note-1',
title: 'Product launch checklist',
body: 'Finalize launch narrative and mobile scope cut line.',
workspaceName: 'Ops',
},
{
id: 'note-2',
title: 'Agent review policy draft',
body: 'Human approval required for destructive and external actions.',
workspaceName: 'Platform',
},
];
function getClient() {
const auth = getAuthClient();
return createPlatformClient({
baseUrl: API_CONFIG.productBaseUrl,
productId: API_CONFIG.productId,
getAccessToken: () => auth.getAccessToken(),
refreshAccessToken: () => auth.refreshAccessToken(),
timeoutMs: API_CONFIG.timeoutMs,
});
}
export async function listNotes(): Promise<MobileNote[]> {
try {
return await getApiClient().fetch<MobileNote[]>('/notes');
} catch {
return FALLBACK_NOTES;
}
}
export async function getNote(id: string): Promise<MobileNote | null> {
try {
return await getClient().get<MobileNote>(`/notes/${id}`);
} catch {
return FALLBACK_NOTES.find((note) => note.id === id) ?? null;
}
}