( options?: ClientConfig, )
| 125 | } |
| 126 | |
| 127 | export const createClient = <T extends Router<any>>( |
| 128 | options?: ClientConfig, |
| 129 | ): UnionToIntersection<Client<T>> => { |
| 130 | const { |
| 131 | baseUrl = "", |
| 132 | credentials = "include", |
| 133 | ...opts |
| 134 | } = options ?? ({} as ClientConfig) |
| 135 | |
| 136 | const jfetch = async (input: RequestInfo | URL, init?: RequestInit) => { |
| 137 | // remove baseUrl from input if already included, for example during SSR |
| 138 | const inputPath = input.toString().replace(baseUrl, "") |
| 139 | const targetUrl = baseUrl + inputPath |
| 140 | |
| 141 | const res = await fetch(targetUrl, { |
| 142 | ...init, |
| 143 | credentials, |
| 144 | cache: "no-store", |
| 145 | }) |
| 146 | |
| 147 | if (!res.ok) { |
| 148 | const message = await res.text() |
| 149 | throw new HTTPException(res.status as ContentfulStatusCode, { |
| 150 | message, |
| 151 | res, |
| 152 | }) |
| 153 | } |
| 154 | |
| 155 | res.json = () => parseJsonResponse(res) |
| 156 | return res |
| 157 | } |
| 158 | |
| 159 | const baseClient = hc(baseUrl, { |
| 160 | ...opts, |
| 161 | fetch: opts.fetch || jfetch, |
| 162 | }) as unknown as UnionToIntersection<Client<T>> |
| 163 | |
| 164 | return createProxy(baseClient, baseUrl) as typeof baseClient |
| 165 | } |
| 166 | |
| 167 | // export type ExtractAppRouter<T> = T extends { |
| 168 | // _def: { routerConfig: Record<string, any> } |
no test coverage detected