import type { KyInstance } from "ky"; import type { MessageQueryOptions } from "./types.js"; export async function fetchMessagePage( client: KyInstance, corpId: string, options: MessageQueryOptions = {} ): Promise<{ count: number; items: Record[] }> { const start = options.start ?? 0; const count = options.count ?? 20; const read = options.read ?? false; const response = await client.get("api/message/v1/messages", { searchParams: { read: String(read), start: String(start), count: String(count), corpId, }, }); const json = (await response.json()) as { count?: number; items?: Record[] }; return { count: json.count ?? json.items?.length ?? 0, items: json.items ?? [] }; } export async function markMessageRead(client: KyInstance, corpId: string, messageId: string): Promise { // The downstream route accepts the compound ID with its colon separators intact. await client.put(`api/message/v1/messages/$${messageId}`, { searchParams: { corpId }, json: { id: messageId }, }); }