import superagent from 'superagent' export const SENDBIRD_SHARED_HEADERS = { 'Api-Token': process.env.SENDBIRD_API_TOKEN, } export const SENDBIRD_BASE_URL = `https://api-${process.env.SENDBIRD_APP_ID}.sendbird.com/v3` async function doCall( httpcall: superagent.SuperAgentRequest, data: Record // in this case the data can really be any // eslint-disable-next-line @typescript-eslint/no-explicit-any ): Promise { try { const resp = await httpcall .set('Api-Token', process.env.SENDBIRD_API_TOKEN) .type('json') .send(data) return resp.body } catch (err) { if (err.response && err.response.body) throw new Error(`${err.response.status} ${err.response.body.message}`) throw new Error(err) } } export async function doPost(path: string, data: Record = {}) { const url = `${SENDBIRD_BASE_URL}${path}` return await doCall(superagent.post(url), data) } export async function doPatch(path: string, data: Record = {}) { const url = `${SENDBIRD_BASE_URL}${path}` return await doCall(superagent.patch(url), data) } export async function doPut(path: string, data: Record = {}) { const url = `${SENDBIRD_BASE_URL}${path}` return await doCall(superagent.put(url), data) } export async function doGet(path: string, data: Record = {}) { const url = `${SENDBIRD_BASE_URL}${path}` return await doCall(superagent.get(url), data) } export async function doDelete(path: string, data: Record = {}) { const url = `${SENDBIRD_BASE_URL}${path}` return await doCall(superagent.delete(url), data) }