feat(dashboard): close legacy parity gaps
This commit is contained in:
1 parent
92287c0a9a
commit
4b3f00729f
21 files changed
+397
-28
No files matched your search
@@ -2,6 +2,8 @@ import { z } from 'zod';
|
||||
import {
|
||||
ActivityResponseSchema,
|
||||
ChatSyncStatusSchema,
|
||||
ChatSyncTriggerResponseSchema,
|
||||
FetchAllChatsResponseSchema,
|
||||
} from '../../../../../packages/api-contracts/src/index.js';
|
||||
|
||||
export const RawLogEntrySchema = z.strictObject({
|
||||
@@ -32,8 +34,8 @@ async function parseResponse<T>(
|
||||
}
|
||||
|
||||
export function createOperationsApi(fetchImplementation?: typeof fetch) {
|
||||
function request(path: string): Promise<Response> {
|
||||
return (fetchImplementation ?? globalThis.fetch)(path);
|
||||
function request(path: string, init?: RequestInit): Promise<Response> {
|
||||
return (fetchImplementation ?? globalThis.fetch)(path, init);
|
||||
}
|
||||
return {
|
||||
async getActivity() {
|
||||
@@ -48,6 +50,18 @@ export function createOperationsApi(fetchImplementation?: typeof fetch) {
|
||||
async getSyncStatus() {
|
||||
return parseResponse(await request('/api/chats/sync'), ChatSyncStatusSchema);
|
||||
},
|
||||
async triggerSync(kind: 'delta' | 'full') {
|
||||
const result = await parseResponse(
|
||||
await request(`/api/chats/sync/${kind}`, { method: 'POST' }),
|
||||
ChatSyncTriggerResponseSchema,
|
||||
);
|
||||
if (!('success' in result)) throw new Error(result.error);
|
||||
if (!result.success) throw new Error(result.reason);
|
||||
return result;
|
||||
},
|
||||
async fetchAllChats() {
|
||||
return parseResponse(await request('/api/chats/fetch-all', { method: 'POST' }), FetchAllChatsResponseSchema);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user