( auth: HttpAuth, headers: HttpHeaderEntry[], )
| 89 | } |
| 90 | |
| 91 | export function applyAuth( |
| 92 | auth: HttpAuth, |
| 93 | headers: HttpHeaderEntry[], |
| 94 | ): HttpHeaderEntry[] { |
| 95 | if (auth.type === 'bearer' && auth.token) { |
| 96 | return [ |
| 97 | ...headers, |
| 98 | { key: 'Authorization', value: `Bearer ${auth.token}` }, |
| 99 | ] |
| 100 | } |
| 101 | |
| 102 | if (auth.type === 'basic' && auth.username !== undefined) { |
| 103 | const credentials = Buffer.from( |
| 104 | `${auth.username}:${auth.password ?? ''}`, |
| 105 | ).toString('base64') |
| 106 | return [ |
| 107 | ...headers, |
| 108 | { key: 'Authorization', value: `Basic ${credentials}` }, |
| 109 | ] |
| 110 | } |
| 111 | |
| 112 | return headers |
| 113 | } |
| 114 | |
| 115 | function buildUrl(rawUrl: string, query: HttpQueryEntry[]): string { |
| 116 | const url = new URL(rawUrl) |
no outgoing calls
no test coverage detected