Built motion from commit b0a9a629.|2.6.33
[motion2.git] / server / api / intZohoAccount / intZohoAccount.controller.js
index dd1acda..8672bd8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa546=['query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','catch','rawAttributes','create','body','find','params','getConfigurations','findOne','ZohoConfiguration','options','hasOwnProperty','addConfiguration','AccountId','Subjects','getSubjects','channel','Descriptions','ZohoField','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.in','https://accounts.zoho.com.cn','/oauth/v2/token','refreshToken','clientSecret','refresh_token','access_token','Unable\x20to\x20retrieve\x20the\x20access\x20token','getFields','host','clientId','serverUrl','zoho.eu','lastIndexOf','Refresh\x20Token\x20not\x20available\x20for\x20the\x20account','GET','format','Calls','Zoho-oauthtoken\x20','response','message','Owner','Subject','Description','WhoId','Call_Duration','Call_Result','Call_Type','remove','includes','api_name','system_mandatory','push','display_label','custom_field','data_type','test','stringify','send','Wrong\x20credentials','statusCode','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','sox','ejs','fs-extra','squel','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../components/integrations/configuration','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','index','map','ZohoAccount','fieldName','type','key','model'];(function(_0x27c84c,_0x115c01){var _0x1bccfc=function(_0x465bf8){while(--_0x465bf8){_0x27c84c['push'](_0x27c84c['shift']());}};_0x1bccfc(++_0x115c01);}(_0xa546,0x151));var _0x6a54=function(_0x52cc6f,_0x573910){_0x52cc6f=_0x52cc6f-0x0;var _0x23941a=_0xa546[_0x52cc6f];return _0x23941a;};'use strict';var emlformat=require(_0x6a54('0x0'));var rimraf=require(_0x6a54('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x6a54('0x2'));var rp=require(_0x6a54('0x3'));var moment=require(_0x6a54('0x4'));var BPromise=require(_0x6a54('0x5'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x6a54('0x6'));var csv=require('to-csv');var ejs=require(_0x6a54('0x7'));var fs=require('fs');var fs_extra=require(_0x6a54('0x8'));var _=require('lodash');var squel=require(_0x6a54('0x9'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x6a54('0xa'));var toCsv=require('to-csv');var querystring=require(_0x6a54('0xb'));var Papa=require(_0x6a54('0xc'));var Redis=require(_0x6a54('0xd'));var authService=require(_0x6a54('0xe'));var qs=require(_0x6a54('0xf'));var as=require(_0x6a54('0x10'));var hardwareService=require(_0x6a54('0x11'));var logger=require(_0x6a54('0x12'))('api');var utils=require(_0x6a54('0x13'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];var integrations=require(_0x6a54('0x14'));function respondWithStatusCode(_0x26245d,_0x1416d0){_0x1416d0=_0x1416d0||0xcc;return function(_0x142cab){if(_0x142cab){return _0x26245d[_0x6a54('0x15')](_0x1416d0);}return _0x26245d[_0x6a54('0x16')](_0x1416d0)[_0x6a54('0x17')]();};}function respondWithResult(_0x49b267,_0x437ffe){_0x437ffe=_0x437ffe||0xc8;return function(_0x57525e){if(_0x57525e){return _0x49b267[_0x6a54('0x16')](_0x437ffe)[_0x6a54('0x18')](_0x57525e);}};}function respondWithFilteredResult(_0x4f0061,_0x1334f3){return function(_0x2775d3){if(_0x2775d3){var _0x2587ab=typeof _0x1334f3[_0x6a54('0x19')]===_0x6a54('0x1a')&&typeof _0x1334f3[_0x6a54('0x1b')]===_0x6a54('0x1a');var _0x32e505=_0x2775d3['count'];var _0x539216=_0x2587ab?0x0:_0x1334f3[_0x6a54('0x19')];var _0x42304f=_0x2587ab?_0x2775d3[_0x6a54('0x1c')]:_0x1334f3[_0x6a54('0x19')]+_0x1334f3[_0x6a54('0x1b')];var _0x30f741;if(_0x42304f>=_0x32e505){_0x42304f=_0x32e505;_0x30f741=0xc8;}else{_0x30f741=0xce;}_0x4f0061[_0x6a54('0x16')](_0x30f741);return _0x4f0061[_0x6a54('0x1d')](_0x6a54('0x1e'),_0x539216+'-'+_0x42304f+'/'+_0x32e505)['json'](_0x2775d3);}return null;};}function patchUpdates(_0x31fd10){return function(_0x4536e3){try{jsonpatch[_0x6a54('0x1f')](_0x4536e3,_0x31fd10,!![]);}catch(_0x214499){return BPromise[_0x6a54('0x20')](_0x214499);}return _0x4536e3[_0x6a54('0x21')]();};}function saveUpdates(_0x4b47b8,_0x175853){return function(_0x4cfc87){if(_0x4cfc87){return _0x4cfc87[_0x6a54('0x22')](_0x4b47b8)[_0x6a54('0x23')](function(_0x3fc031){return _0x3fc031;});}return null;};}function removeEntity(_0x546c5b,_0x45e54a){return function(_0x9a4169){if(_0x9a4169){return _0x9a4169[_0x6a54('0x24')]()[_0x6a54('0x23')](function(){_0x546c5b['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x3c921,_0x4509e1){return function(_0x4168ec){if(!_0x4168ec){_0x3c921['sendStatus'](0x194);}return _0x4168ec;};}function handleError(_0x14f3c2,_0x1688e4){_0x1688e4=_0x1688e4||0x1f4;return function(_0x46a967){logger[_0x6a54('0x25')](_0x46a967[_0x6a54('0x26')]);if(_0x46a967['name']){delete _0x46a967[_0x6a54('0x27')];}_0x14f3c2[_0x6a54('0x16')](_0x1688e4)['send'](_0x46a967);};}exports[_0x6a54('0x28')]=function(_0x5280c1,_0x2d8032){var _0x3b40d3={},_0x3ffa94={},_0x1e149e={'count':0x0,'rows':[]};var _0x4b6c28=_[_0x6a54('0x29')](db[_0x6a54('0x2a')]['rawAttributes'],function(_0x3221da){return{'name':_0x3221da[_0x6a54('0x2b')],'type':_0x3221da[_0x6a54('0x2c')][_0x6a54('0x2d')]};});_0x3ffa94[_0x6a54('0x2e')]=_[_0x6a54('0x29')](_0x4b6c28,'name');_0x3ffa94[_0x6a54('0x2f')]=_[_0x6a54('0x30')](_0x5280c1['query']);_0x3ffa94[_0x6a54('0x31')]=_[_0x6a54('0x32')](_0x3ffa94['model'],_0x3ffa94[_0x6a54('0x2f')]);_0x3b40d3[_0x6a54('0x33')]=_['intersection'](_0x3ffa94[_0x6a54('0x2e')],qs[_0x6a54('0x34')](_0x5280c1[_0x6a54('0x2f')][_0x6a54('0x34')]));_0x3b40d3[_0x6a54('0x33')]=_0x3b40d3[_0x6a54('0x33')][_0x6a54('0x35')]?_0x3b40d3[_0x6a54('0x33')]:_0x3ffa94[_0x6a54('0x2e')];if(!_0x5280c1[_0x6a54('0x2f')]['hasOwnProperty'](_0x6a54('0x36'))){_0x3b40d3[_0x6a54('0x1b')]=qs[_0x6a54('0x1b')](_0x5280c1[_0x6a54('0x2f')]['limit']);_0x3b40d3['offset']=qs['offset'](_0x5280c1[_0x6a54('0x2f')][_0x6a54('0x19')]);}_0x3b40d3[_0x6a54('0x37')]=qs['sort'](_0x5280c1[_0x6a54('0x2f')][_0x6a54('0x38')]);_0x3b40d3[_0x6a54('0x39')]=qs[_0x6a54('0x31')](_[_0x6a54('0x3a')](_0x5280c1[_0x6a54('0x2f')],_0x3ffa94[_0x6a54('0x31')]),_0x4b6c28);if(_0x5280c1[_0x6a54('0x2f')][_0x6a54('0x3b')]){_0x3b40d3[_0x6a54('0x39')]=_[_0x6a54('0x3c')](_0x3b40d3[_0x6a54('0x39')],{'$or':_[_0x6a54('0x29')](_0x4b6c28,function(_0x284c58){if(_0x284c58[_0x6a54('0x2c')]!==_0x6a54('0x3d')){var _0x3887a0={};_0x3887a0[_0x284c58[_0x6a54('0x27')]]={'$like':'%'+_0x5280c1[_0x6a54('0x2f')][_0x6a54('0x3b')]+'%'};return _0x3887a0;}})});}_0x3b40d3=_['merge']({},_0x3b40d3,_0x5280c1['options']);var _0x3f6576={'where':_0x3b40d3[_0x6a54('0x39')]};return db[_0x6a54('0x2a')][_0x6a54('0x1c')](_0x3f6576)['then'](function(_0x535599){_0x1e149e[_0x6a54('0x1c')]=_0x535599;if(_0x5280c1[_0x6a54('0x2f')][_0x6a54('0x3e')]){_0x3b40d3[_0x6a54('0x3f')]=[{'all':!![]}];}return db[_0x6a54('0x2a')][_0x6a54('0x40')](_0x3b40d3);})[_0x6a54('0x23')](function(_0x193126){_0x1e149e['rows']=_0x193126;return _0x1e149e;})['then'](respondWithFilteredResult(_0x2d8032,_0x3b40d3))[_0x6a54('0x41')](handleError(_0x2d8032,null));};exports['show']=function(_0xa9d131,_0x8210bb){var _0x2b1ae6={'raw':![],'where':{'id':_0xa9d131['params']['id']}},_0xe889f={};_0xe889f['model']=_[_0x6a54('0x30')](db[_0x6a54('0x2a')][_0x6a54('0x42')]);_0xe889f[_0x6a54('0x2f')]=_[_0x6a54('0x30')](_0xa9d131[_0x6a54('0x2f')]);_0xe889f['filters']=_[_0x6a54('0x32')](_0xe889f[_0x6a54('0x2e')],_0xe889f['query']);_0x2b1ae6[_0x6a54('0x33')]=_['intersection'](_0xe889f['model'],qs['fields'](_0xa9d131[_0x6a54('0x2f')][_0x6a54('0x34')]));_0x2b1ae6[_0x6a54('0x33')]=_0x2b1ae6['attributes'][_0x6a54('0x35')]?_0x2b1ae6[_0x6a54('0x33')]:_0xe889f[_0x6a54('0x2e')];if(_0xa9d131['query'][_0x6a54('0x3e')]){_0x2b1ae6['include']=[{'all':!![]}];}_0x2b1ae6=_[_0x6a54('0x3c')]({},_0x2b1ae6,_0xa9d131['options']);return db[_0x6a54('0x2a')]['find'](_0x2b1ae6)[_0x6a54('0x23')](handleEntityNotFound(_0x8210bb,null))[_0x6a54('0x23')](respondWithResult(_0x8210bb,null))[_0x6a54('0x41')](handleError(_0x8210bb,null));};exports[_0x6a54('0x43')]=function(_0x67700f,_0x38f5fe){return db[_0x6a54('0x2a')][_0x6a54('0x43')](_0x67700f[_0x6a54('0x44')],{})['then'](respondWithResult(_0x38f5fe,0xc9))[_0x6a54('0x41')](handleError(_0x38f5fe,null));};exports[_0x6a54('0x22')]=function(_0x34963e,_0x20784d){if(_0x34963e[_0x6a54('0x44')]['id']){delete _0x34963e['body']['id'];}return db[_0x6a54('0x2a')][_0x6a54('0x45')]({'where':{'id':_0x34963e[_0x6a54('0x46')]['id']}})[_0x6a54('0x23')](handleEntityNotFound(_0x20784d,null))[_0x6a54('0x23')](saveUpdates(_0x34963e['body'],null))['then'](respondWithResult(_0x20784d,null))['catch'](handleError(_0x20784d,null));};exports['destroy']=function(_0x1856dd,_0x57037e){return db[_0x6a54('0x2a')]['find']({'where':{'id':_0x1856dd[_0x6a54('0x46')]['id']}})['then'](handleEntityNotFound(_0x57037e,null))[_0x6a54('0x23')](removeEntity(_0x57037e,null))[_0x6a54('0x41')](handleError(_0x57037e,null));};exports[_0x6a54('0x47')]=function(_0x265c28,_0x18b09f,_0x402c1c){var _0x581f17={};var _0x4ec2a1={};var _0x2c7d05;var _0x491f94;return db['ZohoAccount'][_0x6a54('0x48')]({'where':{'id':_0x265c28['params']['id']}})[_0x6a54('0x23')](handleEntityNotFound(_0x18b09f,null))['then'](function(_0x36c6aa){if(_0x36c6aa){_0x2c7d05=_0x36c6aa;_0x4ec2a1[_0x6a54('0x2e')]=_[_0x6a54('0x30')](db[_0x6a54('0x49')][_0x6a54('0x42')]);_0x4ec2a1[_0x6a54('0x2f')]=_[_0x6a54('0x30')](_0x265c28[_0x6a54('0x2f')]);_0x4ec2a1['filters']=_['intersection'](_0x4ec2a1['model'],_0x4ec2a1[_0x6a54('0x2f')]);_0x581f17[_0x6a54('0x33')]=_[_0x6a54('0x32')](_0x4ec2a1[_0x6a54('0x2e')],qs[_0x6a54('0x34')](_0x265c28[_0x6a54('0x2f')][_0x6a54('0x34')]));_0x581f17[_0x6a54('0x33')]=_0x581f17[_0x6a54('0x33')]['length']?_0x581f17['attributes']:_0x4ec2a1[_0x6a54('0x2e')];_0x581f17[_0x6a54('0x37')]=qs['sort'](_0x265c28[_0x6a54('0x2f')][_0x6a54('0x38')]);_0x581f17[_0x6a54('0x39')]=qs[_0x6a54('0x31')](_[_0x6a54('0x3a')](_0x265c28[_0x6a54('0x2f')],_0x4ec2a1[_0x6a54('0x31')]));if(_0x265c28['query'][_0x6a54('0x3b')]){_0x581f17[_0x6a54('0x39')]=_['merge'](_0x581f17[_0x6a54('0x39')],{'$or':_[_0x6a54('0x29')](_0x581f17[_0x6a54('0x33')],function(_0xd1792b){var _0x1ebd85={};_0x1ebd85[_0xd1792b]={'$like':'%'+_0x265c28[_0x6a54('0x2f')][_0x6a54('0x3b')]+'%'};return _0x1ebd85;})});}_0x581f17=_[_0x6a54('0x3c')]({},_0x581f17,_0x265c28[_0x6a54('0x4a')]);return _0x2c7d05[_0x6a54('0x47')](_0x581f17);}})[_0x6a54('0x23')](function(_0x137d5a){if(_0x137d5a){_0x491f94=_0x137d5a['length'];if(!_0x265c28[_0x6a54('0x2f')][_0x6a54('0x4b')](_0x6a54('0x36'))){_0x581f17['limit']=qs[_0x6a54('0x1b')](_0x265c28['query']['limit']);_0x581f17[_0x6a54('0x19')]=qs[_0x6a54('0x19')](_0x265c28[_0x6a54('0x2f')][_0x6a54('0x19')]);}return _0x2c7d05[_0x6a54('0x47')](_0x581f17);}})['then'](function(_0x400f50){if(_0x400f50){return _0x400f50?{'count':_0x491f94,'rows':_0x400f50}:null;}})[_0x6a54('0x23')](respondWithResult(_0x18b09f,null))['catch'](handleError(_0x18b09f,null));};exports[_0x6a54('0x4c')]=function(_0x378d20,_0x4fdf46,_0x2c92b4){if(_0x378d20[_0x6a54('0x44')]['id']){delete _0x378d20[_0x6a54('0x44')]['id'];}return db[_0x6a54('0x2a')][_0x6a54('0x48')]({'where':{'id':_0x378d20['params']['id']}})[_0x6a54('0x23')](handleEntityNotFound(_0x4fdf46,null))[_0x6a54('0x23')](function(_0x9a1a5b){if(_0x9a1a5b){_0x378d20['body'][_0x6a54('0x4d')]=_0x9a1a5b['id'];_0x378d20[_0x6a54('0x44')][_0x6a54('0x4e')]=integrations[_0x6a54('0x4f')](_0x378d20['body'][_0x6a54('0x50')],_0x378d20['body'][_0x6a54('0x2c')]);_0x378d20[_0x6a54('0x44')][_0x6a54('0x51')]=integrations['getDescriptions'](_0x378d20[_0x6a54('0x44')]['channel'],_0x378d20[_0x6a54('0x44')][_0x6a54('0x2c')]);return db['ZohoConfiguration'][_0x6a54('0x43')](_0x378d20[_0x6a54('0x44')],{'include':[{'model':db[_0x6a54('0x52')],'as':_0x6a54('0x4e')},{'model':db['ZohoField'],'as':_0x6a54('0x51')}]});}return null;})[_0x6a54('0x23')](respondWithResult(_0x4fdf46,null))[_0x6a54('0x41')](handleError(_0x4fdf46,null));};function getAccessToken(_0x177745){return new Promise(function(_0x5e3e9a,_0xc494d){var _0x40ef80;switch(_0x177745[_0x6a54('0x53')]){case'US':_0x40ef80=_0x6a54('0x54');break;case'AU':_0x40ef80=_0x6a54('0x55');break;case'EU':_0x40ef80=_0x6a54('0x56');break;case'IN':_0x40ef80=_0x6a54('0x57');break;case'CN':_0x40ef80=_0x6a54('0x58');break;default:_0x40ef80=_0x6a54('0x56');break;}var _0x200fa8={'method':'POST','uri':_0x40ef80+_0x6a54('0x59'),'qs':{'refresh_token':_0x177745[_0x6a54('0x5a')],'client_id':_0x177745['clientId'],'client_secret':_0x177745[_0x6a54('0x5b')],'grant_type':_0x6a54('0x5c')},'json':!![]};return rp(_0x200fa8)['then'](function(_0x984fd1){if(_0x984fd1['access_token']){_0x5e3e9a(_0x984fd1[_0x6a54('0x5d')]);}else{_0xc494d(_0x6a54('0x5e'));}})[_0x6a54('0x41')](function(_0x35b21a){_0xc494d(_0x35b21a);});});}exports[_0x6a54('0x5f')]=function(_0x26de40,_0x23bbb5,_0x1dd57a){var _0x44e03b,_0xde6826,_0x52a671,_0x151019,_0x4811f4;return db['ZohoAccount'][_0x6a54('0x48')]({'where':{'id':_0x26de40[_0x6a54('0x46')]['id']},'attributes':['id',_0x6a54('0x60'),_0x6a54('0x53'),_0x6a54('0x61'),_0x6a54('0x5b'),_0x6a54('0x62'),'code',_0x6a54('0x5a')]})[_0x6a54('0x23')](handleEntityNotFound(_0x23bbb5,null))[_0x6a54('0x23')](function(_0x108b76){_0x4811f4=_0x108b76;_0x44e03b=_0x4811f4[_0x6a54('0x60')];_0xde6826=_0x44e03b===_0x6a54('0x63')?'eu':'com';_0x52a671=_0x4811f4['serverUrl'];var _0x55abf4=_0x52a671['slice'](-0x1);if(_0x55abf4==='/'||_0x55abf4==='\x5c'||_0x55abf4===':'){_0x52a671=_0x52a671['substring'](0x0,_0x52a671[_0x6a54('0x64')](_0x55abf4));}if(!_0x4811f4[_0x6a54('0x5a')]){throw new Error(_0x6a54('0x65'));}return getAccessToken(_0x4811f4);})[_0x6a54('0x23')](function(_0x564394){if(_0x564394){return rp({'method':_0x6a54('0x66'),'uri':util[_0x6a54('0x67')]('https://www.zohoapis.%s/crm/v2/settings/fields',_0xde6826),'qs':{'module':_0x6a54('0x68')},'headers':{'Authorization':_0x6a54('0x69')+_0x564394},'json':!![]});}})['then'](function(_0x4e251e){if(_0x4e251e){if(_0x4e251e['response']&&_0x4e251e[_0x6a54('0x6a')][_0x6a54('0x25')]){throw new Error(_0x4e251e[_0x6a54('0x6a')]['error'][_0x6a54('0x6b')]);}var _0x4ff597=[];var _0x73e381=[];var _0x30622e=[_0x6a54('0x6c'),_0x6a54('0x6d'),_0x6a54('0x6e'),_0x6a54('0x6f'),_0x6a54('0x70'),_0x6a54('0x71'),'Call_Start_Time',_0x6a54('0x72')];_0x73e381=_[_0x6a54('0x73')](_0x4e251e[_0x6a54('0x34')],function(_0x567b8d){return _0x30622e[_0x6a54('0x74')](_0x567b8d[_0x6a54('0x75')]);});for(var _0x5d07b3=0x0;_0x5d07b3<_0x73e381[_0x6a54('0x35')];_0x5d07b3++){if(_0x73e381[_0x5d07b3][_0x6a54('0x76')]===![]){_0x4ff597[_0x6a54('0x77')]({'id':_0x73e381[_0x5d07b3]['id'],'name':_0x73e381[_0x5d07b3][_0x6a54('0x78')],'custom':_0x73e381[_0x5d07b3][_0x6a54('0x79')],'options':_0x73e381[_0x5d07b3][_0x6a54('0x7a')]==='picklist'&&_0x73e381[_0x5d07b3]['pick_list_values'][_0x6a54('0x35')]>-0x1?_[_0x6a54('0x29')](_0x73e381[_0x5d07b3]['pick_list_values'],function(_0x377aef){return{'name':_0x377aef,'value':_0x377aef};}):[]});}}return{'count':_0x4ff597[_0x6a54('0x35')],'rows':_0x4ff597};}else{return{'count':0x0,'rows':[]};}})[_0x6a54('0x23')](respondWithResult(_0x23bbb5,null))['catch'](function(_0x2ca4c4){var _0x5f2f30=_0x26de40[_0x6a54('0x2f')][_0x6a54('0x7b')]?0x1f4:_0x2ca4c4['statusCode']||0x1f4;logger[_0x6a54('0x25')]('getFields,\x20%s,\x20%s,\x20%s','getFields',_0x5f2f30,JSON[_0x6a54('0x7c')](_0x2ca4c4));delete _0x2ca4c4[_0x6a54('0x27')];if(_0x5f2f30===0x191){_0x5f2f30=0x190;}_0x23bbb5['status'](_0x5f2f30)[_0x6a54('0x7d')](_0x26de40[_0x6a54('0x2f')][_0x6a54('0x7b')]?{'message':_0x6a54('0x7e'),'statusCode':_0x2ca4c4[_0x6a54('0x7f')]}:_0x2ca4c4);});};
\ No newline at end of file
+var _0xe0b5=['zone','https://accounts.zoho.com','https://accounts.zoho.com.au','POST','/oauth/v2/token','refreshToken','clientSecret','refresh_token','access_token','Unable\x20to\x20retrieve\x20the\x20access\x20token','getFields','host','clientId','serverUrl','code','slice','substring','lastIndexOf','GET','https://www.zohoapis.%s/crm/v2/settings/fields','Calls','Zoho-oauthtoken\x20','response','message','Owner','Subject','WhoId','Call_Duration','Call_Start_Time','Call_Type','remove','includes','api_name','system_mandatory','display_label','custom_field','data_type','picklist','pick_list_values','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','Wrong\x20credentials','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','ejs','fs-extra','lodash','crypto','desk.js','to-csv','papaparse','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','then','error','name','index','map','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','filter','merge','where','VIRTUAL','options','includeAll','include','ZohoAccount','findAll','rows','show','params','find','catch','create','body','update','destroy','getConfigurations','findOne','ZohoConfiguration','order','pick','Subjects','getSubjects','channel','Descriptions','getDescriptions','ZohoField'];(function(_0x3804cc,_0x5bb9f3){var _0x8cbf4a=function(_0x2214a7){while(--_0x2214a7){_0x3804cc['push'](_0x3804cc['shift']());}};_0x8cbf4a(++_0x5bb9f3);}(_0xe0b5,0x1b1));var _0x5e0b=function(_0x4d131c,_0x4e3490){_0x4d131c=_0x4d131c-0x0;var _0x3d7f06=_0xe0b5[_0x4d131c];return _0x3d7f06;};'use strict';var emlformat=require(_0x5e0b('0x0'));var rimraf=require(_0x5e0b('0x1'));var zipdir=require(_0x5e0b('0x2'));var jsonpatch=require(_0x5e0b('0x3'));var rp=require(_0x5e0b('0x4'));var moment=require(_0x5e0b('0x5'));var BPromise=require(_0x5e0b('0x6'));var Mustache=require(_0x5e0b('0x7'));var util=require(_0x5e0b('0x8'));var path=require('path');var sox=require(_0x5e0b('0x9'));var csv=require('to-csv');var ejs=require(_0x5e0b('0xa'));var fs=require('fs');var fs_extra=require(_0x5e0b('0xb'));var _=require(_0x5e0b('0xc'));var squel=require('squel');var crypto=require(_0x5e0b('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x5e0b('0xe'));var toCsv=require(_0x5e0b('0xf'));var querystring=require('querystring');var Papa=require(_0x5e0b('0x10'));var Redis=require(_0x5e0b('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x5e0b('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5e0b('0x13'));var logger=require(_0x5e0b('0x14'))(_0x5e0b('0x15'));var utils=require(_0x5e0b('0x16'));var config=require(_0x5e0b('0x17'));var licenseUtil=require(_0x5e0b('0x18'));var db=require(_0x5e0b('0x19'))['db'];var integrations=require(_0x5e0b('0x1a'));function respondWithStatusCode(_0x5e86c0,_0x2e46f5){_0x2e46f5=_0x2e46f5||0xcc;return function(_0x5f4842){if(_0x5f4842){return _0x5e86c0[_0x5e0b('0x1b')](_0x2e46f5);}return _0x5e86c0[_0x5e0b('0x1c')](_0x2e46f5)[_0x5e0b('0x1d')]();};}function respondWithResult(_0x16ed2b,_0x2719d9){_0x2719d9=_0x2719d9||0xc8;return function(_0x57e653){if(_0x57e653){return _0x16ed2b[_0x5e0b('0x1c')](_0x2719d9)[_0x5e0b('0x1e')](_0x57e653);}};}function respondWithFilteredResult(_0x52677f,_0x284e08){return function(_0x191c04){if(_0x191c04){var _0x158391=typeof _0x284e08[_0x5e0b('0x1f')]===_0x5e0b('0x20')&&typeof _0x284e08[_0x5e0b('0x21')]==='undefined';var _0x46810a=_0x191c04[_0x5e0b('0x22')];var _0x155e67=_0x158391?0x0:_0x284e08[_0x5e0b('0x1f')];var _0x25f7c0=_0x158391?_0x191c04[_0x5e0b('0x22')]:_0x284e08[_0x5e0b('0x1f')]+_0x284e08[_0x5e0b('0x21')];var _0x14e401;if(_0x25f7c0>=_0x46810a){_0x25f7c0=_0x46810a;_0x14e401=0xc8;}else{_0x14e401=0xce;}_0x52677f['status'](_0x14e401);return _0x52677f[_0x5e0b('0x23')](_0x5e0b('0x24'),_0x155e67+'-'+_0x25f7c0+'/'+_0x46810a)['json'](_0x191c04);}return null;};}function patchUpdates(_0x180155){return function(_0x45494a){try{jsonpatch[_0x5e0b('0x25')](_0x45494a,_0x180155,!![]);}catch(_0x3c52f0){return BPromise['reject'](_0x3c52f0);}return _0x45494a['save']();};}function saveUpdates(_0x2f134e,_0x477e7d){return function(_0x5dbb00){if(_0x5dbb00){return _0x5dbb00['update'](_0x2f134e)[_0x5e0b('0x26')](function(_0x54cb14){return _0x54cb14;});}return null;};}function removeEntity(_0xa9624f,_0x2836f2){return function(_0x46eff9){if(_0x46eff9){return _0x46eff9['destroy']()[_0x5e0b('0x26')](function(){_0xa9624f[_0x5e0b('0x1c')](0xcc)[_0x5e0b('0x1d')]();});}};}function handleEntityNotFound(_0x34ad25,_0xf76d30){return function(_0x33ad84){if(!_0x33ad84){_0x34ad25[_0x5e0b('0x1b')](0x194);}return _0x33ad84;};}function handleError(_0xb1b3ec,_0x1b964d){_0x1b964d=_0x1b964d||0x1f4;return function(_0x47fe4a){logger[_0x5e0b('0x27')](_0x47fe4a['stack']);if(_0x47fe4a[_0x5e0b('0x28')]){delete _0x47fe4a['name'];}_0xb1b3ec[_0x5e0b('0x1c')](_0x1b964d)['send'](_0x47fe4a);};}exports[_0x5e0b('0x29')]=function(_0x5c1691,_0x482f6d){var _0x34b6bc={},_0x4003b1={},_0x4ebe6d={'count':0x0,'rows':[]};var _0x3b41f7=_[_0x5e0b('0x2a')](db['ZohoAccount'][_0x5e0b('0x2b')],function(_0x4d4f66){return{'name':_0x4d4f66[_0x5e0b('0x2c')],'type':_0x4d4f66[_0x5e0b('0x2d')][_0x5e0b('0x2e')]};});_0x4003b1[_0x5e0b('0x2f')]=_[_0x5e0b('0x2a')](_0x3b41f7,_0x5e0b('0x28'));_0x4003b1[_0x5e0b('0x30')]=_[_0x5e0b('0x31')](_0x5c1691[_0x5e0b('0x30')]);_0x4003b1[_0x5e0b('0x32')]=_['intersection'](_0x4003b1[_0x5e0b('0x2f')],_0x4003b1[_0x5e0b('0x30')]);_0x34b6bc[_0x5e0b('0x33')]=_[_0x5e0b('0x34')](_0x4003b1['model'],qs[_0x5e0b('0x35')](_0x5c1691[_0x5e0b('0x30')][_0x5e0b('0x35')]));_0x34b6bc['attributes']=_0x34b6bc['attributes'][_0x5e0b('0x36')]?_0x34b6bc[_0x5e0b('0x33')]:_0x4003b1[_0x5e0b('0x2f')];if(!_0x5c1691[_0x5e0b('0x30')][_0x5e0b('0x37')](_0x5e0b('0x38'))){_0x34b6bc['limit']=qs[_0x5e0b('0x21')](_0x5c1691[_0x5e0b('0x30')]['limit']);_0x34b6bc[_0x5e0b('0x1f')]=qs[_0x5e0b('0x1f')](_0x5c1691[_0x5e0b('0x30')][_0x5e0b('0x1f')]);}_0x34b6bc['order']=qs['sort'](_0x5c1691['query'][_0x5e0b('0x39')]);_0x34b6bc['where']=qs[_0x5e0b('0x32')](_['pick'](_0x5c1691[_0x5e0b('0x30')],_0x4003b1[_0x5e0b('0x32')]),_0x3b41f7);if(_0x5c1691[_0x5e0b('0x30')][_0x5e0b('0x3a')]){_0x34b6bc['where']=_[_0x5e0b('0x3b')](_0x34b6bc[_0x5e0b('0x3c')],{'$or':_['map'](_0x3b41f7,function(_0x59a49b){if(_0x59a49b[_0x5e0b('0x2d')]!==_0x5e0b('0x3d')){var _0x31b7ca={};_0x31b7ca[_0x59a49b[_0x5e0b('0x28')]]={'$like':'%'+_0x5c1691[_0x5e0b('0x30')]['filter']+'%'};return _0x31b7ca;}})});}_0x34b6bc=_[_0x5e0b('0x3b')]({},_0x34b6bc,_0x5c1691[_0x5e0b('0x3e')]);var _0x259de6={'where':_0x34b6bc[_0x5e0b('0x3c')]};return db['ZohoAccount']['count'](_0x259de6)[_0x5e0b('0x26')](function(_0x4389ed){_0x4ebe6d['count']=_0x4389ed;if(_0x5c1691['query'][_0x5e0b('0x3f')]){_0x34b6bc[_0x5e0b('0x40')]=[{'all':!![]}];}return db[_0x5e0b('0x41')][_0x5e0b('0x42')](_0x34b6bc);})[_0x5e0b('0x26')](function(_0x2b085b){_0x4ebe6d[_0x5e0b('0x43')]=_0x2b085b;return _0x4ebe6d;})[_0x5e0b('0x26')](respondWithFilteredResult(_0x482f6d,_0x34b6bc))['catch'](handleError(_0x482f6d,null));};exports[_0x5e0b('0x44')]=function(_0x53971d,_0xb39f33){var _0x1d1b9e={'raw':![],'where':{'id':_0x53971d[_0x5e0b('0x45')]['id']}},_0x3c8fe2={};_0x3c8fe2[_0x5e0b('0x2f')]=_[_0x5e0b('0x31')](db[_0x5e0b('0x41')][_0x5e0b('0x2b')]);_0x3c8fe2[_0x5e0b('0x30')]=_['keys'](_0x53971d[_0x5e0b('0x30')]);_0x3c8fe2[_0x5e0b('0x32')]=_[_0x5e0b('0x34')](_0x3c8fe2['model'],_0x3c8fe2[_0x5e0b('0x30')]);_0x1d1b9e[_0x5e0b('0x33')]=_[_0x5e0b('0x34')](_0x3c8fe2[_0x5e0b('0x2f')],qs[_0x5e0b('0x35')](_0x53971d['query'][_0x5e0b('0x35')]));_0x1d1b9e[_0x5e0b('0x33')]=_0x1d1b9e[_0x5e0b('0x33')][_0x5e0b('0x36')]?_0x1d1b9e['attributes']:_0x3c8fe2[_0x5e0b('0x2f')];if(_0x53971d[_0x5e0b('0x30')]['includeAll']){_0x1d1b9e[_0x5e0b('0x40')]=[{'all':!![]}];}_0x1d1b9e=_['merge']({},_0x1d1b9e,_0x53971d['options']);return db[_0x5e0b('0x41')][_0x5e0b('0x46')](_0x1d1b9e)['then'](handleEntityNotFound(_0xb39f33,null))[_0x5e0b('0x26')](respondWithResult(_0xb39f33,null))[_0x5e0b('0x47')](handleError(_0xb39f33,null));};exports[_0x5e0b('0x48')]=function(_0x240e8c,_0xfd7440){return db[_0x5e0b('0x41')][_0x5e0b('0x48')](_0x240e8c[_0x5e0b('0x49')],{})[_0x5e0b('0x26')](respondWithResult(_0xfd7440,0xc9))[_0x5e0b('0x47')](handleError(_0xfd7440,null));};exports[_0x5e0b('0x4a')]=function(_0x3a6306,_0x3a1525){if(_0x3a6306[_0x5e0b('0x49')]['id']){delete _0x3a6306[_0x5e0b('0x49')]['id'];}return db[_0x5e0b('0x41')][_0x5e0b('0x46')]({'where':{'id':_0x3a6306[_0x5e0b('0x45')]['id']}})['then'](handleEntityNotFound(_0x3a1525,null))['then'](saveUpdates(_0x3a6306[_0x5e0b('0x49')],null))['then'](respondWithResult(_0x3a1525,null))['catch'](handleError(_0x3a1525,null));};exports[_0x5e0b('0x4b')]=function(_0x4443ed,_0xf9fe31){return db['ZohoAccount'][_0x5e0b('0x46')]({'where':{'id':_0x4443ed[_0x5e0b('0x45')]['id']}})[_0x5e0b('0x26')](handleEntityNotFound(_0xf9fe31,null))[_0x5e0b('0x26')](removeEntity(_0xf9fe31,null))[_0x5e0b('0x47')](handleError(_0xf9fe31,null));};exports[_0x5e0b('0x4c')]=function(_0x59fbc3,_0x2084f0,_0x22972b){var _0x3ba702={};var _0xde0b01={};var _0x1aceff;var _0x407ffe;return db['ZohoAccount'][_0x5e0b('0x4d')]({'where':{'id':_0x59fbc3['params']['id']}})[_0x5e0b('0x26')](handleEntityNotFound(_0x2084f0,null))[_0x5e0b('0x26')](function(_0x14a620){if(_0x14a620){_0x1aceff=_0x14a620;_0xde0b01['model']=_[_0x5e0b('0x31')](db[_0x5e0b('0x4e')]['rawAttributes']);_0xde0b01[_0x5e0b('0x30')]=_['keys'](_0x59fbc3['query']);_0xde0b01[_0x5e0b('0x32')]=_[_0x5e0b('0x34')](_0xde0b01['model'],_0xde0b01[_0x5e0b('0x30')]);_0x3ba702[_0x5e0b('0x33')]=_[_0x5e0b('0x34')](_0xde0b01[_0x5e0b('0x2f')],qs[_0x5e0b('0x35')](_0x59fbc3[_0x5e0b('0x30')][_0x5e0b('0x35')]));_0x3ba702[_0x5e0b('0x33')]=_0x3ba702[_0x5e0b('0x33')][_0x5e0b('0x36')]?_0x3ba702[_0x5e0b('0x33')]:_0xde0b01[_0x5e0b('0x2f')];_0x3ba702[_0x5e0b('0x4f')]=qs[_0x5e0b('0x39')](_0x59fbc3[_0x5e0b('0x30')]['sort']);_0x3ba702[_0x5e0b('0x3c')]=qs[_0x5e0b('0x32')](_[_0x5e0b('0x50')](_0x59fbc3[_0x5e0b('0x30')],_0xde0b01['filters']));if(_0x59fbc3[_0x5e0b('0x30')][_0x5e0b('0x3a')]){_0x3ba702[_0x5e0b('0x3c')]=_[_0x5e0b('0x3b')](_0x3ba702[_0x5e0b('0x3c')],{'$or':_[_0x5e0b('0x2a')](_0x3ba702[_0x5e0b('0x33')],function(_0x1f31bc){var _0x4f7260={};_0x4f7260[_0x1f31bc]={'$like':'%'+_0x59fbc3[_0x5e0b('0x30')][_0x5e0b('0x3a')]+'%'};return _0x4f7260;})});}_0x3ba702=_[_0x5e0b('0x3b')]({},_0x3ba702,_0x59fbc3[_0x5e0b('0x3e')]);return _0x1aceff[_0x5e0b('0x4c')](_0x3ba702);}})[_0x5e0b('0x26')](function(_0x27bb59){if(_0x27bb59){_0x407ffe=_0x27bb59['length'];if(!_0x59fbc3[_0x5e0b('0x30')][_0x5e0b('0x37')](_0x5e0b('0x38'))){_0x3ba702[_0x5e0b('0x21')]=qs[_0x5e0b('0x21')](_0x59fbc3[_0x5e0b('0x30')][_0x5e0b('0x21')]);_0x3ba702['offset']=qs[_0x5e0b('0x1f')](_0x59fbc3['query'][_0x5e0b('0x1f')]);}return _0x1aceff[_0x5e0b('0x4c')](_0x3ba702);}})[_0x5e0b('0x26')](function(_0x2bd001){if(_0x2bd001){return _0x2bd001?{'count':_0x407ffe,'rows':_0x2bd001}:null;}})[_0x5e0b('0x26')](respondWithResult(_0x2084f0,null))['catch'](handleError(_0x2084f0,null));};exports['addConfiguration']=function(_0x1037fd,_0xdfedd2,_0x4f0e78){if(_0x1037fd['body']['id']){delete _0x1037fd[_0x5e0b('0x49')]['id'];}return db[_0x5e0b('0x41')][_0x5e0b('0x4d')]({'where':{'id':_0x1037fd[_0x5e0b('0x45')]['id']}})[_0x5e0b('0x26')](handleEntityNotFound(_0xdfedd2,null))[_0x5e0b('0x26')](function(_0x4b9828){if(_0x4b9828){_0x1037fd['body']['AccountId']=_0x4b9828['id'];_0x1037fd[_0x5e0b('0x49')][_0x5e0b('0x51')]=integrations[_0x5e0b('0x52')](_0x1037fd[_0x5e0b('0x49')][_0x5e0b('0x53')],_0x1037fd[_0x5e0b('0x49')][_0x5e0b('0x2d')]);_0x1037fd['body'][_0x5e0b('0x54')]=integrations[_0x5e0b('0x55')](_0x1037fd['body'][_0x5e0b('0x53')],_0x1037fd[_0x5e0b('0x49')][_0x5e0b('0x2d')]);return db['ZohoConfiguration']['create'](_0x1037fd['body'],{'include':[{'model':db[_0x5e0b('0x56')],'as':'Subjects'},{'model':db[_0x5e0b('0x56')],'as':_0x5e0b('0x54')}]});}return null;})[_0x5e0b('0x26')](respondWithResult(_0xdfedd2,null))[_0x5e0b('0x47')](handleError(_0xdfedd2,null));};function getAccessToken(_0x46c7f9){return new Promise(function(_0x55a140,_0x500908){var _0x3f0137;switch(_0x46c7f9[_0x5e0b('0x57')]){case'US':_0x3f0137=_0x5e0b('0x58');break;case'AU':_0x3f0137=_0x5e0b('0x59');break;case'EU':_0x3f0137='https://accounts.zoho.eu';break;case'IN':_0x3f0137='https://accounts.zoho.in';break;case'CN':_0x3f0137='https://accounts.zoho.com.cn';break;default:_0x3f0137='https://accounts.zoho.eu';break;}var _0x253313={'method':_0x5e0b('0x5a'),'uri':_0x3f0137+_0x5e0b('0x5b'),'qs':{'refresh_token':_0x46c7f9[_0x5e0b('0x5c')],'client_id':_0x46c7f9['clientId'],'client_secret':_0x46c7f9[_0x5e0b('0x5d')],'grant_type':_0x5e0b('0x5e')},'json':!![]};return rp(_0x253313)[_0x5e0b('0x26')](function(_0x333cf2){if(_0x333cf2[_0x5e0b('0x5f')]){_0x55a140(_0x333cf2[_0x5e0b('0x5f')]);}else{_0x500908(_0x5e0b('0x60'));}})[_0x5e0b('0x47')](function(_0x49bcca){_0x500908(_0x49bcca);});});}exports[_0x5e0b('0x61')]=function(_0x4ddde1,_0x45440c,_0x2659fe){var _0x124cc8,_0x370f2c,_0x2ab51f,_0x52bf0d,_0x3b1242;return db[_0x5e0b('0x41')][_0x5e0b('0x4d')]({'where':{'id':_0x4ddde1[_0x5e0b('0x45')]['id']},'attributes':['id',_0x5e0b('0x62'),_0x5e0b('0x57'),_0x5e0b('0x63'),_0x5e0b('0x5d'),_0x5e0b('0x64'),_0x5e0b('0x65'),_0x5e0b('0x5c')]})[_0x5e0b('0x26')](handleEntityNotFound(_0x45440c,null))['then'](function(_0x4953b7){_0x3b1242=_0x4953b7;_0x124cc8=_0x3b1242[_0x5e0b('0x62')];_0x370f2c=_0x124cc8==='zoho.eu'?'eu':'com';_0x2ab51f=_0x3b1242[_0x5e0b('0x64')];var _0x25fcc5=_0x2ab51f[_0x5e0b('0x66')](-0x1);if(_0x25fcc5==='/'||_0x25fcc5==='\x5c'||_0x25fcc5===':'){_0x2ab51f=_0x2ab51f[_0x5e0b('0x67')](0x0,_0x2ab51f[_0x5e0b('0x68')](_0x25fcc5));}if(!_0x3b1242['refreshToken']){throw new Error('Refresh\x20Token\x20not\x20available\x20for\x20the\x20account');}return getAccessToken(_0x3b1242);})[_0x5e0b('0x26')](function(_0x2ac9e8){if(_0x2ac9e8){return rp({'method':_0x5e0b('0x69'),'uri':util['format'](_0x5e0b('0x6a'),_0x370f2c),'qs':{'module':_0x5e0b('0x6b')},'headers':{'Authorization':_0x5e0b('0x6c')+_0x2ac9e8},'json':!![]});}})[_0x5e0b('0x26')](function(_0x3af97a){if(_0x3af97a){if(_0x3af97a[_0x5e0b('0x6d')]&&_0x3af97a[_0x5e0b('0x6d')]['error']){throw new Error(_0x3af97a['response'][_0x5e0b('0x27')][_0x5e0b('0x6e')]);}var _0x44098c=[];var _0x48db3a=[];var _0x262375=[_0x5e0b('0x6f'),_0x5e0b('0x70'),'Description',_0x5e0b('0x71'),_0x5e0b('0x72'),'Call_Result',_0x5e0b('0x73'),_0x5e0b('0x74')];_0x48db3a=_[_0x5e0b('0x75')](_0x3af97a['fields'],function(_0x468144){return _0x262375[_0x5e0b('0x76')](_0x468144[_0x5e0b('0x77')]);});for(var _0x112515=0x0;_0x112515<_0x48db3a[_0x5e0b('0x36')];_0x112515++){if(_0x48db3a[_0x112515][_0x5e0b('0x78')]===![]){_0x44098c['push']({'id':_0x48db3a[_0x112515]['id'],'name':_0x48db3a[_0x112515][_0x5e0b('0x79')],'custom':_0x48db3a[_0x112515][_0x5e0b('0x7a')],'options':_0x48db3a[_0x112515][_0x5e0b('0x7b')]===_0x5e0b('0x7c')&&_0x48db3a[_0x112515][_0x5e0b('0x7d')][_0x5e0b('0x36')]>-0x1?_[_0x5e0b('0x2a')](_0x48db3a[_0x112515]['pick_list_values'],function(_0x300973){return{'name':_0x300973,'value':_0x300973};}):[]});}}return{'count':_0x44098c[_0x5e0b('0x36')],'rows':_0x44098c};}else{return{'count':0x0,'rows':[]};}})[_0x5e0b('0x26')](respondWithResult(_0x45440c,null))[_0x5e0b('0x47')](function(_0x214631){var _0x23a32d=_0x4ddde1['query'][_0x5e0b('0x7e')]?0x1f4:_0x214631[_0x5e0b('0x7f')]||0x1f4;logger[_0x5e0b('0x27')](_0x5e0b('0x80'),'getFields',_0x23a32d,JSON['stringify'](_0x214631));delete _0x214631['name'];if(_0x23a32d===0x191){_0x23a32d=0x190;}_0x45440c['status'](_0x23a32d)['send'](_0x4ddde1['query'][_0x5e0b('0x7e')]?{'message':_0x5e0b('0x81'),'statusCode':_0x214631[_0x5e0b('0x7f')]}:_0x214631);});};
\ No newline at end of file