export type CreateApiApiHolidaysImportArgs = {year: number, countryCode: string}; export type CreateApiApiHolidaysImportOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Imports a specific year's holidays for the specified country code from nager.at * * POST /api/holidays/import * * Also accepts auth: ApiKey */ export const createApiApiHolidaysImport = async (args: CreateApiApiHolidaysImportArgs, options?: CreateApiApiHolidaysImportOptions) => { const {baseUrl = "https://api.intect.app", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.year != null) query.append("year", String(args.year)) if (args.countryCode != null) query.append("countryCode", String(args.countryCode)) if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/holidays/import${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };