softchatjs-core
Version:
Javascript client for JS based frameworks
2 lines • 2.76 kB
JavaScript
;var d=Object.create;var i=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var c=(e,s)=>{for(var n in s)i(e,n,{get:s[n],enumerable:!0})},R=(e,s,n,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let r of A(s))!E.call(e,r)&&r!==n&&i(e,r,{get:()=>s[r],enumerable:!(a=T(s,r))||a.enumerable});return e};var u=(e,s,n)=>(n=e!=null?d(S(e)):{},R(s||!e||!e.__esModule?i(n,"default",{value:e,enumerable:!0}):n,e)),P=e=>R(i({},"__esModule",{value:!0}),e);var G={};c(G,{CREATE_SESSION:()=>m,GET_BROADCASTLISTS:()=>y,GET_BROADCAST_LIST_MESSAGES:()=>g,GET_CONVERSATION:()=>O,GET_CONVERSATIONS:()=>I,GET_EMOJIS:()=>h,GET_MESSAGES:()=>f,GET_PRESIGNED_URL:()=>C,UPLOAD_ATTACHMENT:()=>_,UPLOAD_MEDIA:()=>$});module.exports=P(G);var p=u(require("axios")),o="https://api.softchatjs.com";var t=async e=>{try{let n=(await(0,p.default)({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"),p.default.isAxiosError(s)&&s.response?new Error(`HTTP error! Status: ${s.response.status}`):new Error("An unknown error occurred.")}};async function m({userId:e,subId:s,projectId:n}){return await t({endpoint:`${o}/auth/session`,body:{userId:e,projectId:n,subId:s},method:"POST"})}async function I(e){return await t({endpoint:`${o}/conversations`,body:{},method:"GET",token:e})}async function O(e,s){return await t({endpoint:`${o}/conversation/${s}`,body:{},method:"GET",token:e})}async function y(e){return await t({endpoint:`${o}/broadcastlists`,body:{},method:"GET",token:e})}async function f(e,s,n){return await t({endpoint:`${o}/messages/${s}${n?"?page="+n:""}`,body:{},method:"GET",token:e})}async function g(e,s,n){return await t({endpoint:`${o}/broadcastlist/messages/${s}${n?"?page="+n:""}`,body:{},method:"GET",token:e})}async function h(e){return await t({endpoint:`${o}/gifs/trending`,body:{},method:"GET",token:e})}async function $(e,s){return await t({endpoint:`${o}/upload`,body:s,method:"POST",token:e})}async function C(e,s){return await t({endpoint:`${o}/presigned-url`,body:s,method:"POST",token:e})}async function _(e,s){return await t({endpoint:`${o}/upload-attachment`,body:s,method:"POST",token:e,headers:{"Content-Type":"multipart/form-data"}})}0&&(module.exports={CREATE_SESSION,GET_BROADCASTLISTS,GET_BROADCAST_LIST_MESSAGES,GET_CONVERSATION,GET_CONVERSATIONS,GET_EMOJIS,GET_MESSAGES,GET_PRESIGNED_URL,UPLOAD_ATTACHMENT,UPLOAD_MEDIA});
//# sourceMappingURL=fetch.js.map