All files / src/services/elevenLabsInternalAPI/workspace index.ts

75% Statements 6/8
100% Branches 0/0
100% Functions 1/1
75% Lines 6/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                  1x       1x 1x                           1x 1x         1x    
import { fetch as undiciFetch, Response } from "undici";
import { ELEVEN_LABS_INTERNAL_API_BASE_URL } from "../constants";
import { RequestType } from "./request";
import { NoThrow } from "@/utils/NoThrow";
import { proxyAgentPool } from "@/lib/proxyAgentPool";
import { requestHeaders } from "@/requestHeaders";
import { ResponseSchema } from "./response";
 
export async function workspace(req: RequestType) {
    const url = `${ELEVEN_LABS_INTERNAL_API_BASE_URL}/workspace`;
 
    let response: Response;
 
    try {
        response = await undiciFetch(url, {
            headers: {
                ...requestHeaders,
                "Cache-Control": "no-cache",
                Authorization: `Bearer ${req.bearerToken}`,
            },
            dispatcher: proxyAgentPool.get(req.proxyURL),
        });
    } catch (error) {
        return NoThrow.error(error);
    }
 
    let rawData: unknown;
 
    try {
        rawData = await response.json();
    } catch (error) {
        return NoThrow.error(error);
    }
 
    return NoThrow.fromZodResult(await ResponseSchema.safeParseAsync(rawData));
}