From d64e191e5e3266aebfb18e4cb0d4e2be6be3e29b Mon Sep 17 00:00:00 2001 From: sevichecc <91365763+Sevichecc@users.noreply.github.com> Date: Fri, 14 Apr 2023 14:20:48 +0800 Subject: [PATCH] refactor: api types --- src/api.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/api.ts b/src/api.ts index 698ec9b..930830b 100644 --- a/src/api.ts +++ b/src/api.ts @@ -1,6 +1,6 @@ import fetch from "node-fetch"; import { OAuth, getPreferenceValues } from "@raycast/api"; -import { AppResponse, Preference, Status } from "./types"; +import { Credentials, Preference, Status ,StatusResponse} from "./types"; import { authorize } from "./oauth"; export const fetchToken = async (params: URLSearchParams, errorMessage: string): Promise => { @@ -19,7 +19,7 @@ export const fetchToken = async (params: URLSearchParams, errorMessage: string): return (await response.json()) as OAuth.TokenResponse; }; -export const createApp = async (): Promise => { +export const createApp = async (): Promise => { const { instance } = getPreferenceValues(); const response = await fetch(`https://${instance}/api/v1/apps`, { @@ -39,16 +39,16 @@ export const createApp = async (): Promise => { throw new Error("Failed to create Akkoma app"); } - return (await response.json()) as AppResponse; + return (await response.json()) as Credentials; }; -export const postNewStatus = async ({ +export const postNewStatus = async ({ status, visibility, spoiler_text, sensitive, scheduled_at, -}: Status): Promise => { +}: Partial) : Promise => { const { instance } = getPreferenceValues(); const token = await authorize(); @@ -66,10 +66,9 @@ export const postNewStatus = async ({ scheduled_at, }), }); - if (!response.ok) { throw new Error("Failed to pulish new status"); } - return (await response.json()) as T; + return (await response.json()) as StatusResponse; };