export type GetApiV2RatesConusLodgingYearArgs = {year: unknown}; export type GetApiV2RatesConusLodgingYearOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Lodging rates for the Continental US by year * * GET /v2/rates/conus/lodging/{year} */ export const getApiV2RatesConusLodgingYear = async (args: GetApiV2RatesConusLodgingYearArgs, options?: GetApiV2RatesConusLodgingYearOptions) => { const {baseUrl = "https://api.gsa.gov/travel/perdiem", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v2/rates/conus/lodging/${encodeURIComponent(String(args.year))}${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 };