export type GetApiCalendarArgs = {limit?: number | undefined, importance?: number | undefined, lang?: string | undefined, values?: string | undefined, f?: ('json' | 'csv' | 'html') | undefined}; export type GetApiCalendarOptions = {baseUrl: string, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * GET /calendar */ export const getApiCalendar = async (args: GetApiCalendarArgs, options: GetApiCalendarOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.limit != null) query.append("limit", String(args.limit)) if (args.importance != null) query.append("importance", String(args.importance)) if (args.lang != null) query.append("lang", String(args.lang)) if (args.values != null) query.append("values", String(args.values)) if (args.f != null) query.append("f", String(args.f)) if (OAuth2 !== undefined) query.set("c", OAuth2) const url = `${baseUrl.replace(/\/+$/, '')}/calendar${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 };