export type GetApiV2RatesZipZipYearYearArgs = {zip: number, year: unknown}; export type GetApiV2RatesZipZipYearYearOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get per diem rates by ZIP code and year * * GET /v2/rates/zip/{zip}/year/{year} */ export const getApiV2RatesZipZipYearYear = async (args: GetApiV2RatesZipZipYearYearArgs, options?: GetApiV2RatesZipZipYearYearOptions) => { 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/zip/${encodeURIComponent(String(args.zip))}/year/${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 };