UNPKG

@lableb/javascript-sdk

Version:

Lableb cloud search client for javascript

35 lines (25 loc) 881 B
import axios from "axios"; import { customIdentity, customPickBy } from "../utils"; import { lablebHttpClientSchema } from "./client.schema"; import { LablebHttpClientParams } from "./client.type"; function mapValues(obj: any, fn: any) { if (typeof obj == 'object') return Object.keys(obj).reduce((result, key) => ({ ...result, [key]: fn(obj[key]), }), {}); else return undefined; } export async function LablebHttpClient(options: LablebHttpClientParams) { const result = await lablebHttpClientSchema.validate(options); return axios( customPickBy({ method: result?.method, url: result?.url, headers: result?.headers, data: result?.body, params: result?.params, }, customIdentity)) .then((response: any) => response.data); }