UNPKG

softchatjs-core

Version:
2 lines 1.94 kB
import r from"axios";var o="https://api.softchatjs.com";var t=async e=>{try{let n=(await r({url:e.endpoint,method:e.method,headers:{"Cache-Control":"no-cache",accessToken:e.token||"","Content-Type":"application/json",...e.headers},data:e.method==="POST"?e.body:void 0,responseType:"json",timeout:3e4})).data;return typeof n=="object"&&n&&"success"in n?n:{...n,success:!1}}catch(s){throw console.log(s,"fetch error"),r.isAxiosError(s)&&s.response?new Error(`HTTP error! Status: ${s.response.status}`):new Error("An unknown error occurred.")}};async function a({userId:e,subId:s,projectId:n}){return await t({endpoint:`${o}/auth/session`,body:{userId:e,projectId:n,subId:s},method:"POST"})}async function R(e){return await t({endpoint:`${o}/conversations`,body:{},method:"GET",token:e})}async function d(e,s){return await t({endpoint:`${o}/conversation/${s}`,body:{},method:"GET",token:e})}async function T(e){return await t({endpoint:`${o}/broadcastlists`,body:{},method:"GET",token:e})}async function A(e,s,n){return await t({endpoint:`${o}/messages/${s}${n?"?page="+n:""}`,body:{},method:"GET",token:e})}async function S(e,s,n){return await t({endpoint:`${o}/broadcastlist/messages/${s}${n?"?page="+n:""}`,body:{},method:"GET",token:e})}async function E(e){return await t({endpoint:`${o}/gifs/trending`,body:{},method:"GET",token:e})}async function c(e,s){return await t({endpoint:`${o}/upload`,body:s,method:"POST",token:e})}async function u(e,s){return await t({endpoint:`${o}/presigned-url`,body:s,method:"POST",token:e})}async function P(e,s){return await t({endpoint:`${o}/upload-attachment`,body:s,method:"POST",token:e,headers:{"Content-Type":"multipart/form-data"}})}export{a as CREATE_SESSION,T as GET_BROADCASTLISTS,S as GET_BROADCAST_LIST_MESSAGES,d as GET_CONVERSATION,R as GET_CONVERSATIONS,E as GET_EMOJIS,A as GET_MESSAGES,u as GET_PRESIGNED_URL,P as UPLOAD_ATTACHMENT,c as UPLOAD_MEDIA}; //# sourceMappingURL=fetch.mjs.map