diff --git a/src/components/playing/spotify/types.ts b/src/components/playing/spotify/types.ts index f11c3f5..3012c22 100644 --- a/src/components/playing/spotify/types.ts +++ b/src/components/playing/spotify/types.ts @@ -37,57 +37,65 @@ export function isAuthToken(obj: unknown): obj is AuthToken { return isRefreshToken(obj) && "refresh_token" in obj; } +type externalUrls = { + spotify: string; +}; + +const isExternalUrl = (obj: unknown): obj is externalUrls => + isObj(obj) && "spotify" in obj && typeof obj.spotify === "string"; + export type nowPlaying = null | { type: "track"; - id: string; name: string; + + external_urls: externalUrls; + album: { + external_urls: externalUrls; + name: string; images: { url: string; - height: number; - width: number; }[]; }; artists: { + external_urls: externalUrls; name: string; - id: string; }[]; }; export function isNowPlaying(obj: unknown): obj is nowPlaying { return ( - isObj(obj) && - "type" in obj && - obj.type === "track" && - "id" in obj && - typeof obj.id === "string" && - "name" in obj && - typeof obj.name === "string" && - "album" in obj && - isObj(obj.album) && - "images" in obj.album && - Array.isArray(obj.album.images) && - obj.album.images.reduce( - (acc, curr) => - acc && - "url" in curr && - typeof curr.url === "string" && - "height" in curr && - typeof curr.height === "number" && - "width" in curr && - typeof curr.width === "number", - true, - ) && - "artists" in obj && - Array.isArray(obj.artists) && - obj.artists.reduce( - (acc, curr) => - acc && - "name" in curr && - typeof curr.name === "string" && - "id" in curr && - typeof curr.id === "string", - true, - ) + obj === null || + (isObj(obj) && + "type" in obj && + obj.type === "track" && + "name" in obj && + typeof obj.name === "string" && + "external_urls" in obj && + isExternalUrl(obj.external_urls) && + "album" in obj && + isObj(obj.album) && + "external_urls" in obj.album && + isExternalUrl(obj.album.external_urls) && + "name" in obj.album && + typeof obj.album.name === "string" && + "images" in obj.album && + Array.isArray(obj.album.images) && + obj.album.images.reduce( + (acc, curr) => + acc && isObj(curr) && "url" in curr && typeof curr.url === "string", + true, + ) && + "artists" in obj && + Array.isArray(obj.artists) && + obj.artists.reduce( + (acc, curr) => + acc && + "external_urls" in curr && + isExternalUrl(curr.external_urls) && + "name" in curr && + typeof curr.name === "string", + true, + )) ); }