UNPKG

amelia-sendbird-desk-agent

Version:
1 lines 4.77 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});class AmeliaSendbird{constructor(){this.GATE_API="https://gate.sendbird.com",this.last_login_at=null,this.account_locked=!1,this.use_lock_30mins=!0,this.use_lock_90days_no_login=!1,this.use_lock_5times_wrong_pw=!1,this.use_pw_policy=!1,this.use_change_pw_every_90days=!1,this.token=null,this.organizations=[],this.userInfo=null,this.applications=[],this.users=[]}loginToDashboard(t,s,e){const n=this.GATE_API+"/dashboard/auth/authenticate/",i={email:t,password:s};fetch(n,{method:"POST",headers:{"content-type":"application/json;charset=UTF-8"},body:JSON.stringify(i)}).then(t=>t.json()).then(t=>{t?(this.last_login_at=t.last_login_at,this.account_locked=t.account_locked,this.use_lock_30mins=t.use_lock_30mins,this.use_lock_90days_no_login=t.use_lock_90days_no_login,this.use_lock_5times_wrong_pw=t.use_lock_5times_wrong_pw,this.use_pw_policy=t.use_pw_policy,this.use_change_pw_every_90days=t.use_change_pw_every_90days,this.token=t.token,e(null,this.token)):e(new Error("No data"),null)}).catch(t=>{e(t,null)})}verifyDashboardToken(t,s){const e=this.GATE_API+"/dashboard/auth/verify2/";fetch(e,{headers:{authorization:t,"content-type":"application/json;charset=UTF-8"}}).then(t=>t.json()).then(t=>{t?(this.token=t.token,this.organizations=t.organizations,this.userInfo=t,s(null,!0)):s(new Error("No data"),!1)}).catch(t=>{s(t,!1)})}getToken(){return this.token}getOrganizations(){return this.organizations}getOrgId(){return this.getOrganizationValue("uuid")}getOrgName(){return this.getOrganizationValue("name")}getSignedUser(){return this.userInfo?this.userInfo.user:null}getOrgMembers(){return this.getOrganizationValue("members")}getLastLoginTime(){return this.last_login_at}getIsAccountLocked(){return this.account_locked}getUseLock30mins(){return this.use_lock_30mins}getUseLock90DaysNoLogin(){return this.use_lock_90days_no_login}getUseLock5TimesWrongPassword(){return this.use_lock_5times_wrong_pw}getUsePasswordPolicy(){return this.use_pw_policy}getUseChangePasswordEvery90Days(){return this.use_change_pw_every_90days}getApplications(t,s=null){if(this.token){const e=s||this.GATE_API+"/dashboard/applications/?limit=100&offset=0&app_name=&order=app_name",n=this.token;fetch(e,{headers:{authorization:n,"content-type":"application/json;charset=UTF-8"}}).then(t=>t.json()).then(s=>{s?(this.applications.push(...s.results),s.next?this.getApplications(t,s.next):t(null,this.applications)):t(new Error("No data"),this.applications)}).catch(s=>{t(s,this.applications)})}else t(new Error("No token"),null)}getApplicationDetails(t,s){if(this.token){const e=this.GATE_API+"/dashboard/applications/"+t+"/get_detail/",n=this.token;fetch(e,{headers:{authorization:n,"content-type":"application/json;charset=UTF-8"}}).then(t=>t.json()).then(t=>{t?s(null,t):s(new Error("No data"),null)}).catch(t=>{s(t,null)})}else s(new Error("No token"),null)}getPlanDetails(t){if(this.token){const s=this.GATE_API+"/dashboard_api/billing/subscriptions/current/?product=CHAT",e=this.token;fetch(s,{headers:{authorization:e,"content-type":"application/json;charset=UTF-8"}}).then(t=>t.json()).then(s=>{s?t(null,s):t(new Error("No data"),null)}).catch(s=>{t(s,null)})}else t(new Error("No token"),null)}getUsers(t,s,e,n=""){if(this.token){n||(this.users=[]);const i=`${this.GATE_API}/platform/v3/users?active_mode=all&limit=${s}&token=${n}`,o=this.token;fetch(i,{headers:{authorization:o,"content-type":"application/json;charset=UTF-8","app-id":t}}).then(t=>t.json()).then(t=>{t?(this.users=t.users,e(null,this.users)):e(new Error("No data"),this.users)}).catch(t=>{e(t,this.users)})}else e(new Error("No token"),this.users)}getUserByNickname(t,s,e,n,i=""){if(this.token){i||(this.users=[]);const o=`${this.GATE_API}/platform/v3/users?token=${i}&limit=${e}&active_mode=all&nickname=${s}`,a=this.token;fetch(o,{headers:{authorization:a,"content-type":"application/json;charset=UTF-8","app-id":t}}).then(t=>t.json()).then(t=>{t?(this.users=t.users,n(null,this.users)):n(new Error("No data"),this.users)}).catch(t=>{n(t,this.users)})}else n(new Error("No token"),this.users)}getUserByNicknameStartsWith(t,s,e,n,i=""){if(this.token){i||(this.users=[]);const o=`${this.GATE_API}/platform/v3/users?token=${i}&limit=${e}&active_mode=all&nickname_startswith=${s}`,a=this.token;fetch(o,{headers:{authorization:a,"content-type":"application/json;charset=UTF-8","app-id":t}}).then(t=>t.json()).then(t=>{t?(this.users=t.users,n(null,this.users)):n(new Error("No data"),this.users)}).catch(t=>{n(t,this.users)})}else n(new Error("No token"),this.users)}getOrganizationValue(t){return!this.organizations||!Array.isArray(this.organizations)||this.organizations.length<=0?null:this.organizations[0][t]}}exports.default=AmeliaSendbird;