import { type TwitterUser, type TweetList, type TwitterList, type TwitterNotification, } from "../fetching/types"; const headers = { "Content-Type": "application/json" }; async function postJson( url: string, body: Record, ): Promise { const res = await fetch(url, { method: "POST", headers, body: JSON.stringify(body), }); if (!res.ok) { const text = await res.text(); throw new Error(text || `Request failed (${res.status})`); } return (await res.json()) as T; } export const twitterClient = { own(payload: Record) { // return postJson(`/api/twitter/our`, payload); }, timeline(mode: string, payload: Record) { console.log("fetching tweets", mode); return postJson(`/api/twitter/timeline/${mode}`, payload); }, lists(payload: Record) { return postJson("/api/twitter/lists", payload); }, notifications(payload: Record) { return postJson( "/api/twitter/notifications", payload, ); }, removeBookmark(payload: Record) { return postJson<{ status: string }>( "/api/twitter/bookmarks/remove", payload, ); }, like(tweetId: string, payload: Record) { return postJson<{ status: string }>( `/api/twitter/tweets/${tweetId}/like`, payload, ); }, retweet(tweetId: string, payload: Record) { return postJson<{ status: string }>( `/api/twitter/tweets/${tweetId}/retweet`, payload, ); }, bookmark(tweetId: string, payload: Record) { return postJson<{ status: string }>( `/api/twitter/tweets/${tweetId}/bookmark`, payload, ); }, reply(tweetId: string, payload: Record) { return postJson<{ status: string }>( `/api/twitter/tweets/${tweetId}/reply`, payload, ); }, };