(req: ZoomInfoProxyRequest, accessToken: string)
| 43 | } |
| 44 | |
| 45 | async function callZoomInfo(req: ZoomInfoProxyRequest, accessToken: string): Promise<Invocation> { |
| 46 | const url = assertSafeZoomInfoUrl(buildApiUrl(req), 'apiUrl').toString() |
| 47 | const hasBody = req.body !== undefined && req.body !== null |
| 48 | const headers: Record<string, string> = { |
| 49 | Authorization: `Bearer ${accessToken}`, |
| 50 | Accept: 'application/json', |
| 51 | } |
| 52 | if (hasBody) headers['Content-Type'] = 'application/json' |
| 53 | |
| 54 | const response = await secureFetchWithValidation( |
| 55 | url, |
| 56 | { |
| 57 | method: req.method, |
| 58 | headers, |
| 59 | body: hasBody |
| 60 | ? typeof req.body === 'string' |
| 61 | ? req.body |
| 62 | : JSON.stringify(req.body) |
| 63 | : undefined, |
| 64 | timeout: ZOOMINFO_OUTBOUND_FETCH_TIMEOUT_MS, |
| 65 | }, |
| 66 | 'apiUrl' |
| 67 | ) |
| 68 | |
| 69 | const raw = await response.text() |
| 70 | let parsed: unknown = null |
| 71 | if (raw.length > 0) { |
| 72 | try { |
| 73 | parsed = JSON.parse(raw) |
| 74 | } catch { |
| 75 | parsed = raw |
| 76 | } |
| 77 | } |
| 78 | return { status: response.status, body: parsed } |
| 79 | } |
| 80 | |
| 81 | export const POST = withRouteHandler(async (request: NextRequest) => { |
| 82 | const requestId = generateRequestId() |
no test coverage detected