UNPKG

refraction-cli

Version:
31 lines (25 loc) 792 B
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ import axios from 'axios'; import { getConfig } from './config'; import type { AxiosResponse, AxiosRequestConfig } from 'axios'; const base = 'https://app.refraction.dev'; const request = async <T>( path: string, body?: Record<string, unknown>, props?: AxiosRequestConfig ): Promise<AxiosResponse<T>> => { const endpoint = new URL(path, base).href; const userId = getConfig('userId'); const teamId = getConfig('teamId'); const response = await axios.post<T>(endpoint, body, { headers: { 'Content-Type': 'application/json', 'X-Refraction-User': userId, 'X-Refraction-Team': teamId, 'X-Refraction-Source': 'cli', }, ...props, }); return response; }; export default request;