(method: string, path: string, body?: unknown)
| 57 | } |
| 58 | |
| 59 | const cf = async (method: string, path: string, body?: unknown): Promise<CfFetchResult> => { |
| 60 | const response = await fetch(`${CF_API}${path}`, { |
| 61 | method, |
| 62 | headers: { |
| 63 | authorization: `Bearer ${TOKEN}`, |
| 64 | "content-type": "application/json", |
| 65 | }, |
| 66 | body: body === undefined ? undefined : JSON.stringify(body), |
| 67 | }); |
| 68 | const json: any = await response.json().catch(() => ({ success: false, errors: [] })); |
| 69 | return { |
| 70 | ok: json.success === true, |
| 71 | errors: JSON.stringify(json.errors ?? []), |
| 72 | result: json.result, |
| 73 | }; |
| 74 | }; |
| 75 | |
| 76 | const cfOk = async (method: string, path: string, body?: unknown): Promise<any> => { |
| 77 | const response = await cf(method, path, body); |
no test coverage detected