Download packages/kap-server/test/helpers/auth.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 780 Bytes
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/kap-server/test/helpers/auth.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/kap-server/test/helpers/auth.ts
-
curl -L -o auth.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/kap-server/test/helpers/auth.ts
780 Bytes
| import type { RunningServer } from '../../src/start'; | |
| type HeaderMap = Record<string, string>; | |
| interface FetchOptions { | |
| readonly method?: string; | |
| readonly headers?: HeaderMap; | |
| readonly body?: string; | |
| readonly signal?: AbortSignal; | |
| } | |
| export function bearerToken(server: RunningServer): string { | |
| return server.authTokenService.getToken(); | |
| } | |
| export function authHeaders(server: RunningServer, extra: HeaderMap = {}): HeaderMap { | |
| return { | |
| ...extra, | |
| authorization: `Bearer ${bearerToken(server)}`, | |
| }; | |
| } | |
| export async function authedFetch( | |
| server: RunningServer, | |
| base: string, | |
| path: string, | |
| init: FetchOptions = {}, | |
| ): Promise<Response> { | |
| return fetch(`${base}${path}`, { | |
| ...init, | |
| headers: authHeaders(server, init.headers), | |
| } as never); | |
| } | |