export type GetApiHelloUserArgs = {Accept: 'application/vnd.hmrc.1.0+json' | 'application/vnd.hmrc.1.0+xml'}; export type GetApiHelloUserOptions = {baseUrl?: string | undefined, userRestricted?: string | undefined, fetch?: typeof fetch | undefined}; /** * Say hello user * * GET /hello/user */ export const getApiHelloUser = async (args: GetApiHelloUserArgs, options?: GetApiHelloUserOptions) => { const {baseUrl = "https://test-api.service.hmrc.gov.uk", fetch: fetchFn = fetch, userRestricted} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (userRestricted !== undefined) headers.set('authorization', `Bearer ${userRestricted}`) const url = `${baseUrl.replace(/\/+$/, '')}/hello/user${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 (await res.json()) as unknown };