UNPKG

@ixo/supamoto-bot-sdk

Version:

An SDK to easily interact with Supamoto bot db

85 lines 1.89 kB
import fetch from 'node-fetch'; import { cleanUrlString } from '../../utils/url'; import { throwResponseError } from '../../utils/error'; export async function searchCustomers({ queue, search, country, queued, limit, offset }, botUrl, accessToken) { const url = `${botUrl}/action`; const payload = { action: 'search-customers', flags: { queue, search, country, queued, limit, offset } }; const response = await fetch(cleanUrlString(url), { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, body: JSON.stringify(payload) }); if (!response.ok) { throw throwResponseError(response); } const data = await response.json(); return data; } export async function getCustomer({ customerId }, botUrl, accessToken) { const url = `${botUrl}/action`; const payload = { action: 'get-customer', flags: { customerId } }; const response = await fetch(cleanUrlString(url), { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, body: JSON.stringify(payload) }); if (!response.ok) { throw throwResponseError(response); } const data = await response.json(); return data; } export async function getCustomers({ customerIds }, botUrl, accessToken) { const url = `${botUrl}/action`; const payload = { action: 'get-customers', flags: { customerIds } }; const response = await fetch(cleanUrlString(url), { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}` }, body: JSON.stringify(payload) }); if (!response.ok) { throw throwResponseError(response); } const data = await response.json(); return data; }