export type GetApiShowsSearchArgs = {title?: string | undefined, summary?: string | undefined, order?: string | undefined, recent?: string | undefined, platforms?: string | undefined, country?: string | undefined, nbpp?: string | undefined, page?: string | undefined, locale?: string | undefined}; export type GetApiShowsSearchOptions = {baseUrl?: string | undefined, BetaSeriesApiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Search for a series, with member information if a token is provided * * GET /shows/search */ export const getApiShowsSearch = async (args: GetApiShowsSearchArgs, options?: GetApiShowsSearchOptions) => { const {baseUrl = "https://api.betaseries.com", fetch: fetchFn = fetch, BetaSeriesApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.title != null) query.append("title", String(args.title)) if (args.summary != null) query.append("summary", String(args.summary)) if (args.order != null) query.append("order", String(args.order)) if (args.recent != null) query.append("recent", String(args.recent)) if (args.platforms != null) query.append("platforms", String(args.platforms)) if (args.country != null) query.append("country", String(args.country)) if (args.nbpp != null) query.append("nbpp", String(args.nbpp)) if (args.page != null) query.append("page", String(args.page)) if (args.locale != null) query.append("locale", String(args.locale)) if (BetaSeriesApiKey !== undefined) headers.set("X-BetaSeries-Key", BetaSeriesApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/shows/search${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };