Built motion from commit f74363e9.|2.6.34
[motion2.git] / server / api / intZohoAccount / intZohoAccount.controller.js
index b7531e8..9b32ccf 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3f97=['merge','VIRTUAL','include','findAll','rows','catch','show','params','includeAll','options','find','create','body','getConfigurations','findOne','ZohoConfiguration','sort','filter','length','hasOwnProperty','AccountId','Subjects','channel','getDescriptions','ZohoField','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.in','https://accounts.zoho.com.cn','refreshToken','clientId','refresh_token','access_token','Unable\x20to\x20retrieve\x20the\x20access\x20token','getFields','host','zone','clientSecret','serverUrl','code','zoho.eu','slice','lastIndexOf','GET','format','https://www.zohoapis.%s/crm/v2/settings/fields','Zoho-oauthtoken\x20','response','message','Owner','Subject','Description','WhoId','Call_Duration','Call_Result','Call_Start_Time','includes','api_name','system_mandatory','custom_field','data_type','pick_list_values','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','stringify','send','Wrong\x20credentials','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','util','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','update','destroy','then','error','name','map','ZohoAccount','rawAttributes','type','key','model','keys','query','filters','intersection','attributes','fields','nolimit','order','where','pick'];(function(_0x4730f3,_0x284ee0){var _0x573ccb=function(_0x1865bc){while(--_0x1865bc){_0x4730f3['push'](_0x4730f3['shift']());}};_0x573ccb(++_0x284ee0);}(_0x3f97,0xc1));var _0x73f9=function(_0x111012,_0x2d7f0c){_0x111012=_0x111012-0x0;var _0x32cadc=_0x3f97[_0x111012];return _0x32cadc;};'use strict';var emlformat=require(_0x73f9('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x73f9('0x1'));var jsonpatch=require(_0x73f9('0x2'));var rp=require(_0x73f9('0x3'));var moment=require('moment');var BPromise=require(_0x73f9('0x4'));var Mustache=require('mustache');var util=require(_0x73f9('0x5'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x73f9('0x6'));var _=require(_0x73f9('0x7'));var squel=require(_0x73f9('0x8'));var crypto=require(_0x73f9('0x9'));var jsforce=require(_0x73f9('0xa'));var deskjs=require(_0x73f9('0xb'));var toCsv=require(_0x73f9('0xc'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x73f9('0xd'));var as=require(_0x73f9('0xe'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x73f9('0xf'))(_0x73f9('0x10'));var utils=require(_0x73f9('0x11'));var config=require(_0x73f9('0x12'));var licenseUtil=require('../../config/license/util');var db=require(_0x73f9('0x13'))['db'];var integrations=require(_0x73f9('0x14'));function respondWithStatusCode(_0x5f04f9,_0x2bc7c0){_0x2bc7c0=_0x2bc7c0||0xcc;return function(_0x41dd35){if(_0x41dd35){return _0x5f04f9[_0x73f9('0x15')](_0x2bc7c0);}return _0x5f04f9[_0x73f9('0x16')](_0x2bc7c0)[_0x73f9('0x17')]();};}function respondWithResult(_0x1a7896,_0x3fcddf){_0x3fcddf=_0x3fcddf||0xc8;return function(_0x2e749d){if(_0x2e749d){return _0x1a7896['status'](_0x3fcddf)[_0x73f9('0x18')](_0x2e749d);}};}function respondWithFilteredResult(_0x57f038,_0x3c2f4d){return function(_0x5f3600){if(_0x5f3600){var _0x1eac9b=typeof _0x3c2f4d[_0x73f9('0x19')]===_0x73f9('0x1a')&&typeof _0x3c2f4d[_0x73f9('0x1b')]===_0x73f9('0x1a');var _0x1affcf=_0x5f3600[_0x73f9('0x1c')];var _0x547a1c=_0x1eac9b?0x0:_0x3c2f4d['offset'];var _0x10ae5d=_0x1eac9b?_0x5f3600[_0x73f9('0x1c')]:_0x3c2f4d[_0x73f9('0x19')]+_0x3c2f4d[_0x73f9('0x1b')];var _0x4254f8;if(_0x10ae5d>=_0x1affcf){_0x10ae5d=_0x1affcf;_0x4254f8=0xc8;}else{_0x4254f8=0xce;}_0x57f038['status'](_0x4254f8);return _0x57f038[_0x73f9('0x1d')](_0x73f9('0x1e'),_0x547a1c+'-'+_0x10ae5d+'/'+_0x1affcf)[_0x73f9('0x18')](_0x5f3600);}return null;};}function patchUpdates(_0x1c24c8){return function(_0x5ab23a){try{jsonpatch[_0x73f9('0x1f')](_0x5ab23a,_0x1c24c8,!![]);}catch(_0xe4d270){return BPromise[_0x73f9('0x20')](_0xe4d270);}return _0x5ab23a[_0x73f9('0x21')]();};}function saveUpdates(_0x8206b8,_0x581877){return function(_0x3b359d){if(_0x3b359d){return _0x3b359d[_0x73f9('0x22')](_0x8206b8)['then'](function(_0x13ff92){return _0x13ff92;});}return null;};}function removeEntity(_0x363456,_0x231979){return function(_0x59c230){if(_0x59c230){return _0x59c230[_0x73f9('0x23')]()[_0x73f9('0x24')](function(){_0x363456['status'](0xcc)[_0x73f9('0x17')]();});}};}function handleEntityNotFound(_0x5e38c2,_0x253657){return function(_0x356a18){if(!_0x356a18){_0x5e38c2['sendStatus'](0x194);}return _0x356a18;};}function handleError(_0x5e25d0,_0x1e431f){_0x1e431f=_0x1e431f||0x1f4;return function(_0x4cc66b){logger[_0x73f9('0x25')](_0x4cc66b['stack']);if(_0x4cc66b[_0x73f9('0x26')]){delete _0x4cc66b[_0x73f9('0x26')];}_0x5e25d0['status'](_0x1e431f)['send'](_0x4cc66b);};}exports['index']=function(_0x3c3047,_0x3700ab){var _0x4f12b4={},_0x2f4b91={},_0x19c315={'count':0x0,'rows':[]};var _0x93c7fb=_[_0x73f9('0x27')](db[_0x73f9('0x28')][_0x73f9('0x29')],function(_0x1d36e1){return{'name':_0x1d36e1['fieldName'],'type':_0x1d36e1[_0x73f9('0x2a')][_0x73f9('0x2b')]};});_0x2f4b91[_0x73f9('0x2c')]=_[_0x73f9('0x27')](_0x93c7fb,_0x73f9('0x26'));_0x2f4b91['query']=_[_0x73f9('0x2d')](_0x3c3047[_0x73f9('0x2e')]);_0x2f4b91[_0x73f9('0x2f')]=_[_0x73f9('0x30')](_0x2f4b91[_0x73f9('0x2c')],_0x2f4b91[_0x73f9('0x2e')]);_0x4f12b4[_0x73f9('0x31')]=_[_0x73f9('0x30')](_0x2f4b91[_0x73f9('0x2c')],qs[_0x73f9('0x32')](_0x3c3047[_0x73f9('0x2e')][_0x73f9('0x32')]));_0x4f12b4['attributes']=_0x4f12b4[_0x73f9('0x31')]['length']?_0x4f12b4[_0x73f9('0x31')]:_0x2f4b91[_0x73f9('0x2c')];if(!_0x3c3047[_0x73f9('0x2e')]['hasOwnProperty'](_0x73f9('0x33'))){_0x4f12b4[_0x73f9('0x1b')]=qs[_0x73f9('0x1b')](_0x3c3047[_0x73f9('0x2e')]['limit']);_0x4f12b4[_0x73f9('0x19')]=qs[_0x73f9('0x19')](_0x3c3047['query']['offset']);}_0x4f12b4[_0x73f9('0x34')]=qs['sort'](_0x3c3047[_0x73f9('0x2e')]['sort']);_0x4f12b4[_0x73f9('0x35')]=qs['filters'](_[_0x73f9('0x36')](_0x3c3047[_0x73f9('0x2e')],_0x2f4b91[_0x73f9('0x2f')]),_0x93c7fb);if(_0x3c3047[_0x73f9('0x2e')]['filter']){_0x4f12b4[_0x73f9('0x35')]=_[_0x73f9('0x37')](_0x4f12b4[_0x73f9('0x35')],{'$or':_['map'](_0x93c7fb,function(_0x233b04){if(_0x233b04[_0x73f9('0x2a')]!==_0x73f9('0x38')){var _0x56089c={};_0x56089c[_0x233b04['name']]={'$like':'%'+_0x3c3047[_0x73f9('0x2e')]['filter']+'%'};return _0x56089c;}})});}_0x4f12b4=_[_0x73f9('0x37')]({},_0x4f12b4,_0x3c3047['options']);var _0x83a45f={'where':_0x4f12b4[_0x73f9('0x35')]};return db['ZohoAccount']['count'](_0x83a45f)[_0x73f9('0x24')](function(_0x3d93ac){_0x19c315['count']=_0x3d93ac;if(_0x3c3047[_0x73f9('0x2e')]['includeAll']){_0x4f12b4[_0x73f9('0x39')]=[{'all':!![]}];}return db['ZohoAccount'][_0x73f9('0x3a')](_0x4f12b4);})['then'](function(_0x9c816d){_0x19c315[_0x73f9('0x3b')]=_0x9c816d;return _0x19c315;})['then'](respondWithFilteredResult(_0x3700ab,_0x4f12b4))[_0x73f9('0x3c')](handleError(_0x3700ab,null));};exports[_0x73f9('0x3d')]=function(_0x4271af,_0x255e0e){var _0x3fe8a0={'raw':![],'where':{'id':_0x4271af[_0x73f9('0x3e')]['id']}},_0x154e05={};_0x154e05[_0x73f9('0x2c')]=_['keys'](db['ZohoAccount']['rawAttributes']);_0x154e05[_0x73f9('0x2e')]=_[_0x73f9('0x2d')](_0x4271af[_0x73f9('0x2e')]);_0x154e05[_0x73f9('0x2f')]=_[_0x73f9('0x30')](_0x154e05[_0x73f9('0x2c')],_0x154e05[_0x73f9('0x2e')]);_0x3fe8a0[_0x73f9('0x31')]=_['intersection'](_0x154e05[_0x73f9('0x2c')],qs[_0x73f9('0x32')](_0x4271af[_0x73f9('0x2e')][_0x73f9('0x32')]));_0x3fe8a0[_0x73f9('0x31')]=_0x3fe8a0[_0x73f9('0x31')]['length']?_0x3fe8a0[_0x73f9('0x31')]:_0x154e05[_0x73f9('0x2c')];if(_0x4271af[_0x73f9('0x2e')][_0x73f9('0x3f')]){_0x3fe8a0['include']=[{'all':!![]}];}_0x3fe8a0=_['merge']({},_0x3fe8a0,_0x4271af[_0x73f9('0x40')]);return db[_0x73f9('0x28')][_0x73f9('0x41')](_0x3fe8a0)[_0x73f9('0x24')](handleEntityNotFound(_0x255e0e,null))[_0x73f9('0x24')](respondWithResult(_0x255e0e,null))[_0x73f9('0x3c')](handleError(_0x255e0e,null));};exports[_0x73f9('0x42')]=function(_0x4d5146,_0x480d5d){return db['ZohoAccount'][_0x73f9('0x42')](_0x4d5146['body'],{})[_0x73f9('0x24')](respondWithResult(_0x480d5d,0xc9))[_0x73f9('0x3c')](handleError(_0x480d5d,null));};exports['update']=function(_0xce5a8d,_0xc423){if(_0xce5a8d[_0x73f9('0x43')]['id']){delete _0xce5a8d[_0x73f9('0x43')]['id'];}return db['ZohoAccount'][_0x73f9('0x41')]({'where':{'id':_0xce5a8d[_0x73f9('0x3e')]['id']}})[_0x73f9('0x24')](handleEntityNotFound(_0xc423,null))[_0x73f9('0x24')](saveUpdates(_0xce5a8d['body'],null))[_0x73f9('0x24')](respondWithResult(_0xc423,null))['catch'](handleError(_0xc423,null));};exports['destroy']=function(_0x349c0a,_0x50d9da){return db[_0x73f9('0x28')][_0x73f9('0x41')]({'where':{'id':_0x349c0a[_0x73f9('0x3e')]['id']}})['then'](handleEntityNotFound(_0x50d9da,null))['then'](removeEntity(_0x50d9da,null))[_0x73f9('0x3c')](handleError(_0x50d9da,null));};exports[_0x73f9('0x44')]=function(_0x4a6c89,_0x4111f6,_0x28533b){var _0x71c1d0={};var _0x1ab3fa={};var _0x178f7b;var _0x4d0a73;return db['ZohoAccount'][_0x73f9('0x45')]({'where':{'id':_0x4a6c89[_0x73f9('0x3e')]['id']}})[_0x73f9('0x24')](handleEntityNotFound(_0x4111f6,null))[_0x73f9('0x24')](function(_0x29a539){if(_0x29a539){_0x178f7b=_0x29a539;_0x1ab3fa[_0x73f9('0x2c')]=_[_0x73f9('0x2d')](db[_0x73f9('0x46')][_0x73f9('0x29')]);_0x1ab3fa['query']=_[_0x73f9('0x2d')](_0x4a6c89[_0x73f9('0x2e')]);_0x1ab3fa[_0x73f9('0x2f')]=_['intersection'](_0x1ab3fa[_0x73f9('0x2c')],_0x1ab3fa[_0x73f9('0x2e')]);_0x71c1d0[_0x73f9('0x31')]=_['intersection'](_0x1ab3fa[_0x73f9('0x2c')],qs[_0x73f9('0x32')](_0x4a6c89[_0x73f9('0x2e')]['fields']));_0x71c1d0[_0x73f9('0x31')]=_0x71c1d0['attributes']['length']?_0x71c1d0['attributes']:_0x1ab3fa[_0x73f9('0x2c')];_0x71c1d0['order']=qs['sort'](_0x4a6c89['query'][_0x73f9('0x47')]);_0x71c1d0[_0x73f9('0x35')]=qs[_0x73f9('0x2f')](_[_0x73f9('0x36')](_0x4a6c89['query'],_0x1ab3fa[_0x73f9('0x2f')]));if(_0x4a6c89[_0x73f9('0x2e')][_0x73f9('0x48')]){_0x71c1d0['where']=_[_0x73f9('0x37')](_0x71c1d0[_0x73f9('0x35')],{'$or':_['map'](_0x71c1d0[_0x73f9('0x31')],function(_0x3d7bd4){var _0x27465a={};_0x27465a[_0x3d7bd4]={'$like':'%'+_0x4a6c89['query'][_0x73f9('0x48')]+'%'};return _0x27465a;})});}_0x71c1d0=_[_0x73f9('0x37')]({},_0x71c1d0,_0x4a6c89[_0x73f9('0x40')]);return _0x178f7b['getConfigurations'](_0x71c1d0);}})[_0x73f9('0x24')](function(_0x1cbf66){if(_0x1cbf66){_0x4d0a73=_0x1cbf66[_0x73f9('0x49')];if(!_0x4a6c89[_0x73f9('0x2e')][_0x73f9('0x4a')](_0x73f9('0x33'))){_0x71c1d0[_0x73f9('0x1b')]=qs[_0x73f9('0x1b')](_0x4a6c89[_0x73f9('0x2e')]['limit']);_0x71c1d0[_0x73f9('0x19')]=qs['offset'](_0x4a6c89[_0x73f9('0x2e')]['offset']);}return _0x178f7b[_0x73f9('0x44')](_0x71c1d0);}})[_0x73f9('0x24')](function(_0x497f0d){if(_0x497f0d){return _0x497f0d?{'count':_0x4d0a73,'rows':_0x497f0d}:null;}})[_0x73f9('0x24')](respondWithResult(_0x4111f6,null))[_0x73f9('0x3c')](handleError(_0x4111f6,null));};exports['addConfiguration']=function(_0x59384d,_0x5aa771,_0x10f810){if(_0x59384d[_0x73f9('0x43')]['id']){delete _0x59384d['body']['id'];}return db['ZohoAccount'][_0x73f9('0x45')]({'where':{'id':_0x59384d[_0x73f9('0x3e')]['id']}})[_0x73f9('0x24')](handleEntityNotFound(_0x5aa771,null))[_0x73f9('0x24')](function(_0x58f7fc){if(_0x58f7fc){_0x59384d['body'][_0x73f9('0x4b')]=_0x58f7fc['id'];_0x59384d['body'][_0x73f9('0x4c')]=integrations['getSubjects'](_0x59384d[_0x73f9('0x43')][_0x73f9('0x4d')],_0x59384d[_0x73f9('0x43')]['type']);_0x59384d[_0x73f9('0x43')]['Descriptions']=integrations[_0x73f9('0x4e')](_0x59384d[_0x73f9('0x43')][_0x73f9('0x4d')],_0x59384d[_0x73f9('0x43')][_0x73f9('0x2a')]);return db[_0x73f9('0x46')][_0x73f9('0x42')](_0x59384d['body'],{'include':[{'model':db[_0x73f9('0x4f')],'as':'Subjects'},{'model':db[_0x73f9('0x4f')],'as':'Descriptions'}]});}return null;})[_0x73f9('0x24')](respondWithResult(_0x5aa771,null))['catch'](handleError(_0x5aa771,null));};function getAccessToken(_0x4f9699){return new Promise(function(_0x305f4e,_0x1338a0){var _0x4c648d;switch(_0x4f9699['zone']){case'US':_0x4c648d=_0x73f9('0x50');break;case'AU':_0x4c648d=_0x73f9('0x51');break;case'EU':_0x4c648d=_0x73f9('0x52');break;case'IN':_0x4c648d=_0x73f9('0x53');break;case'CN':_0x4c648d=_0x73f9('0x54');break;default:_0x4c648d=_0x73f9('0x52');break;}var _0x5dd925={'method':'POST','uri':_0x4c648d+'/oauth/v2/token','qs':{'refresh_token':_0x4f9699[_0x73f9('0x55')],'client_id':_0x4f9699[_0x73f9('0x56')],'client_secret':_0x4f9699['clientSecret'],'grant_type':_0x73f9('0x57')},'json':!![]};return rp(_0x5dd925)[_0x73f9('0x24')](function(_0x42f53d){if(_0x42f53d[_0x73f9('0x58')]){_0x305f4e(_0x42f53d[_0x73f9('0x58')]);}else{_0x1338a0(_0x73f9('0x59'));}})['catch'](function(_0x2c9b57){_0x1338a0(_0x2c9b57);});});}exports[_0x73f9('0x5a')]=function(_0x5ce967,_0x21e377,_0x494a6e){var _0x2d96ea,_0x4ddee4,_0x18bf1a,_0x47e27d,_0x5adebb;return db[_0x73f9('0x28')][_0x73f9('0x45')]({'where':{'id':_0x5ce967[_0x73f9('0x3e')]['id']},'attributes':['id',_0x73f9('0x5b'),_0x73f9('0x5c'),_0x73f9('0x56'),_0x73f9('0x5d'),_0x73f9('0x5e'),_0x73f9('0x5f'),_0x73f9('0x55')]})[_0x73f9('0x24')](handleEntityNotFound(_0x21e377,null))[_0x73f9('0x24')](function(_0x281dad){_0x5adebb=_0x281dad;_0x2d96ea=_0x5adebb[_0x73f9('0x5b')];_0x4ddee4=_0x2d96ea===_0x73f9('0x60')?'eu':'com';_0x18bf1a=_0x5adebb[_0x73f9('0x5e')];var _0x153606=_0x18bf1a[_0x73f9('0x61')](-0x1);if(_0x153606==='/'||_0x153606==='\x5c'||_0x153606===':'){_0x18bf1a=_0x18bf1a['substring'](0x0,_0x18bf1a[_0x73f9('0x62')](_0x153606));}if(!_0x5adebb[_0x73f9('0x55')]){throw new Error('Refresh\x20Token\x20not\x20available\x20for\x20the\x20account');}return getAccessToken(_0x5adebb);})['then'](function(_0x3a26d1){if(_0x3a26d1){return rp({'method':_0x73f9('0x63'),'uri':util[_0x73f9('0x64')](_0x73f9('0x65'),_0x4ddee4),'qs':{'module':'Calls'},'headers':{'Authorization':_0x73f9('0x66')+_0x3a26d1},'json':!![]});}})[_0x73f9('0x24')](function(_0x8d7501){if(_0x8d7501){if(_0x8d7501['response']&&_0x8d7501[_0x73f9('0x67')][_0x73f9('0x25')]){throw new Error(_0x8d7501[_0x73f9('0x67')]['error'][_0x73f9('0x68')]);}var _0x121e16=[];var _0x44a278=[];var _0x3c3d0f=[_0x73f9('0x69'),_0x73f9('0x6a'),_0x73f9('0x6b'),_0x73f9('0x6c'),_0x73f9('0x6d'),_0x73f9('0x6e'),_0x73f9('0x6f'),'Call_Type'];_0x44a278=_['remove'](_0x8d7501['fields'],function(_0x5c5fe0){return _0x3c3d0f[_0x73f9('0x70')](_0x5c5fe0[_0x73f9('0x71')]);});for(var _0x3f830f=0x0;_0x3f830f<_0x44a278['length'];_0x3f830f++){if(_0x44a278[_0x3f830f][_0x73f9('0x72')]===![]){_0x121e16['push']({'id':_0x44a278[_0x3f830f]['id'],'name':_0x44a278[_0x3f830f]['display_label'],'custom':_0x44a278[_0x3f830f][_0x73f9('0x73')],'options':_0x44a278[_0x3f830f][_0x73f9('0x74')]==='picklist'&&_0x44a278[_0x3f830f]['pick_list_values']['length']>-0x1?_['map'](_0x44a278[_0x3f830f][_0x73f9('0x75')],function(_0x2221da){return{'name':_0x2221da,'value':_0x2221da};}):[]});}}return{'count':_0x121e16[_0x73f9('0x49')],'rows':_0x121e16};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithResult(_0x21e377,null))[_0x73f9('0x3c')](function(_0x2d025e){var _0x3b37bd=_0x5ce967[_0x73f9('0x2e')][_0x73f9('0x76')]?0x1f4:_0x2d025e[_0x73f9('0x77')]||0x1f4;logger[_0x73f9('0x25')](_0x73f9('0x78'),_0x73f9('0x5a'),_0x3b37bd,JSON[_0x73f9('0x79')](_0x2d025e));delete _0x2d025e[_0x73f9('0x26')];if(_0x3b37bd===0x191){_0x3b37bd=0x190;}_0x21e377[_0x73f9('0x16')](_0x3b37bd)[_0x73f9('0x7a')](_0x5ce967['query'][_0x73f9('0x76')]?{'message':_0x73f9('0x7b'),'statusCode':_0x2d025e[_0x73f9('0x77')]}:_0x2d025e);});};
\ No newline at end of file
+var _0x7c7b=['api_name','system_mandatory','push','display_label','custom_field','data_type','picklist','pick_list_values','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','getFields','stringify','Wrong\x20credentials','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','sox','fs-extra','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','../../components/integrations/configuration','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','rawAttributes','type','key','map','query','keys','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter','where','merge','options','ZohoAccount','includeAll','include','findAll','rows','show','find','catch','create','body','params','getConfigurations','findOne','ZohoConfiguration','AccountId','Subjects','channel','getDescriptions','ZohoField','Descriptions','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.eu','https://accounts.zoho.in','https://accounts.zoho.com.cn','POST','/oauth/v2/token','refreshToken','clientId','clientSecret','refresh_token','access_token','Unable\x20to\x20retrieve\x20the\x20access\x20token','host','serverUrl','com','slice','substring','Refresh\x20Token\x20not\x20available\x20for\x20the\x20account','https://www.zohoapis.%s/crm/v2/settings/fields','Zoho-oauthtoken\x20','response','message','Owner','Description','WhoId','Call_Result','Call_Type','remove','includes'];(function(_0x5cfa08,_0x1874cd){var _0x3b7727=function(_0x14760e){while(--_0x14760e){_0x5cfa08['push'](_0x5cfa08['shift']());}};_0x3b7727(++_0x1874cd);}(_0x7c7b,0x10e));var _0xb7c7=function(_0x3d784f,_0x100ef1){_0x3d784f=_0x3d784f-0x0;var _0x32340e=_0x7c7b[_0x3d784f];return _0x32340e;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xb7c7('0x0'));var jsonpatch=require(_0xb7c7('0x1'));var rp=require(_0xb7c7('0x2'));var moment=require(_0xb7c7('0x3'));var BPromise=require(_0xb7c7('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0xb7c7('0x5'));var sox=require(_0xb7c7('0x6'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xb7c7('0x7'));var _=require('lodash');var squel=require(_0xb7c7('0x8'));var crypto=require(_0xb7c7('0x9'));var jsforce=require(_0xb7c7('0xa'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xb7c7('0xb'));var Papa=require(_0xb7c7('0xc'));var Redis=require(_0xb7c7('0xd'));var authService=require('../../components/auth/service');var qs=require(_0xb7c7('0xe'));var as=require(_0xb7c7('0xf'));var hardwareService=require(_0xb7c7('0x10'));var logger=require(_0xb7c7('0x11'))(_0xb7c7('0x12'));var utils=require(_0xb7c7('0x13'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xb7c7('0x14'))['db'];var integrations=require(_0xb7c7('0x15'));function respondWithStatusCode(_0xdf4b5a,_0x416a3d){_0x416a3d=_0x416a3d||0xcc;return function(_0x387247){if(_0x387247){return _0xdf4b5a[_0xb7c7('0x16')](_0x416a3d);}return _0xdf4b5a[_0xb7c7('0x17')](_0x416a3d)[_0xb7c7('0x18')]();};}function respondWithResult(_0x10de68,_0x5469c5){_0x5469c5=_0x5469c5||0xc8;return function(_0x463e8e){if(_0x463e8e){return _0x10de68[_0xb7c7('0x17')](_0x5469c5)[_0xb7c7('0x19')](_0x463e8e);}};}function respondWithFilteredResult(_0x52b017,_0x6e013c){return function(_0x18875e){if(_0x18875e){var _0x40400d=typeof _0x6e013c[_0xb7c7('0x1a')]==='undefined'&&typeof _0x6e013c[_0xb7c7('0x1b')]===_0xb7c7('0x1c');var _0x1477e6=_0x18875e['count'];var _0x536d21=_0x40400d?0x0:_0x6e013c['offset'];var _0x3b4943=_0x40400d?_0x18875e[_0xb7c7('0x1d')]:_0x6e013c['offset']+_0x6e013c['limit'];var _0x2e234e;if(_0x3b4943>=_0x1477e6){_0x3b4943=_0x1477e6;_0x2e234e=0xc8;}else{_0x2e234e=0xce;}_0x52b017[_0xb7c7('0x17')](_0x2e234e);return _0x52b017[_0xb7c7('0x1e')](_0xb7c7('0x1f'),_0x536d21+'-'+_0x3b4943+'/'+_0x1477e6)['json'](_0x18875e);}return null;};}function patchUpdates(_0x65018c){return function(_0x43b4fe){try{jsonpatch[_0xb7c7('0x20')](_0x43b4fe,_0x65018c,!![]);}catch(_0x55eec3){return BPromise[_0xb7c7('0x21')](_0x55eec3);}return _0x43b4fe[_0xb7c7('0x22')]();};}function saveUpdates(_0x4fab17,_0x5541fc){return function(_0x29891a){if(_0x29891a){return _0x29891a[_0xb7c7('0x23')](_0x4fab17)[_0xb7c7('0x24')](function(_0x149c24){return _0x149c24;});}return null;};}function removeEntity(_0x4911cf,_0x422914){return function(_0x44b163){if(_0x44b163){return _0x44b163[_0xb7c7('0x25')]()[_0xb7c7('0x24')](function(){_0x4911cf['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0xeeb6bc,_0x31126e){return function(_0x472ff4){if(!_0x472ff4){_0xeeb6bc[_0xb7c7('0x16')](0x194);}return _0x472ff4;};}function handleError(_0x56632e,_0x3f5453){_0x3f5453=_0x3f5453||0x1f4;return function(_0x3c9153){logger[_0xb7c7('0x26')](_0x3c9153[_0xb7c7('0x27')]);if(_0x3c9153[_0xb7c7('0x28')]){delete _0x3c9153['name'];}_0x56632e[_0xb7c7('0x17')](_0x3f5453)[_0xb7c7('0x29')](_0x3c9153);};}exports['index']=function(_0xb26934,_0x44eaec){var _0x1c4187={},_0x51d9db={},_0x562158={'count':0x0,'rows':[]};var _0x236831=_['map'](db['ZohoAccount'][_0xb7c7('0x2a')],function(_0x444a39){return{'name':_0x444a39['fieldName'],'type':_0x444a39[_0xb7c7('0x2b')][_0xb7c7('0x2c')]};});_0x51d9db['model']=_[_0xb7c7('0x2d')](_0x236831,_0xb7c7('0x28'));_0x51d9db[_0xb7c7('0x2e')]=_[_0xb7c7('0x2f')](_0xb26934[_0xb7c7('0x2e')]);_0x51d9db['filters']=_[_0xb7c7('0x30')](_0x51d9db[_0xb7c7('0x31')],_0x51d9db[_0xb7c7('0x2e')]);_0x1c4187[_0xb7c7('0x32')]=_[_0xb7c7('0x30')](_0x51d9db[_0xb7c7('0x31')],qs[_0xb7c7('0x33')](_0xb26934[_0xb7c7('0x2e')]['fields']));_0x1c4187[_0xb7c7('0x32')]=_0x1c4187[_0xb7c7('0x32')][_0xb7c7('0x34')]?_0x1c4187[_0xb7c7('0x32')]:_0x51d9db[_0xb7c7('0x31')];if(!_0xb26934[_0xb7c7('0x2e')][_0xb7c7('0x35')](_0xb7c7('0x36'))){_0x1c4187[_0xb7c7('0x1b')]=qs[_0xb7c7('0x1b')](_0xb26934[_0xb7c7('0x2e')][_0xb7c7('0x1b')]);_0x1c4187['offset']=qs['offset'](_0xb26934[_0xb7c7('0x2e')][_0xb7c7('0x1a')]);}_0x1c4187[_0xb7c7('0x37')]=qs['sort'](_0xb26934[_0xb7c7('0x2e')][_0xb7c7('0x38')]);_0x1c4187['where']=qs[_0xb7c7('0x39')](_[_0xb7c7('0x3a')](_0xb26934[_0xb7c7('0x2e')],_0x51d9db[_0xb7c7('0x39')]),_0x236831);if(_0xb26934['query'][_0xb7c7('0x3b')]){_0x1c4187[_0xb7c7('0x3c')]=_[_0xb7c7('0x3d')](_0x1c4187['where'],{'$or':_[_0xb7c7('0x2d')](_0x236831,function(_0x30a10e){if(_0x30a10e['type']!=='VIRTUAL'){var _0xa3c087={};_0xa3c087[_0x30a10e['name']]={'$like':'%'+_0xb26934[_0xb7c7('0x2e')][_0xb7c7('0x3b')]+'%'};return _0xa3c087;}})});}_0x1c4187=_[_0xb7c7('0x3d')]({},_0x1c4187,_0xb26934[_0xb7c7('0x3e')]);var _0x2f4b9f={'where':_0x1c4187['where']};return db[_0xb7c7('0x3f')][_0xb7c7('0x1d')](_0x2f4b9f)[_0xb7c7('0x24')](function(_0x34a182){_0x562158[_0xb7c7('0x1d')]=_0x34a182;if(_0xb26934[_0xb7c7('0x2e')][_0xb7c7('0x40')]){_0x1c4187[_0xb7c7('0x41')]=[{'all':!![]}];}return db[_0xb7c7('0x3f')][_0xb7c7('0x42')](_0x1c4187);})[_0xb7c7('0x24')](function(_0x324a2a){_0x562158[_0xb7c7('0x43')]=_0x324a2a;return _0x562158;})['then'](respondWithFilteredResult(_0x44eaec,_0x1c4187))['catch'](handleError(_0x44eaec,null));};exports[_0xb7c7('0x44')]=function(_0x3f3f76,_0x108a17){var _0xc3d427={'raw':![],'where':{'id':_0x3f3f76['params']['id']}},_0xa623eb={};_0xa623eb[_0xb7c7('0x31')]=_[_0xb7c7('0x2f')](db[_0xb7c7('0x3f')][_0xb7c7('0x2a')]);_0xa623eb[_0xb7c7('0x2e')]=_[_0xb7c7('0x2f')](_0x3f3f76[_0xb7c7('0x2e')]);_0xa623eb[_0xb7c7('0x39')]=_[_0xb7c7('0x30')](_0xa623eb[_0xb7c7('0x31')],_0xa623eb['query']);_0xc3d427['attributes']=_[_0xb7c7('0x30')](_0xa623eb[_0xb7c7('0x31')],qs[_0xb7c7('0x33')](_0x3f3f76['query'][_0xb7c7('0x33')]));_0xc3d427['attributes']=_0xc3d427[_0xb7c7('0x32')][_0xb7c7('0x34')]?_0xc3d427[_0xb7c7('0x32')]:_0xa623eb[_0xb7c7('0x31')];if(_0x3f3f76['query'][_0xb7c7('0x40')]){_0xc3d427[_0xb7c7('0x41')]=[{'all':!![]}];}_0xc3d427=_[_0xb7c7('0x3d')]({},_0xc3d427,_0x3f3f76[_0xb7c7('0x3e')]);return db[_0xb7c7('0x3f')][_0xb7c7('0x45')](_0xc3d427)['then'](handleEntityNotFound(_0x108a17,null))[_0xb7c7('0x24')](respondWithResult(_0x108a17,null))[_0xb7c7('0x46')](handleError(_0x108a17,null));};exports[_0xb7c7('0x47')]=function(_0x38f5d3,_0x91fb09){return db[_0xb7c7('0x3f')]['create'](_0x38f5d3[_0xb7c7('0x48')],{})[_0xb7c7('0x24')](respondWithResult(_0x91fb09,0xc9))['catch'](handleError(_0x91fb09,null));};exports[_0xb7c7('0x23')]=function(_0x84c243,_0xe84dc8){if(_0x84c243[_0xb7c7('0x48')]['id']){delete _0x84c243[_0xb7c7('0x48')]['id'];}return db[_0xb7c7('0x3f')][_0xb7c7('0x45')]({'where':{'id':_0x84c243[_0xb7c7('0x49')]['id']}})[_0xb7c7('0x24')](handleEntityNotFound(_0xe84dc8,null))[_0xb7c7('0x24')](saveUpdates(_0x84c243[_0xb7c7('0x48')],null))[_0xb7c7('0x24')](respondWithResult(_0xe84dc8,null))[_0xb7c7('0x46')](handleError(_0xe84dc8,null));};exports[_0xb7c7('0x25')]=function(_0x571e21,_0x2bfe5b){return db[_0xb7c7('0x3f')][_0xb7c7('0x45')]({'where':{'id':_0x571e21[_0xb7c7('0x49')]['id']}})[_0xb7c7('0x24')](handleEntityNotFound(_0x2bfe5b,null))['then'](removeEntity(_0x2bfe5b,null))[_0xb7c7('0x46')](handleError(_0x2bfe5b,null));};exports[_0xb7c7('0x4a')]=function(_0x21e558,_0x6cf5b5,_0x4afde6){var _0x5215f9={};var _0x3798e5={};var _0x25561b;var _0x3bb6c1;return db[_0xb7c7('0x3f')][_0xb7c7('0x4b')]({'where':{'id':_0x21e558[_0xb7c7('0x49')]['id']}})[_0xb7c7('0x24')](handleEntityNotFound(_0x6cf5b5,null))[_0xb7c7('0x24')](function(_0x6e46){if(_0x6e46){_0x25561b=_0x6e46;_0x3798e5[_0xb7c7('0x31')]=_['keys'](db[_0xb7c7('0x4c')][_0xb7c7('0x2a')]);_0x3798e5[_0xb7c7('0x2e')]=_['keys'](_0x21e558[_0xb7c7('0x2e')]);_0x3798e5[_0xb7c7('0x39')]=_[_0xb7c7('0x30')](_0x3798e5[_0xb7c7('0x31')],_0x3798e5[_0xb7c7('0x2e')]);_0x5215f9['attributes']=_[_0xb7c7('0x30')](_0x3798e5[_0xb7c7('0x31')],qs['fields'](_0x21e558[_0xb7c7('0x2e')]['fields']));_0x5215f9[_0xb7c7('0x32')]=_0x5215f9[_0xb7c7('0x32')]['length']?_0x5215f9[_0xb7c7('0x32')]:_0x3798e5[_0xb7c7('0x31')];_0x5215f9[_0xb7c7('0x37')]=qs['sort'](_0x21e558[_0xb7c7('0x2e')]['sort']);_0x5215f9[_0xb7c7('0x3c')]=qs[_0xb7c7('0x39')](_[_0xb7c7('0x3a')](_0x21e558[_0xb7c7('0x2e')],_0x3798e5[_0xb7c7('0x39')]));if(_0x21e558['query'][_0xb7c7('0x3b')]){_0x5215f9[_0xb7c7('0x3c')]=_['merge'](_0x5215f9[_0xb7c7('0x3c')],{'$or':_[_0xb7c7('0x2d')](_0x5215f9['attributes'],function(_0x518a86){var _0x3e786a={};_0x3e786a[_0x518a86]={'$like':'%'+_0x21e558[_0xb7c7('0x2e')][_0xb7c7('0x3b')]+'%'};return _0x3e786a;})});}_0x5215f9=_[_0xb7c7('0x3d')]({},_0x5215f9,_0x21e558['options']);return _0x25561b[_0xb7c7('0x4a')](_0x5215f9);}})[_0xb7c7('0x24')](function(_0x33658b){if(_0x33658b){_0x3bb6c1=_0x33658b[_0xb7c7('0x34')];if(!_0x21e558[_0xb7c7('0x2e')][_0xb7c7('0x35')](_0xb7c7('0x36'))){_0x5215f9[_0xb7c7('0x1b')]=qs[_0xb7c7('0x1b')](_0x21e558[_0xb7c7('0x2e')][_0xb7c7('0x1b')]);_0x5215f9[_0xb7c7('0x1a')]=qs[_0xb7c7('0x1a')](_0x21e558[_0xb7c7('0x2e')]['offset']);}return _0x25561b[_0xb7c7('0x4a')](_0x5215f9);}})[_0xb7c7('0x24')](function(_0x958499){if(_0x958499){return _0x958499?{'count':_0x3bb6c1,'rows':_0x958499}:null;}})[_0xb7c7('0x24')](respondWithResult(_0x6cf5b5,null))['catch'](handleError(_0x6cf5b5,null));};exports['addConfiguration']=function(_0x5c11ec,_0x1de69e,_0x12a4aa){if(_0x5c11ec[_0xb7c7('0x48')]['id']){delete _0x5c11ec['body']['id'];}return db[_0xb7c7('0x3f')][_0xb7c7('0x4b')]({'where':{'id':_0x5c11ec[_0xb7c7('0x49')]['id']}})[_0xb7c7('0x24')](handleEntityNotFound(_0x1de69e,null))[_0xb7c7('0x24')](function(_0x5b9ce7){if(_0x5b9ce7){_0x5c11ec[_0xb7c7('0x48')][_0xb7c7('0x4d')]=_0x5b9ce7['id'];_0x5c11ec['body'][_0xb7c7('0x4e')]=integrations['getSubjects'](_0x5c11ec[_0xb7c7('0x48')][_0xb7c7('0x4f')],_0x5c11ec[_0xb7c7('0x48')]['type']);_0x5c11ec[_0xb7c7('0x48')]['Descriptions']=integrations[_0xb7c7('0x50')](_0x5c11ec[_0xb7c7('0x48')][_0xb7c7('0x4f')],_0x5c11ec[_0xb7c7('0x48')]['type']);return db[_0xb7c7('0x4c')][_0xb7c7('0x47')](_0x5c11ec[_0xb7c7('0x48')],{'include':[{'model':db[_0xb7c7('0x51')],'as':'Subjects'},{'model':db[_0xb7c7('0x51')],'as':_0xb7c7('0x52')}]});}return null;})[_0xb7c7('0x24')](respondWithResult(_0x1de69e,null))[_0xb7c7('0x46')](handleError(_0x1de69e,null));};function getAccessToken(_0x25eecb){return new Promise(function(_0x5b8608,_0x3f3a51){var _0x29994e;switch(_0x25eecb[_0xb7c7('0x53')]){case'US':_0x29994e=_0xb7c7('0x54');break;case'AU':_0x29994e=_0xb7c7('0x55');break;case'EU':_0x29994e=_0xb7c7('0x56');break;case'IN':_0x29994e=_0xb7c7('0x57');break;case'CN':_0x29994e=_0xb7c7('0x58');break;default:_0x29994e=_0xb7c7('0x56');break;}var _0x19b12e={'method':_0xb7c7('0x59'),'uri':_0x29994e+_0xb7c7('0x5a'),'qs':{'refresh_token':_0x25eecb[_0xb7c7('0x5b')],'client_id':_0x25eecb[_0xb7c7('0x5c')],'client_secret':_0x25eecb[_0xb7c7('0x5d')],'grant_type':_0xb7c7('0x5e')},'json':!![]};return rp(_0x19b12e)[_0xb7c7('0x24')](function(_0x37d71d){if(_0x37d71d['access_token']){_0x5b8608(_0x37d71d[_0xb7c7('0x5f')]);}else{_0x3f3a51(_0xb7c7('0x60'));}})[_0xb7c7('0x46')](function(_0x1b1dc5){_0x3f3a51(_0x1b1dc5);});});}exports['getFields']=function(_0x51a4d2,_0x8eadb4,_0x56bf18){var _0x255b01,_0x17f721,_0x57c57f,_0x2662d8,_0x5028e4;return db['ZohoAccount'][_0xb7c7('0x4b')]({'where':{'id':_0x51a4d2[_0xb7c7('0x49')]['id']},'attributes':['id',_0xb7c7('0x61'),_0xb7c7('0x53'),_0xb7c7('0x5c'),_0xb7c7('0x5d'),_0xb7c7('0x62'),'code',_0xb7c7('0x5b')]})[_0xb7c7('0x24')](handleEntityNotFound(_0x8eadb4,null))[_0xb7c7('0x24')](function(_0x356542){_0x5028e4=_0x356542;_0x255b01=_0x5028e4[_0xb7c7('0x61')];_0x17f721=_0x255b01==='zoho.eu'?'eu':_0xb7c7('0x63');_0x57c57f=_0x5028e4['serverUrl'];var _0x3ad0e8=_0x57c57f[_0xb7c7('0x64')](-0x1);if(_0x3ad0e8==='/'||_0x3ad0e8==='\x5c'||_0x3ad0e8===':'){_0x57c57f=_0x57c57f[_0xb7c7('0x65')](0x0,_0x57c57f['lastIndexOf'](_0x3ad0e8));}if(!_0x5028e4[_0xb7c7('0x5b')]){throw new Error(_0xb7c7('0x66'));}return getAccessToken(_0x5028e4);})[_0xb7c7('0x24')](function(_0x358c3c){if(_0x358c3c){return rp({'method':'GET','uri':util['format'](_0xb7c7('0x67'),_0x17f721),'qs':{'module':'Calls'},'headers':{'Authorization':_0xb7c7('0x68')+_0x358c3c},'json':!![]});}})[_0xb7c7('0x24')](function(_0x3f77f8){if(_0x3f77f8){if(_0x3f77f8[_0xb7c7('0x69')]&&_0x3f77f8['response']['error']){throw new Error(_0x3f77f8[_0xb7c7('0x69')][_0xb7c7('0x26')][_0xb7c7('0x6a')]);}var _0x4e9411=[];var _0x27cad5=[];var _0x38e51f=[_0xb7c7('0x6b'),'Subject',_0xb7c7('0x6c'),_0xb7c7('0x6d'),'Call_Duration',_0xb7c7('0x6e'),'Call_Start_Time',_0xb7c7('0x6f')];_0x27cad5=_[_0xb7c7('0x70')](_0x3f77f8[_0xb7c7('0x33')],function(_0x189e20){return _0x38e51f[_0xb7c7('0x71')](_0x189e20[_0xb7c7('0x72')]);});for(var _0x499d2b=0x0;_0x499d2b<_0x27cad5[_0xb7c7('0x34')];_0x499d2b++){if(_0x27cad5[_0x499d2b][_0xb7c7('0x73')]===![]){_0x4e9411[_0xb7c7('0x74')]({'id':_0x27cad5[_0x499d2b]['id'],'name':_0x27cad5[_0x499d2b][_0xb7c7('0x75')],'custom':_0x27cad5[_0x499d2b][_0xb7c7('0x76')],'options':_0x27cad5[_0x499d2b][_0xb7c7('0x77')]===_0xb7c7('0x78')&&_0x27cad5[_0x499d2b]['pick_list_values'][_0xb7c7('0x34')]>-0x1?_['map'](_0x27cad5[_0x499d2b][_0xb7c7('0x79')],function(_0x179e0f){return{'name':_0x179e0f,'value':_0x179e0f};}):[]});}}return{'count':_0x4e9411[_0xb7c7('0x34')],'rows':_0x4e9411};}else{return{'count':0x0,'rows':[]};}})['then'](respondWithResult(_0x8eadb4,null))[_0xb7c7('0x46')](function(_0x3a787b){var _0x4a07e4=_0x51a4d2['query'][_0xb7c7('0x7a')]?0x1f4:_0x3a787b[_0xb7c7('0x7b')]||0x1f4;logger[_0xb7c7('0x26')](_0xb7c7('0x7c'),_0xb7c7('0x7d'),_0x4a07e4,JSON[_0xb7c7('0x7e')](_0x3a787b));delete _0x3a787b[_0xb7c7('0x28')];if(_0x4a07e4===0x191){_0x4a07e4=0x190;}_0x8eadb4[_0xb7c7('0x17')](_0x4a07e4)[_0xb7c7('0x29')](_0x51a4d2[_0xb7c7('0x2e')]['test']?{'message':_0xb7c7('0x7f'),'statusCode':_0x3a787b['statusCode']}:_0x3a787b);});};
\ No newline at end of file