Built motion from commit 5fcd269f5146f10cf3129722d518881dfac64576. Version 3.0.0...
[motion-next.git] / server / api / intZohoAccount / intZohoAccount.controller.js
index d5db5df..81966ff 100644 (file)
@@ -1 +1 @@
-const a346_0x145b=['response','ZohoConfiguration','VIRTUAL','model','lastIndexOf','getDescriptions','type','../../components/parsers/qs','Refresh\x20Token\x20not\x20available\x20for\x20the\x20account','substring','count','Zoho-oauthtoken\x20','serverUrl','intersection','https://accounts.zoho.com.cn','where','push','index','AccountId','refreshToken','Owner','host','pick_list_values','system_mandatory','length','body','nolimit','data_type','create','offset','options','clientSecret','getConfigurations','GET','catch','findOne','fields','zoho.eu','send','update','picklist','map','test','/oauth/v2/token','Unable\x20to\x20retrieve\x20the\x20access\x20token','error','ZohoAccount','status','https://accounts.zoho.com.au','getFields','../../config/logger','zone','Calls','channel','merge','includes','fieldName','Subject','then','json','destroy','Call_Duration','name','clientId','stringify','sendStatus','filters','custom_field','Call_Result','keys','order','limit','api','remove','findAll','https://www.zohoapis.%s/crm/v2/settings/fields','end','include','filter','refresh_token','statusCode','access_token','com','sequelize','show','Call_Start_Time','format','like','display_label','undefined','attributes','ZohoField','Subjects','../../mysqldb','params','rawAttributes','getFields,\x20%s,\x20%s,\x20%s','sort','util','query','Wrong\x20credentials','set'];(function(_0x2ec521,_0x145bd7){const _0x2ffa7a=function(_0x4775ef){while(--_0x4775ef){_0x2ec521['push'](_0x2ec521['shift']());}};_0x2ffa7a(++_0x145bd7);}(a346_0x145b,0x73));const a346_0x2ffa=function(_0x2ec521,_0x145bd7){_0x2ec521=_0x2ec521-0x0;let _0x2ffa7a=a346_0x145b[_0x2ec521];return _0x2ffa7a;};const _0x29152a=a346_0x2ffa;'use strict';const rp=require('request-promise-native'),util=require(_0x29152a('0x55')),_=require('lodash'),qs=require(_0x29152a('0x60')),logger=require(_0x29152a('0x25'))(_0x29152a('0x3b')),db=require(_0x29152a('0x50'))['db'],{Op}=require(_0x29152a('0x46')),integrations=require('../../components/integrations/configuration');function respondWithResult(_0x4775ef,_0x5cfa7a){return _0x5cfa7a=_0x5cfa7a||0xc8,function(_0x11d792){const _0x3abf19=a346_0x2ffa;if(_0x11d792)return _0x4775ef['status'](_0x5cfa7a)[_0x3abf19('0x2e')](_0x11d792);};}function respondWithFilteredResult(_0x1fb11e,_0x418f9d){return function(_0x538056){const _0x20ba50=a346_0x2ffa;if(_0x538056){const _0x10fdc5=_0x538056[_0x20ba50('0x63')],_0x4e9f7d=_0x418f9d[_0x20ba50('0x10')];let _0x465c32=_0x418f9d[_0x20ba50('0x10')]+_0x418f9d[_0x20ba50('0x3a')],_0x255d13;return _0x465c32>=_0x10fdc5?(_0x465c32=_0x10fdc5,_0x255d13=0xc8):_0x255d13=0xce,_0x1fb11e[_0x20ba50('0x22')](_0x255d13),_0x1fb11e[_0x20ba50('0x58')]('Content-Range',_0x4e9f7d+'-'+_0x465c32+'/'+_0x10fdc5)['json'](_0x538056);}return null;};}function saveUpdates(_0x57818a){return function(_0x1a8747){const _0x432636=a346_0x2ffa;if(_0x1a8747)return _0x1a8747[_0x432636('0x1a')](_0x57818a)['then'](function(_0x36ca7f){return _0x36ca7f;});return null;};}function removeEntity(_0x1a99a7){return function(_0xd627fa){const _0x1a3dcf=a346_0x2ffa;if(_0xd627fa)return _0xd627fa[_0x1a3dcf('0x2f')]()[_0x1a3dcf('0x2d')](function(){const _0x3d4132=_0x1a3dcf;_0x1a99a7['status'](0xcc)[_0x3d4132('0x3f')]();});};}function handleEntityNotFound(_0x2c5b61){return function(_0x2b49b7){const _0x389f2c=a346_0x2ffa;return!_0x2b49b7&&_0x2c5b61[_0x389f2c('0x34')](0x194),_0x2b49b7;};}function handleError(_0x254b53,_0x2a20d3){return _0x2a20d3=_0x2a20d3||0x1f4,function(_0x585292){const _0x4db2d9=a346_0x2ffa;logger['error'](_0x585292['stack']),_0x585292[_0x4db2d9('0x31')]&&delete _0x585292[_0x4db2d9('0x31')],_0x254b53['status'](_0x2a20d3)[_0x4db2d9('0x19')](_0x585292);};}exports[_0x29152a('0x4')]=function(_0x58efbd,_0x18eb50){const _0x478779=_0x29152a;let _0x44ed18={};const _0x26a693={},_0x3e6c14={'count':0x0,'rows':[]},_0x445a61=_['map'](db['ZohoAccount'][_0x478779('0x52')],function(_0x35ed2c){const _0x5697e0=_0x478779;return{'name':_0x35ed2c[_0x5697e0('0x2b')],'type':_0x35ed2c[_0x5697e0('0x5f')]['key']};});_0x26a693[_0x478779('0x5c')]=_['map'](_0x445a61,_0x478779('0x31')),_0x26a693['query']=_[_0x478779('0x38')](_0x58efbd[_0x478779('0x56')]),_0x26a693[_0x478779('0x35')]=_['intersection'](_0x26a693[_0x478779('0x5c')],_0x26a693[_0x478779('0x56')]),_0x44ed18['attributes']=_['intersection'](_0x26a693[_0x478779('0x5c')],qs['fields'](_0x58efbd['query'][_0x478779('0x17')])),_0x44ed18[_0x478779('0x4d')]=_0x44ed18[_0x478779('0x4d')][_0x478779('0xb')]?_0x44ed18[_0x478779('0x4d')]:_0x26a693[_0x478779('0x5c')];typeof _0x58efbd[_0x478779('0x56')]['nolimit']==='undefined'&&(_0x44ed18[_0x478779('0x3a')]=qs['limit'](_0x58efbd['query']['limit']),_0x44ed18[_0x478779('0x10')]=qs['offset'](_0x58efbd['query']['offset']));_0x44ed18[_0x478779('0x39')]=qs[_0x478779('0x54')](_0x58efbd['query'][_0x478779('0x54')]),_0x44ed18[_0x478779('0x2')]=qs[_0x478779('0x35')](_['pick'](_0x58efbd[_0x478779('0x56')],_0x26a693[_0x478779('0x35')]),_0x445a61);_0x58efbd[_0x478779('0x56')][_0x478779('0x41')]&&(_0x44ed18[_0x478779('0x2')]=_['merge'](_0x44ed18[_0x478779('0x2')],{[Op['or']]:_[_0x478779('0x1c')](_0x445a61,function(_0x262529){const _0x5be0ae=_0x478779;if(_0x262529[_0x5be0ae('0x5f')]!==_0x5be0ae('0x5b')){const _0x1ff9d4={};return _0x1ff9d4[_0x262529[_0x5be0ae('0x31')]]={[Op[_0x5be0ae('0x4a')]]:'%'+_0x58efbd['query'][_0x5be0ae('0x41')]+'%'},_0x1ff9d4;}})}));_0x44ed18=_[_0x478779('0x29')]({},_0x44ed18,_0x58efbd[_0x478779('0x11')]);const _0x372d11={'where':_0x44ed18['where']};return db[_0x478779('0x21')]['count'](_0x372d11)[_0x478779('0x2d')](function(_0x3485c9){const _0x199257=_0x478779;return _0x3e6c14[_0x199257('0x63')]=_0x3485c9,_0x58efbd[_0x199257('0x56')]['includeAll']&&(_0x44ed18[_0x199257('0x40')]=[{'all':!![]}]),db['ZohoAccount'][_0x199257('0x3d')](_0x44ed18);})[_0x478779('0x2d')](function(_0x8f1cff){return _0x3e6c14['rows']=_0x8f1cff,_0x3e6c14;})[_0x478779('0x2d')](respondWithFilteredResult(_0x18eb50,_0x44ed18))[_0x478779('0x15')](handleError(_0x18eb50,null));},exports[_0x29152a('0x47')]=function(_0x7fd753,_0x4e587f){const _0x43ae88=_0x29152a;let _0x260e48={'raw':![],'where':{'id':_0x7fd753[_0x43ae88('0x51')]['id']}};const _0xb5db80={};return _0xb5db80[_0x43ae88('0x5c')]=_[_0x43ae88('0x38')](db['ZohoAccount'][_0x43ae88('0x52')]),_0xb5db80[_0x43ae88('0x56')]=_['keys'](_0x7fd753[_0x43ae88('0x56')]),_0xb5db80['filters']=_[_0x43ae88('0x0')](_0xb5db80[_0x43ae88('0x5c')],_0xb5db80[_0x43ae88('0x56')]),_0x260e48[_0x43ae88('0x4d')]=_[_0x43ae88('0x0')](_0xb5db80[_0x43ae88('0x5c')],qs[_0x43ae88('0x17')](_0x7fd753[_0x43ae88('0x56')][_0x43ae88('0x17')])),_0x260e48['attributes']=_0x260e48[_0x43ae88('0x4d')][_0x43ae88('0xb')]?_0x260e48[_0x43ae88('0x4d')]:_0xb5db80[_0x43ae88('0x5c')],_0x7fd753['query']['includeAll']&&(_0x260e48[_0x43ae88('0x40')]=[{'all':!![]}]),_0x260e48=_['merge']({},_0x260e48,_0x7fd753[_0x43ae88('0x11')]),db[_0x43ae88('0x21')][_0x43ae88('0x16')](_0x260e48)[_0x43ae88('0x2d')](handleEntityNotFound(_0x4e587f,null))[_0x43ae88('0x2d')](respondWithResult(_0x4e587f,null))[_0x43ae88('0x15')](handleError(_0x4e587f,null));},exports[_0x29152a('0xf')]=function(_0x3e7419,_0x577337){const _0xa9224f=_0x29152a;return db[_0xa9224f('0x21')]['create'](_0x3e7419[_0xa9224f('0xc')],{})[_0xa9224f('0x2d')](respondWithResult(_0x577337,0xc9))[_0xa9224f('0x15')](handleError(_0x577337,null));},exports['update']=function(_0x2185f9,_0x1ae566){const _0x3387e8=_0x29152a;return _0x2185f9[_0x3387e8('0xc')]['id']&&delete _0x2185f9[_0x3387e8('0xc')]['id'],db[_0x3387e8('0x21')]['findOne']({'where':{'id':_0x2185f9[_0x3387e8('0x51')]['id']}})['then'](handleEntityNotFound(_0x1ae566,null))[_0x3387e8('0x2d')](saveUpdates(_0x2185f9[_0x3387e8('0xc')],null))[_0x3387e8('0x2d')](respondWithResult(_0x1ae566,null))[_0x3387e8('0x15')](handleError(_0x1ae566,null));},exports[_0x29152a('0x2f')]=function(_0x28a8ec,_0x505370){const _0x4976c1=_0x29152a;return db[_0x4976c1('0x21')][_0x4976c1('0x16')]({'where':{'id':_0x28a8ec['params']['id']}})['then'](handleEntityNotFound(_0x505370,null))[_0x4976c1('0x2d')](removeEntity(_0x505370,null))['catch'](handleError(_0x505370,null));},exports[_0x29152a('0x13')]=function(_0x1d924b,_0x1af98d){const _0x372274=_0x29152a;let _0x4c1eb2={};const _0x105a04={};let _0x4e4a81,_0x48794d;return db[_0x372274('0x21')][_0x372274('0x16')]({'where':{'id':_0x1d924b[_0x372274('0x51')]['id']}})[_0x372274('0x2d')](handleEntityNotFound(_0x1af98d,null))[_0x372274('0x2d')](function(_0x3c4165){const _0x1fe761=_0x372274;if(_0x3c4165)return _0x4e4a81=_0x3c4165,_0x105a04['model']=_[_0x1fe761('0x38')](db[_0x1fe761('0x5a')][_0x1fe761('0x52')]),_0x105a04[_0x1fe761('0x56')]=_['keys'](_0x1d924b[_0x1fe761('0x56')]),_0x105a04[_0x1fe761('0x35')]=_[_0x1fe761('0x0')](_0x105a04['model'],_0x105a04[_0x1fe761('0x56')]),_0x4c1eb2[_0x1fe761('0x4d')]=_['intersection'](_0x105a04[_0x1fe761('0x5c')],qs['fields'](_0x1d924b[_0x1fe761('0x56')][_0x1fe761('0x17')])),_0x4c1eb2[_0x1fe761('0x4d')]=_0x4c1eb2[_0x1fe761('0x4d')][_0x1fe761('0xb')]?_0x4c1eb2[_0x1fe761('0x4d')]:_0x105a04[_0x1fe761('0x5c')],_0x4c1eb2[_0x1fe761('0x39')]=qs[_0x1fe761('0x54')](_0x1d924b['query'][_0x1fe761('0x54')]),_0x4c1eb2['where']=qs[_0x1fe761('0x35')](_['pick'](_0x1d924b[_0x1fe761('0x56')],_0x105a04[_0x1fe761('0x35')])),_0x1d924b['query'][_0x1fe761('0x41')]&&(_0x4c1eb2['where']=_[_0x1fe761('0x29')](_0x4c1eb2[_0x1fe761('0x2')],{[Op['or']]:_[_0x1fe761('0x1c')](_0x4c1eb2[_0x1fe761('0x4d')],function(_0x5bb59b){const _0x548292=_0x1fe761,_0x33b889={};return _0x33b889[_0x5bb59b]={[Op[_0x548292('0x4a')]]:'%'+_0x1d924b['query']['filter']+'%'},_0x33b889;})})),_0x4c1eb2=_[_0x1fe761('0x29')]({},_0x4c1eb2,_0x1d924b[_0x1fe761('0x11')]),_0x4e4a81[_0x1fe761('0x13')](_0x4c1eb2);})['then'](function(_0x1242a9){const _0x129a6a=_0x372274;if(_0x1242a9)return _0x48794d=_0x1242a9[_0x129a6a('0xb')],typeof _0x1d924b[_0x129a6a('0x56')][_0x129a6a('0xd')]===_0x129a6a('0x4c')&&(_0x4c1eb2[_0x129a6a('0x3a')]=qs['limit'](_0x1d924b['query']['limit']),_0x4c1eb2[_0x129a6a('0x10')]=qs[_0x129a6a('0x10')](_0x1d924b[_0x129a6a('0x56')][_0x129a6a('0x10')])),_0x4e4a81['getConfigurations'](_0x4c1eb2);})[_0x372274('0x2d')](function(_0xad5452){if(_0xad5452)return _0xad5452?{'count':_0x48794d,'rows':_0xad5452}:null;})[_0x372274('0x2d')](respondWithResult(_0x1af98d,null))[_0x372274('0x15')](handleError(_0x1af98d,null));},exports['addConfiguration']=function(_0x5800c7,_0xf37e5){const _0x4f98d4=_0x29152a;return _0x5800c7['body']['id']&&delete _0x5800c7[_0x4f98d4('0xc')]['id'],db['ZohoAccount'][_0x4f98d4('0x16')]({'where':{'id':_0x5800c7['params']['id']}})['then'](handleEntityNotFound(_0xf37e5,null))[_0x4f98d4('0x2d')](function(_0x1a92ea){const _0x4672dc=_0x4f98d4;if(_0x1a92ea)return _0x5800c7['body'][_0x4672dc('0x5')]=_0x1a92ea['id'],_0x5800c7[_0x4672dc('0xc')]['Subjects']=integrations['getSubjects'](_0x5800c7[_0x4672dc('0xc')][_0x4672dc('0x28')],_0x5800c7[_0x4672dc('0xc')][_0x4672dc('0x5f')]),_0x5800c7[_0x4672dc('0xc')]['Descriptions']=integrations[_0x4672dc('0x5e')](_0x5800c7[_0x4672dc('0xc')]['channel'],_0x5800c7[_0x4672dc('0xc')][_0x4672dc('0x5f')]),db[_0x4672dc('0x5a')][_0x4672dc('0xf')](_0x5800c7[_0x4672dc('0xc')],{'include':[{'model':db[_0x4672dc('0x4e')],'as':_0x4672dc('0x4f')},{'model':db[_0x4672dc('0x4e')],'as':'Descriptions'}]});return null;})[_0x4f98d4('0x2d')](respondWithResult(_0xf37e5,null))[_0x4f98d4('0x15')](handleError(_0xf37e5,null));};function getAccessToken(_0x5814e0){return new Promise(function(_0x1052c7,_0x2c5315){const _0x3ac23e=a346_0x2ffa;let _0x146279;switch(_0x5814e0[_0x3ac23e('0x26')]){case'US':_0x146279='https://accounts.zoho.com';break;case'AU':_0x146279=_0x3ac23e('0x23');break;case'EU':_0x146279='https://accounts.zoho.eu';break;case'IN':_0x146279='https://accounts.zoho.in';break;case'CN':_0x146279=_0x3ac23e('0x1');break;default:_0x146279='https://accounts.zoho.eu';break;}const _0x5751f8={'method':'POST','uri':_0x146279+_0x3ac23e('0x1e'),'qs':{'refresh_token':_0x5814e0[_0x3ac23e('0x6')],'client_id':_0x5814e0[_0x3ac23e('0x32')],'client_secret':_0x5814e0[_0x3ac23e('0x12')],'grant_type':_0x3ac23e('0x42')},'json':!![]};return rp(_0x5751f8)[_0x3ac23e('0x2d')](function(_0x413e65){const _0x28ec3a=_0x3ac23e;_0x413e65[_0x28ec3a('0x44')]?_0x1052c7(_0x413e65[_0x28ec3a('0x44')]):_0x2c5315(_0x28ec3a('0x1f'));})[_0x3ac23e('0x15')](function(_0x238b0d){_0x2c5315(_0x238b0d);});});}exports[_0x29152a('0x24')]=function(_0x4a2588,_0x1e45d7){const _0x3bc667=_0x29152a;let _0x4c15b3,_0x3cc188,_0x3bf3e9,_0x3ef54d;return db[_0x3bc667('0x21')][_0x3bc667('0x16')]({'where':{'id':_0x4a2588[_0x3bc667('0x51')]['id']},'attributes':['id',_0x3bc667('0x8'),_0x3bc667('0x26'),'clientId',_0x3bc667('0x12'),_0x3bc667('0x65'),'code',_0x3bc667('0x6')]})[_0x3bc667('0x2d')](handleEntityNotFound(_0x1e45d7,null))[_0x3bc667('0x2d')](function(_0xf4ed00){const _0x57b3e8=_0x3bc667;_0x3ef54d=_0xf4ed00,_0x4c15b3=_0x3ef54d[_0x57b3e8('0x8')],_0x3cc188=_0x4c15b3===_0x57b3e8('0x18')?'eu':_0x57b3e8('0x45'),_0x3bf3e9=_0x3ef54d[_0x57b3e8('0x65')];const _0x5d2b13=_0x3bf3e9['slice'](-0x1);(_0x5d2b13==='/'||_0x5d2b13==='\x5c'||_0x5d2b13===':')&&(_0x3bf3e9=_0x3bf3e9[_0x57b3e8('0x62')](0x0,_0x3bf3e9[_0x57b3e8('0x5d')](_0x5d2b13)));if(!_0x3ef54d[_0x57b3e8('0x6')])throw new Error(_0x57b3e8('0x61'));return getAccessToken(_0x3ef54d);})[_0x3bc667('0x2d')](function(_0x2e4668){const _0x45be44=_0x3bc667;if(_0x2e4668)return rp({'method':_0x45be44('0x14'),'uri':util[_0x45be44('0x49')](_0x45be44('0x3e'),_0x3cc188),'qs':{'module':_0x45be44('0x27')},'headers':{'Authorization':_0x45be44('0x64')+_0x2e4668},'json':!![]});})[_0x3bc667('0x2d')](function(_0x39a7ce){const _0x17aa37=_0x3bc667;if(_0x39a7ce){if(_0x39a7ce['response']&&_0x39a7ce[_0x17aa37('0x59')][_0x17aa37('0x20')])throw new Error(_0x39a7ce[_0x17aa37('0x59')][_0x17aa37('0x20')]['message']);const _0x2e6480=[];let _0x4c5f58=[];const _0x17af30=[_0x17aa37('0x7'),_0x17aa37('0x2c'),'Description','WhoId',_0x17aa37('0x30'),_0x17aa37('0x37'),_0x17aa37('0x48'),'Call_Type'];_0x4c5f58=_[_0x17aa37('0x3c')](_0x39a7ce[_0x17aa37('0x17')],function(_0x388638){const _0xb0a998=_0x17aa37;return _0x17af30[_0xb0a998('0x2a')](_0x388638['api_name']);});for(let _0x1cfb49=0x0;_0x1cfb49<_0x4c5f58[_0x17aa37('0xb')];_0x1cfb49++){_0x4c5f58[_0x1cfb49][_0x17aa37('0xa')]===![]&&_0x2e6480[_0x17aa37('0x3')]({'id':_0x4c5f58[_0x1cfb49]['id'],'name':_0x4c5f58[_0x1cfb49][_0x17aa37('0x4b')],'custom':_0x4c5f58[_0x1cfb49][_0x17aa37('0x36')],'options':_0x4c5f58[_0x1cfb49][_0x17aa37('0xe')]===_0x17aa37('0x1b')&&_0x4c5f58[_0x1cfb49]['pick_list_values'][_0x17aa37('0xb')]>-0x1?_['map'](_0x4c5f58[_0x1cfb49][_0x17aa37('0x9')],function(_0x5cbacf){return{'name':_0x5cbacf,'value':_0x5cbacf};}):[]});}return{'count':_0x2e6480[_0x17aa37('0xb')],'rows':_0x2e6480};}else return{'count':0x0,'rows':[]};})['then'](respondWithResult(_0x1e45d7,null))['catch'](function(_0x78dbc4){const _0x38bb93=_0x3bc667;let _0x29cf84=_0x4a2588[_0x38bb93('0x56')][_0x38bb93('0x1d')]?0x1f4:_0x78dbc4[_0x38bb93('0x43')]||0x1f4;logger[_0x38bb93('0x20')](_0x38bb93('0x53'),_0x38bb93('0x24'),_0x29cf84,JSON[_0x38bb93('0x33')](_0x78dbc4)),delete _0x78dbc4[_0x38bb93('0x31')],_0x29cf84===0x191&&(_0x29cf84=0x190),_0x1e45d7[_0x38bb93('0x22')](_0x29cf84)[_0x38bb93('0x19')](_0x4a2588[_0x38bb93('0x56')]['test']?{'message':_0x38bb93('0x57'),'statusCode':_0x78dbc4['statusCode']}:_0x78dbc4);});};
\ No newline at end of file
+const a346_0x50e9=['/oauth/v2/token','Calls','data_type','key','Refresh\x20Token\x20not\x20available\x20for\x20the\x20account','Description','destroy','clientSecret','Subject','ZohoField','merge','sendStatus','order','api','pick_list_values','map','findOne','name','fields','api_name','ZohoAccount','body','lastIndexOf','picklist','statusCode','filter','model','undefined','zoho.eu','getFields','https://accounts.zoho.com','options','end','json','refreshToken','Unable\x20to\x20retrieve\x20the\x20access\x20token','test','lodash','count','rows','serverUrl','POST','refresh_token','https://accounts.zoho.com.cn','include','Wrong\x20credentials','includes','slice','ZohoConfiguration','offset','custom_field','fieldName','query','length','clientId','sort','system_mandatory','findAll','create','host','filters','like','channel','access_token','params','zone','index','getDescriptions','format','status','../../components/parsers/qs','error','util','stringify','code','Content-Range','includeAll','Descriptions','getConfigurations','then','sequelize','keys','limit','where','stack','catch','WhoId','send','response','attributes','nolimit','https://accounts.zoho.eu','pick','display_label','getFields,\x20%s,\x20%s,\x20%s','rawAttributes','show','intersection','addConfiguration','type','Call_Start_Time','update','https://www.zohoapis.%s/crm/v2/settings/fields'];(function(_0x42f4b1,_0x50e922){const _0x42734c=function(_0x14c257){while(--_0x14c257){_0x42f4b1['push'](_0x42f4b1['shift']());}};_0x42734c(++_0x50e922);}(a346_0x50e9,0x7f));const a346_0x4273=function(_0x42f4b1,_0x50e922){_0x42f4b1=_0x42f4b1-0x0;let _0x42734c=a346_0x50e9[_0x42f4b1];return _0x42734c;};const _0x287329=a346_0x4273;'use strict';const rp=require('request-promise-native'),util=require(_0x287329('0x30')),_=require(_0x287329('0xd')),qs=require(_0x287329('0x2e')),logger=require('../../config/logger')(_0x287329('0x5c')),db=require('../../mysqldb')['db'],{Op}=require(_0x287329('0x38')),integrations=require('../../components/integrations/configuration');function respondWithResult(_0x14c257,_0x17b003){return _0x17b003=_0x17b003||0xc8,function(_0x358835){const _0x7422d3=a346_0x4273;if(_0x358835)return _0x14c257[_0x7422d3('0x2d')](_0x17b003)[_0x7422d3('0x9')](_0x358835);};}function respondWithFilteredResult(_0x52706d,_0x4faa98){return function(_0xcaa6fd){const _0x3b2fb3=a346_0x4273;if(_0xcaa6fd){const _0x13c89c=_0xcaa6fd[_0x3b2fb3('0xe')],_0x5bca5e=_0x4faa98[_0x3b2fb3('0x19')];let _0x589232=_0x4faa98['offset']+_0x4faa98[_0x3b2fb3('0x3a')],_0x67633e;return _0x589232>=_0x13c89c?(_0x589232=_0x13c89c,_0x67633e=0xc8):_0x67633e=0xce,_0x52706d[_0x3b2fb3('0x2d')](_0x67633e),_0x52706d['set'](_0x3b2fb3('0x33'),_0x5bca5e+'-'+_0x589232+'/'+_0x13c89c)[_0x3b2fb3('0x9')](_0xcaa6fd);}return null;};}function saveUpdates(_0x2aa116){return function(_0x5ef25b){const _0x5baac2=a346_0x4273;if(_0x5ef25b)return _0x5ef25b[_0x5baac2('0x4d')](_0x2aa116)[_0x5baac2('0x37')](function(_0x1664df){return _0x1664df;});return null;};}function removeEntity(_0x462a41){return function(_0x2cb96){const _0x1b3dc8=a346_0x4273;if(_0x2cb96)return _0x2cb96[_0x1b3dc8('0x55')]()[_0x1b3dc8('0x37')](function(){const _0x2b5805=_0x1b3dc8;_0x462a41[_0x2b5805('0x2d')](0xcc)[_0x2b5805('0x8')]();});};}function handleEntityNotFound(_0x2b47f0){return function(_0x5c4e67){const _0x4a9edf=a346_0x4273;return!_0x5c4e67&&_0x2b47f0[_0x4a9edf('0x5a')](0x194),_0x5c4e67;};}function handleError(_0x294459,_0x364ae6){return _0x364ae6=_0x364ae6||0x1f4,function(_0x5d63e7){const _0xa22f4a=a346_0x4273;logger[_0xa22f4a('0x2f')](_0x5d63e7[_0xa22f4a('0x3c')]),_0x5d63e7[_0xa22f4a('0x60')]&&delete _0x5d63e7['name'],_0x294459[_0xa22f4a('0x2d')](_0x364ae6)[_0xa22f4a('0x3f')](_0x5d63e7);};}exports[_0x287329('0x2a')]=function(_0x5973a8,_0x25c471){const _0xb1acf0=_0x287329;let _0x35c360={};const _0x4ea846={},_0x1439d1={'count':0x0,'rows':[]},_0x35858d=_[_0xb1acf0('0x5e')](db[_0xb1acf0('0x63')]['rawAttributes'],function(_0x539190){const _0x3ebf8e=_0xb1acf0;return{'name':_0x539190[_0x3ebf8e('0x1b')],'type':_0x539190['type'][_0x3ebf8e('0x52')]};});_0x4ea846[_0xb1acf0('0x2')]=_[_0xb1acf0('0x5e')](_0x35858d,_0xb1acf0('0x60')),_0x4ea846[_0xb1acf0('0x1c')]=_[_0xb1acf0('0x39')](_0x5973a8[_0xb1acf0('0x1c')]),_0x4ea846[_0xb1acf0('0x24')]=_[_0xb1acf0('0x49')](_0x4ea846[_0xb1acf0('0x2')],_0x4ea846['query']),_0x35c360[_0xb1acf0('0x41')]=_['intersection'](_0x4ea846[_0xb1acf0('0x2')],qs['fields'](_0x5973a8[_0xb1acf0('0x1c')][_0xb1acf0('0x61')])),_0x35c360[_0xb1acf0('0x41')]=_0x35c360['attributes'][_0xb1acf0('0x1d')]?_0x35c360[_0xb1acf0('0x41')]:_0x4ea846['model'];typeof _0x5973a8[_0xb1acf0('0x1c')][_0xb1acf0('0x42')]===_0xb1acf0('0x3')&&(_0x35c360[_0xb1acf0('0x3a')]=qs['limit'](_0x5973a8['query'][_0xb1acf0('0x3a')]),_0x35c360[_0xb1acf0('0x19')]=qs['offset'](_0x5973a8['query'][_0xb1acf0('0x19')]));_0x35c360[_0xb1acf0('0x5b')]=qs[_0xb1acf0('0x1f')](_0x5973a8['query']['sort']),_0x35c360[_0xb1acf0('0x3b')]=qs[_0xb1acf0('0x24')](_[_0xb1acf0('0x44')](_0x5973a8[_0xb1acf0('0x1c')],_0x4ea846['filters']),_0x35858d);_0x5973a8[_0xb1acf0('0x1c')][_0xb1acf0('0x1')]&&(_0x35c360[_0xb1acf0('0x3b')]=_[_0xb1acf0('0x59')](_0x35c360[_0xb1acf0('0x3b')],{[Op['or']]:_[_0xb1acf0('0x5e')](_0x35858d,function(_0x3cba5a){const _0x2d7f74=_0xb1acf0;if(_0x3cba5a[_0x2d7f74('0x4b')]!=='VIRTUAL'){const _0x329b8c={};return _0x329b8c[_0x3cba5a[_0x2d7f74('0x60')]]={[Op[_0x2d7f74('0x25')]]:'%'+_0x5973a8['query'][_0x2d7f74('0x1')]+'%'},_0x329b8c;}})}));_0x35c360=_[_0xb1acf0('0x59')]({},_0x35c360,_0x5973a8[_0xb1acf0('0x7')]);const _0x5be183={'where':_0x35c360[_0xb1acf0('0x3b')]};return db[_0xb1acf0('0x63')][_0xb1acf0('0xe')](_0x5be183)[_0xb1acf0('0x37')](function(_0x5ecc66){const _0xca0b6d=_0xb1acf0;return _0x1439d1[_0xca0b6d('0xe')]=_0x5ecc66,_0x5973a8[_0xca0b6d('0x1c')][_0xca0b6d('0x34')]&&(_0x35c360[_0xca0b6d('0x14')]=[{'all':!![]}]),db[_0xca0b6d('0x63')][_0xca0b6d('0x21')](_0x35c360);})['then'](function(_0x14b3ea){const _0x167b27=_0xb1acf0;return _0x1439d1[_0x167b27('0xf')]=_0x14b3ea,_0x1439d1;})[_0xb1acf0('0x37')](respondWithFilteredResult(_0x25c471,_0x35c360))[_0xb1acf0('0x3d')](handleError(_0x25c471,null));},exports[_0x287329('0x48')]=function(_0x40fb14,_0x5b7bc5){const _0x2e2eb6=_0x287329;let _0x4e9c94={'raw':![],'where':{'id':_0x40fb14[_0x2e2eb6('0x28')]['id']}};const _0x396550={};return _0x396550['model']=_[_0x2e2eb6('0x39')](db[_0x2e2eb6('0x63')]['rawAttributes']),_0x396550[_0x2e2eb6('0x1c')]=_[_0x2e2eb6('0x39')](_0x40fb14[_0x2e2eb6('0x1c')]),_0x396550[_0x2e2eb6('0x24')]=_[_0x2e2eb6('0x49')](_0x396550['model'],_0x396550[_0x2e2eb6('0x1c')]),_0x4e9c94[_0x2e2eb6('0x41')]=_['intersection'](_0x396550[_0x2e2eb6('0x2')],qs['fields'](_0x40fb14['query']['fields'])),_0x4e9c94[_0x2e2eb6('0x41')]=_0x4e9c94[_0x2e2eb6('0x41')][_0x2e2eb6('0x1d')]?_0x4e9c94[_0x2e2eb6('0x41')]:_0x396550[_0x2e2eb6('0x2')],_0x40fb14['query'][_0x2e2eb6('0x34')]&&(_0x4e9c94[_0x2e2eb6('0x14')]=[{'all':!![]}]),_0x4e9c94=_[_0x2e2eb6('0x59')]({},_0x4e9c94,_0x40fb14[_0x2e2eb6('0x7')]),db[_0x2e2eb6('0x63')][_0x2e2eb6('0x5f')](_0x4e9c94)[_0x2e2eb6('0x37')](handleEntityNotFound(_0x5b7bc5,null))[_0x2e2eb6('0x37')](respondWithResult(_0x5b7bc5,null))['catch'](handleError(_0x5b7bc5,null));},exports[_0x287329('0x22')]=function(_0x22e456,_0x538d01){const _0x2e4bfc=_0x287329;return db[_0x2e4bfc('0x63')][_0x2e4bfc('0x22')](_0x22e456[_0x2e4bfc('0x64')],{})[_0x2e4bfc('0x37')](respondWithResult(_0x538d01,0xc9))['catch'](handleError(_0x538d01,null));},exports['update']=function(_0x407d0f,_0x25cce0){const _0x4727d2=_0x287329;return _0x407d0f[_0x4727d2('0x64')]['id']&&delete _0x407d0f[_0x4727d2('0x64')]['id'],db['ZohoAccount']['findOne']({'where':{'id':_0x407d0f[_0x4727d2('0x28')]['id']}})[_0x4727d2('0x37')](handleEntityNotFound(_0x25cce0,null))[_0x4727d2('0x37')](saveUpdates(_0x407d0f['body'],null))[_0x4727d2('0x37')](respondWithResult(_0x25cce0,null))['catch'](handleError(_0x25cce0,null));},exports['destroy']=function(_0x334e5d,_0xe50dc7){const _0x2b25a6=_0x287329;return db[_0x2b25a6('0x63')][_0x2b25a6('0x5f')]({'where':{'id':_0x334e5d['params']['id']}})[_0x2b25a6('0x37')](handleEntityNotFound(_0xe50dc7,null))['then'](removeEntity(_0xe50dc7,null))['catch'](handleError(_0xe50dc7,null));},exports['getConfigurations']=function(_0x575d1f,_0x17211c){const _0x53fc86=_0x287329;let _0x600853={};const _0x2295b1={};let _0x4382af,_0x537548;return db[_0x53fc86('0x63')][_0x53fc86('0x5f')]({'where':{'id':_0x575d1f[_0x53fc86('0x28')]['id']}})[_0x53fc86('0x37')](handleEntityNotFound(_0x17211c,null))[_0x53fc86('0x37')](function(_0x43ac33){const _0x3a0de6=_0x53fc86;if(_0x43ac33)return _0x4382af=_0x43ac33,_0x2295b1[_0x3a0de6('0x2')]=_[_0x3a0de6('0x39')](db[_0x3a0de6('0x18')][_0x3a0de6('0x47')]),_0x2295b1[_0x3a0de6('0x1c')]=_[_0x3a0de6('0x39')](_0x575d1f[_0x3a0de6('0x1c')]),_0x2295b1[_0x3a0de6('0x24')]=_[_0x3a0de6('0x49')](_0x2295b1['model'],_0x2295b1['query']),_0x600853['attributes']=_[_0x3a0de6('0x49')](_0x2295b1[_0x3a0de6('0x2')],qs['fields'](_0x575d1f[_0x3a0de6('0x1c')][_0x3a0de6('0x61')])),_0x600853[_0x3a0de6('0x41')]=_0x600853[_0x3a0de6('0x41')][_0x3a0de6('0x1d')]?_0x600853['attributes']:_0x2295b1[_0x3a0de6('0x2')],_0x600853['order']=qs[_0x3a0de6('0x1f')](_0x575d1f[_0x3a0de6('0x1c')][_0x3a0de6('0x1f')]),_0x600853['where']=qs[_0x3a0de6('0x24')](_['pick'](_0x575d1f[_0x3a0de6('0x1c')],_0x2295b1[_0x3a0de6('0x24')])),_0x575d1f['query'][_0x3a0de6('0x1')]&&(_0x600853[_0x3a0de6('0x3b')]=_[_0x3a0de6('0x59')](_0x600853['where'],{[Op['or']]:_['map'](_0x600853[_0x3a0de6('0x41')],function(_0x1f193c){const _0x147934=_0x3a0de6,_0x4e0341={};return _0x4e0341[_0x1f193c]={[Op[_0x147934('0x25')]]:'%'+_0x575d1f['query']['filter']+'%'},_0x4e0341;})})),_0x600853=_[_0x3a0de6('0x59')]({},_0x600853,_0x575d1f[_0x3a0de6('0x7')]),_0x4382af[_0x3a0de6('0x36')](_0x600853);})[_0x53fc86('0x37')](function(_0xd09986){const _0x4c8559=_0x53fc86;if(_0xd09986)return _0x537548=_0xd09986[_0x4c8559('0x1d')],typeof _0x575d1f[_0x4c8559('0x1c')][_0x4c8559('0x42')]===_0x4c8559('0x3')&&(_0x600853[_0x4c8559('0x3a')]=qs[_0x4c8559('0x3a')](_0x575d1f[_0x4c8559('0x1c')][_0x4c8559('0x3a')]),_0x600853[_0x4c8559('0x19')]=qs[_0x4c8559('0x19')](_0x575d1f[_0x4c8559('0x1c')][_0x4c8559('0x19')])),_0x4382af['getConfigurations'](_0x600853);})[_0x53fc86('0x37')](function(_0x4088b4){if(_0x4088b4)return _0x4088b4?{'count':_0x537548,'rows':_0x4088b4}:null;})[_0x53fc86('0x37')](respondWithResult(_0x17211c,null))['catch'](handleError(_0x17211c,null));},exports[_0x287329('0x4a')]=function(_0x3f9f40,_0x297099){const _0x1ff55e=_0x287329;return _0x3f9f40[_0x1ff55e('0x64')]['id']&&delete _0x3f9f40['body']['id'],db[_0x1ff55e('0x63')][_0x1ff55e('0x5f')]({'where':{'id':_0x3f9f40[_0x1ff55e('0x28')]['id']}})[_0x1ff55e('0x37')](handleEntityNotFound(_0x297099,null))['then'](function(_0x423176){const _0x24ceed=_0x1ff55e;if(_0x423176)return _0x3f9f40[_0x24ceed('0x64')]['AccountId']=_0x423176['id'],_0x3f9f40['body']['Subjects']=integrations['getSubjects'](_0x3f9f40['body'][_0x24ceed('0x26')],_0x3f9f40[_0x24ceed('0x64')][_0x24ceed('0x4b')]),_0x3f9f40[_0x24ceed('0x64')][_0x24ceed('0x35')]=integrations[_0x24ceed('0x2b')](_0x3f9f40[_0x24ceed('0x64')][_0x24ceed('0x26')],_0x3f9f40[_0x24ceed('0x64')][_0x24ceed('0x4b')]),db['ZohoConfiguration'][_0x24ceed('0x22')](_0x3f9f40['body'],{'include':[{'model':db[_0x24ceed('0x58')],'as':'Subjects'},{'model':db['ZohoField'],'as':_0x24ceed('0x35')}]});return null;})[_0x1ff55e('0x37')](respondWithResult(_0x297099,null))[_0x1ff55e('0x3d')](handleError(_0x297099,null));};function getAccessToken(_0x4b7927){return new Promise(function(_0x620fab,_0x4bd06c){const _0x14473c=a346_0x4273;let _0x337439;switch(_0x4b7927[_0x14473c('0x29')]){case'US':_0x337439=_0x14473c('0x6');break;case'AU':_0x337439='https://accounts.zoho.com.au';break;case'EU':_0x337439=_0x14473c('0x43');break;case'IN':_0x337439='https://accounts.zoho.in';break;case'CN':_0x337439=_0x14473c('0x13');break;default:_0x337439=_0x14473c('0x43');break;}const _0x349a21={'method':_0x14473c('0x11'),'uri':_0x337439+_0x14473c('0x4f'),'qs':{'refresh_token':_0x4b7927[_0x14473c('0xa')],'client_id':_0x4b7927[_0x14473c('0x1e')],'client_secret':_0x4b7927['clientSecret'],'grant_type':_0x14473c('0x12')},'json':!![]};return rp(_0x349a21)[_0x14473c('0x37')](function(_0x5a66fd){const _0x558be2=_0x14473c;_0x5a66fd[_0x558be2('0x27')]?_0x620fab(_0x5a66fd[_0x558be2('0x27')]):_0x4bd06c(_0x558be2('0xb'));})[_0x14473c('0x3d')](function(_0x20483c){_0x4bd06c(_0x20483c);});});}exports['getFields']=function(_0x4290ce,_0x3bf3dc){const _0x55b1f7=_0x287329;let _0x574876,_0x4903fc,_0x3888b5,_0x304e00;return db[_0x55b1f7('0x63')][_0x55b1f7('0x5f')]({'where':{'id':_0x4290ce['params']['id']},'attributes':['id',_0x55b1f7('0x23'),_0x55b1f7('0x29'),_0x55b1f7('0x1e'),_0x55b1f7('0x56'),_0x55b1f7('0x10'),_0x55b1f7('0x32'),_0x55b1f7('0xa')]})['then'](handleEntityNotFound(_0x3bf3dc,null))[_0x55b1f7('0x37')](function(_0x59030c){const _0x1c3c71=_0x55b1f7;_0x304e00=_0x59030c,_0x574876=_0x304e00['host'],_0x4903fc=_0x574876===_0x1c3c71('0x4')?'eu':'com',_0x3888b5=_0x304e00[_0x1c3c71('0x10')];const _0x5c7b9a=_0x3888b5[_0x1c3c71('0x17')](-0x1);(_0x5c7b9a==='/'||_0x5c7b9a==='\x5c'||_0x5c7b9a===':')&&(_0x3888b5=_0x3888b5['substring'](0x0,_0x3888b5[_0x1c3c71('0x65')](_0x5c7b9a)));if(!_0x304e00[_0x1c3c71('0xa')])throw new Error(_0x1c3c71('0x53'));return getAccessToken(_0x304e00);})[_0x55b1f7('0x37')](function(_0x1a0499){const _0xf50342=_0x55b1f7;if(_0x1a0499)return rp({'method':'GET','uri':util[_0xf50342('0x2c')](_0xf50342('0x4e'),_0x4903fc),'qs':{'module':_0xf50342('0x50')},'headers':{'Authorization':'Zoho-oauthtoken\x20'+_0x1a0499},'json':!![]});})[_0x55b1f7('0x37')](function(_0x2b7d05){const _0x2c9731=_0x55b1f7;if(_0x2b7d05){if(_0x2b7d05[_0x2c9731('0x40')]&&_0x2b7d05[_0x2c9731('0x40')]['error'])throw new Error(_0x2b7d05[_0x2c9731('0x40')][_0x2c9731('0x2f')]['message']);const _0x2446f4=[];let _0x1e11d6=[];const _0x5698aa=['Owner',_0x2c9731('0x57'),_0x2c9731('0x54'),_0x2c9731('0x3e'),'Call_Duration','Call_Result',_0x2c9731('0x4c'),'Call_Type'];_0x1e11d6=_['remove'](_0x2b7d05[_0x2c9731('0x61')],function(_0x44ca58){const _0x5c0171=_0x2c9731;return _0x5698aa[_0x5c0171('0x16')](_0x44ca58[_0x5c0171('0x62')]);});for(let _0x1b5dbc=0x0;_0x1b5dbc<_0x1e11d6[_0x2c9731('0x1d')];_0x1b5dbc++){_0x1e11d6[_0x1b5dbc][_0x2c9731('0x20')]===![]&&_0x2446f4['push']({'id':_0x1e11d6[_0x1b5dbc]['id'],'name':_0x1e11d6[_0x1b5dbc][_0x2c9731('0x45')],'custom':_0x1e11d6[_0x1b5dbc][_0x2c9731('0x1a')],'options':_0x1e11d6[_0x1b5dbc][_0x2c9731('0x51')]===_0x2c9731('0x66')&&_0x1e11d6[_0x1b5dbc][_0x2c9731('0x5d')]['length']>-0x1?_['map'](_0x1e11d6[_0x1b5dbc][_0x2c9731('0x5d')],function(_0x4105d4){return{'name':_0x4105d4,'value':_0x4105d4};}):[]});}return{'count':_0x2446f4['length'],'rows':_0x2446f4};}else return{'count':0x0,'rows':[]};})[_0x55b1f7('0x37')](respondWithResult(_0x3bf3dc,null))[_0x55b1f7('0x3d')](function(_0x188112){const _0x19ee55=_0x55b1f7;let _0x1e5b38=_0x4290ce[_0x19ee55('0x1c')][_0x19ee55('0xc')]?0x1f4:_0x188112[_0x19ee55('0x0')]||0x1f4;logger[_0x19ee55('0x2f')](_0x19ee55('0x46'),_0x19ee55('0x5'),_0x1e5b38,JSON[_0x19ee55('0x31')](_0x188112)),delete _0x188112['name'],_0x1e5b38===0x191&&(_0x1e5b38=0x190),_0x3bf3dc[_0x19ee55('0x2d')](_0x1e5b38)[_0x19ee55('0x3f')](_0x4290ce[_0x19ee55('0x1c')][_0x19ee55('0xc')]?{'message':_0x19ee55('0x15'),'statusCode':_0x188112[_0x19ee55('0x0')]}:_0x188112);});};
\ No newline at end of file