(
path: string,
schema: Schema.Schema<A, I, never>,
options: Omit<RequestOptions, "query"> = {},
)
| 147 | }; |
| 148 | |
| 149 | const publicRequest = async <A, I>( |
| 150 | path: string, |
| 151 | schema: Schema.Schema<A, I, never>, |
| 152 | options: Omit<RequestOptions, "query"> = {}, |
| 153 | ): Promise<A> => { |
| 154 | const url = new URL(path, origin); |
| 155 | const headers = new Headers(); |
| 156 | let body: BodyInit | undefined; |
| 157 | if (options.body !== undefined) { |
| 158 | headers.set("Content-Type", "application/json"); |
| 159 | body = JSON.stringify(options.body); |
| 160 | } |
| 161 | |
| 162 | const response = await fetch(url.toString(), { |
| 163 | method: options.method ?? "GET", |
| 164 | headers, |
| 165 | body, |
| 166 | }); |
| 167 | const payload = await parseJson(response); |
| 168 | if (!response.ok) { |
| 169 | throw new MobileApiError( |
| 170 | `Mobile API request failed with ${response.status}`, |
| 171 | response.status, |
| 172 | payload, |
| 173 | ); |
| 174 | } |
| 175 | return decode(schema, payload); |
| 176 | }; |
| 177 | |
| 178 | return { |
| 179 | getAuthConfig: () => |
no test coverage detected