Built motion from commit (unavailable).|2.5.29
[motion2.git] / server / api / intFreshsalesConfiguration / intFreshsalesConfiguration.controller.js
index 5366b60..c2a284b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x326f=['destroy','end','stack','name','index','FreshsalesConfiguration','type','key','model','query','filters','intersection','attributes','fields','nolimit','limit','order','sort','where','pick','merge','map','filter','options','includeAll','include','rows','show','params','keys','rawAttributes','length','find','create','body','FreshsalesField','getSubjects','getDescriptions','findOne','hasOwnProperty','getFields','html-pdf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','lodash','squel','crypto','jsforce','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','../../config/utils','../../config/license/util','jayson/promise','client','then','info','FreshsalesConfiguration,\x20%s,\x20%s','request\x20sent','debug','FreshsalesConfiguration,\x20%s,\x20%s,\x20%s','error','code','catch','sendStatus','status','json','offset','set','Content-Range','reject','save','update'];(function(_0x1d2bbb,_0x202267){var _0x38082b=function(_0x27d153){while(--_0x27d153){_0x1d2bbb['push'](_0x1d2bbb['shift']());}};_0x38082b(++_0x202267);}(_0x326f,0xd1));var _0xf326=function(_0x59d7ba,_0xa421a1){_0x59d7ba=_0x59d7ba-0x0;var _0x2a20fb=_0x326f[_0x59d7ba];return _0x2a20fb;};'use strict';var pdf=require(_0xf326('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xf326('0x1'));var jsonpatch=require(_0xf326('0x2'));var rp=require(_0xf326('0x3'));var moment=require(_0xf326('0x4'));var BPromise=require(_0xf326('0x5'));var Mustache=require(_0xf326('0x6'));var util=require(_0xf326('0x7'));var path=require(_0xf326('0x8'));var sox=require(_0xf326('0x9'));var csv=require(_0xf326('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xf326('0xb'));var squel=require(_0xf326('0xc'));var crypto=require(_0xf326('0xd'));var jsforce=require(_0xf326('0xe'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xf326('0xf'));var Redis=require(_0xf326('0x10'));var authService=require(_0xf326('0x11'));var qs=require(_0xf326('0x12'));var as=require(_0xf326('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xf326('0x14'))('api');var utils=require(_0xf326('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0xf326('0x16'));var db=require('../../mysqldb')['db'];var jayson=require(_0xf326('0x17'));var client=jayson[_0xf326('0x18')]['http']({'port':0x232a});function respondWithRpcPromise(_0x342fe5,_0x472632,_0x3504eb,_0x17a098){return new BPromise(function(_0x5c8483,_0x45c1b6){var _0x5204ee=_0x17a098||client;return _0x5204ee['request'](_0x342fe5,_0x3504eb)[_0xf326('0x19')](function(_0x11f6d2){logger[_0xf326('0x1a')](_0xf326('0x1b'),_0x472632,_0xf326('0x1c'));logger[_0xf326('0x1d')](_0xf326('0x1e'),_0x472632,_0xf326('0x1c'),JSON['stringify'](_0x11f6d2));if(_0x11f6d2[_0xf326('0x1f')]){if(_0x11f6d2[_0xf326('0x1f')][_0xf326('0x20')]===0x1f4){logger[_0xf326('0x1f')](_0xf326('0x1b'),_0x472632,_0x11f6d2[_0xf326('0x1f')]['message']);return _0x45c1b6(_0x11f6d2['error']['message']);}logger[_0xf326('0x1f')](_0xf326('0x1b'),_0x472632,_0x11f6d2['error']['message']);return _0x5c8483(_0x11f6d2[_0xf326('0x1f')]['message']);}else{logger['info'](_0xf326('0x1b'),_0x472632,_0xf326('0x1c'));_0x5c8483(_0x11f6d2['result']['message']);}})[_0xf326('0x21')](function(_0xb1efcf){logger['error'](_0xf326('0x1b'),_0x472632,_0xb1efcf);_0x45c1b6(_0xb1efcf);});});}function respondWithStatusCode(_0x1b9039,_0x43c53e){_0x43c53e=_0x43c53e||0xcc;return function(_0x295752){if(_0x295752){return _0x1b9039[_0xf326('0x22')](_0x43c53e);}return _0x1b9039[_0xf326('0x23')](_0x43c53e)['end']();};}function respondWithResult(_0x55b9f4,_0x4f31f6){_0x4f31f6=_0x4f31f6||0xc8;return function(_0x520d85){if(_0x520d85){return _0x55b9f4[_0xf326('0x23')](_0x4f31f6)[_0xf326('0x24')](_0x520d85);}};}function respondWithFilteredResult(_0x1ff2b5,_0x148953){return function(_0x410237){if(_0x410237){var _0x5217d4=_0x410237['count'],_0x201d28=_0x148953[_0xf326('0x25')],_0xa3c0b=_0x148953['offset']+_0x148953['limit'],_0x212d5d;if(_0xa3c0b>=_0x5217d4){_0xa3c0b=_0x5217d4;_0x212d5d=0xc8;}else{_0x212d5d=0xce;}_0x1ff2b5[_0xf326('0x23')](_0x212d5d);return _0x1ff2b5[_0xf326('0x26')](_0xf326('0x27'),_0x201d28+'-'+_0xa3c0b+'/'+_0x5217d4)['json'](_0x410237);}return null;};}function patchUpdates(_0xc115d9){return function(_0x292500){try{jsonpatch['apply'](_0x292500,_0xc115d9,!![]);}catch(_0x225776){return BPromise[_0xf326('0x28')](_0x225776);}return _0x292500[_0xf326('0x29')]();};}function saveUpdates(_0x18d110,_0xa80156){return function(_0x269be9){if(_0x269be9){return _0x269be9[_0xf326('0x2a')](_0x18d110)[_0xf326('0x19')](function(_0x43b951){return _0x43b951;});}return null;};}function removeEntity(_0x349a03,_0x4b52f2){return function(_0x1035ed){if(_0x1035ed){return _0x1035ed[_0xf326('0x2b')]()[_0xf326('0x19')](function(){_0x349a03['status'](0xcc)[_0xf326('0x2c')]();});}};}function handleEntityNotFound(_0x1721fd,_0x303dc6){return function(_0x4df451){if(!_0x4df451){_0x1721fd['sendStatus'](0x194);}return _0x4df451;};}function handleError(_0x2b8b31,_0x46d75e){_0x46d75e=_0x46d75e||0x1f4;return function(_0x9c3039){logger[_0xf326('0x1f')](_0x9c3039[_0xf326('0x2d')]);if(_0x9c3039[_0xf326('0x2e')]){delete _0x9c3039[_0xf326('0x2e')];}_0x2b8b31[_0xf326('0x23')](_0x46d75e)['send'](_0x9c3039);};}exports[_0xf326('0x2f')]=function(_0x1981bc,_0x51207a){var _0x4083a2={},_0x4e5d7c={},_0xce1cbb={'count':0x0,'rows':[]};var _0x481b64=_['map'](db[_0xf326('0x30')]['rawAttributes'],function(_0x40dcb4){return{'name':_0x40dcb4['fieldName'],'type':_0x40dcb4[_0xf326('0x31')][_0xf326('0x32')]};});_0x4e5d7c[_0xf326('0x33')]=_['map'](_0x481b64,_0xf326('0x2e'));_0x4e5d7c[_0xf326('0x34')]=_['keys'](_0x1981bc[_0xf326('0x34')]);_0x4e5d7c[_0xf326('0x35')]=_[_0xf326('0x36')](_0x4e5d7c[_0xf326('0x33')],_0x4e5d7c['query']);_0x4083a2[_0xf326('0x37')]=_[_0xf326('0x36')](_0x4e5d7c[_0xf326('0x33')],qs[_0xf326('0x38')](_0x1981bc[_0xf326('0x34')]['fields']));_0x4083a2[_0xf326('0x37')]=_0x4083a2[_0xf326('0x37')]['length']?_0x4083a2['attributes']:_0x4e5d7c[_0xf326('0x33')];if(!_0x1981bc['query']['hasOwnProperty'](_0xf326('0x39'))){_0x4083a2['limit']=qs[_0xf326('0x3a')](_0x1981bc[_0xf326('0x34')][_0xf326('0x3a')]);_0x4083a2[_0xf326('0x25')]=qs['offset'](_0x1981bc[_0xf326('0x34')][_0xf326('0x25')]);}_0x4083a2[_0xf326('0x3b')]=qs[_0xf326('0x3c')](_0x1981bc[_0xf326('0x34')][_0xf326('0x3c')]);_0x4083a2[_0xf326('0x3d')]=qs[_0xf326('0x35')](_[_0xf326('0x3e')](_0x1981bc[_0xf326('0x34')],_0x4e5d7c[_0xf326('0x35')]),_0x481b64);if(_0x1981bc[_0xf326('0x34')]['filter']){_0x4083a2[_0xf326('0x3d')]=_[_0xf326('0x3f')](_0x4083a2[_0xf326('0x3d')],{'$or':_[_0xf326('0x40')](_0x481b64,function(_0x1dd262){if(_0x1dd262[_0xf326('0x31')]!=='VIRTUAL'){var _0x28e2d3={};_0x28e2d3[_0x1dd262[_0xf326('0x2e')]]={'$like':'%'+_0x1981bc['query'][_0xf326('0x41')]+'%'};return _0x28e2d3;}})});}_0x4083a2=_[_0xf326('0x3f')]({},_0x4083a2,_0x1981bc[_0xf326('0x42')]);var _0x305863={'where':_0x4083a2[_0xf326('0x3d')]};return db['FreshsalesConfiguration']['count'](_0x305863)[_0xf326('0x19')](function(_0x44e101){_0xce1cbb['count']=_0x44e101;if(_0x1981bc['query'][_0xf326('0x43')]){_0x4083a2[_0xf326('0x44')]=[{'all':!![]}];}return db[_0xf326('0x30')]['findAll'](_0x4083a2);})[_0xf326('0x19')](function(_0xe96e1e){_0xce1cbb[_0xf326('0x45')]=_0xe96e1e;return _0xce1cbb;})[_0xf326('0x19')](respondWithFilteredResult(_0x51207a,_0x4083a2))[_0xf326('0x21')](handleError(_0x51207a,null));};exports[_0xf326('0x46')]=function(_0x12792c,_0x3b90dc){var _0x3df9a8={'raw':![],'where':{'id':_0x12792c[_0xf326('0x47')]['id']}},_0x27ced1={};_0x27ced1[_0xf326('0x33')]=_[_0xf326('0x48')](db[_0xf326('0x30')][_0xf326('0x49')]);_0x27ced1['query']=_[_0xf326('0x48')](_0x12792c[_0xf326('0x34')]);_0x27ced1[_0xf326('0x35')]=_[_0xf326('0x36')](_0x27ced1['model'],_0x27ced1[_0xf326('0x34')]);_0x3df9a8[_0xf326('0x37')]=_[_0xf326('0x36')](_0x27ced1[_0xf326('0x33')],qs['fields'](_0x12792c[_0xf326('0x34')][_0xf326('0x38')]));_0x3df9a8[_0xf326('0x37')]=_0x3df9a8[_0xf326('0x37')][_0xf326('0x4a')]?_0x3df9a8['attributes']:_0x27ced1['model'];if(_0x12792c[_0xf326('0x34')][_0xf326('0x43')]){_0x3df9a8[_0xf326('0x44')]=[{'all':!![]}];}_0x3df9a8=_['merge']({},_0x3df9a8,_0x12792c[_0xf326('0x42')]);return db[_0xf326('0x30')][_0xf326('0x4b')](_0x3df9a8)['then'](handleEntityNotFound(_0x3b90dc,null))['then'](respondWithResult(_0x3b90dc,null))[_0xf326('0x21')](handleError(_0x3b90dc,null));};exports['create']=function(_0x1cf58f,_0x554277){return db[_0xf326('0x30')][_0xf326('0x4c')](_0x1cf58f[_0xf326('0x4d')],{})[_0xf326('0x19')](respondWithResult(_0x554277,0xc9))[_0xf326('0x21')](handleError(_0x554277,null));};exports[_0xf326('0x2a')]=function(_0x7f7ece,_0x495a16){if(_0x7f7ece[_0xf326('0x4d')]['id']){delete _0x7f7ece[_0xf326('0x4d')]['id'];}return db[_0xf326('0x30')]['find']({'where':{'id':_0x7f7ece[_0xf326('0x47')]['id']}})[_0xf326('0x19')](handleEntityNotFound(_0x495a16,null))[_0xf326('0x19')](saveUpdates(_0x7f7ece[_0xf326('0x4d')],null))[_0xf326('0x19')](respondWithResult(_0x495a16,null))['catch'](handleError(_0x495a16,null));};exports[_0xf326('0x2b')]=function(_0x21eac7,_0x287a97){return db[_0xf326('0x30')]['find']({'where':{'id':_0x21eac7[_0xf326('0x47')]['id']}})[_0xf326('0x19')](handleEntityNotFound(_0x287a97,null))[_0xf326('0x19')](removeEntity(_0x287a97,null))[_0xf326('0x21')](handleError(_0x287a97,null));};exports['getSubjects']=function(_0x5be2b1,_0x18b46e,_0x44d2ed){var _0x55ca96={};var _0x3cf6fa={};var _0x29de71;var _0x316609;return db[_0xf326('0x30')]['findOne']({'where':{'id':_0x5be2b1[_0xf326('0x47')]['id']}})['then'](handleEntityNotFound(_0x18b46e,null))['then'](function(_0x9d84c3){if(_0x9d84c3){_0x29de71=_0x9d84c3;_0x3cf6fa['model']=_[_0xf326('0x48')](db[_0xf326('0x4e')][_0xf326('0x49')]);_0x3cf6fa['query']=_['keys'](_0x5be2b1[_0xf326('0x34')]);_0x3cf6fa[_0xf326('0x35')]=_[_0xf326('0x36')](_0x3cf6fa['model'],_0x3cf6fa[_0xf326('0x34')]);_0x55ca96['attributes']=_[_0xf326('0x36')](_0x3cf6fa[_0xf326('0x33')],qs[_0xf326('0x38')](_0x5be2b1[_0xf326('0x34')][_0xf326('0x38')]));_0x55ca96[_0xf326('0x37')]=_0x55ca96[_0xf326('0x37')][_0xf326('0x4a')]?_0x55ca96[_0xf326('0x37')]:_0x3cf6fa[_0xf326('0x33')];_0x55ca96[_0xf326('0x3b')]=qs[_0xf326('0x3c')](_0x5be2b1[_0xf326('0x34')]['sort']);_0x55ca96[_0xf326('0x3d')]=qs['filters'](_[_0xf326('0x3e')](_0x5be2b1[_0xf326('0x34')],_0x3cf6fa['filters']));if(_0x5be2b1[_0xf326('0x34')]['filter']){_0x55ca96[_0xf326('0x3d')]=_[_0xf326('0x3f')](_0x55ca96[_0xf326('0x3d')],{'$or':_[_0xf326('0x40')](_0x55ca96[_0xf326('0x37')],function(_0x51ff5e){var _0x4ec099={};_0x4ec099[_0x51ff5e]={'$like':'%'+_0x5be2b1[_0xf326('0x34')][_0xf326('0x41')]+'%'};return _0x4ec099;})});}_0x55ca96=_[_0xf326('0x3f')]({},_0x55ca96,_0x5be2b1[_0xf326('0x42')]);return _0x29de71[_0xf326('0x4f')](_0x55ca96);}})['then'](function(_0x28c4f2){if(_0x28c4f2){_0x316609=_0x28c4f2[_0xf326('0x4a')];if(!_0x5be2b1['query']['hasOwnProperty']('nolimit')){_0x55ca96[_0xf326('0x3a')]=qs[_0xf326('0x3a')](_0x5be2b1[_0xf326('0x34')][_0xf326('0x3a')]);_0x55ca96[_0xf326('0x25')]=qs[_0xf326('0x25')](_0x5be2b1[_0xf326('0x34')]['offset']);}return _0x29de71[_0xf326('0x4f')](_0x55ca96);}})[_0xf326('0x19')](function(_0x3c3379){if(_0x3c3379){return _0x3c3379?{'count':_0x316609,'rows':_0x3c3379}:null;}})[_0xf326('0x19')](respondWithResult(_0x18b46e,null))['catch'](handleError(_0x18b46e,null));};exports[_0xf326('0x50')]=function(_0x5eebe8,_0x499b59,_0x2dd9e4){var _0x540fa0={};var _0x78ba34={};var _0x3411a4;var _0x461059;return db[_0xf326('0x30')][_0xf326('0x51')]({'where':{'id':_0x5eebe8['params']['id']}})['then'](handleEntityNotFound(_0x499b59,null))['then'](function(_0xeeea57){if(_0xeeea57){_0x3411a4=_0xeeea57;_0x78ba34[_0xf326('0x33')]=_[_0xf326('0x48')](db[_0xf326('0x4e')][_0xf326('0x49')]);_0x78ba34['query']=_[_0xf326('0x48')](_0x5eebe8[_0xf326('0x34')]);_0x78ba34[_0xf326('0x35')]=_['intersection'](_0x78ba34['model'],_0x78ba34[_0xf326('0x34')]);_0x540fa0[_0xf326('0x37')]=_['intersection'](_0x78ba34['model'],qs[_0xf326('0x38')](_0x5eebe8['query'][_0xf326('0x38')]));_0x540fa0['attributes']=_0x540fa0['attributes']['length']?_0x540fa0[_0xf326('0x37')]:_0x78ba34[_0xf326('0x33')];_0x540fa0[_0xf326('0x3b')]=qs['sort'](_0x5eebe8[_0xf326('0x34')][_0xf326('0x3c')]);_0x540fa0[_0xf326('0x3d')]=qs[_0xf326('0x35')](_[_0xf326('0x3e')](_0x5eebe8[_0xf326('0x34')],_0x78ba34[_0xf326('0x35')]));if(_0x5eebe8[_0xf326('0x34')][_0xf326('0x41')]){_0x540fa0['where']=_[_0xf326('0x3f')](_0x540fa0['where'],{'$or':_[_0xf326('0x40')](_0x540fa0[_0xf326('0x37')],function(_0x40ee66){var _0x4ba982={};_0x4ba982[_0x40ee66]={'$like':'%'+_0x5eebe8[_0xf326('0x34')][_0xf326('0x41')]+'%'};return _0x4ba982;})});}_0x540fa0=_[_0xf326('0x3f')]({},_0x540fa0,_0x5eebe8['options']);return _0x3411a4[_0xf326('0x50')](_0x540fa0);}})[_0xf326('0x19')](function(_0x3bbe4c){if(_0x3bbe4c){_0x461059=_0x3bbe4c[_0xf326('0x4a')];if(!_0x5eebe8['query'][_0xf326('0x52')]('nolimit')){_0x540fa0['limit']=qs[_0xf326('0x3a')](_0x5eebe8[_0xf326('0x34')]['limit']);_0x540fa0['offset']=qs['offset'](_0x5eebe8[_0xf326('0x34')]['offset']);}return _0x3411a4[_0xf326('0x50')](_0x540fa0);}})[_0xf326('0x19')](function(_0x3434b2){if(_0x3434b2){return _0x3434b2?{'count':_0x461059,'rows':_0x3434b2}:null;}})[_0xf326('0x19')](respondWithResult(_0x499b59,null))[_0xf326('0x21')](handleError(_0x499b59,null));};exports[_0xf326('0x53')]=function(_0x5d23f0,_0x39edf8,_0x323926){var _0x5f1724={};var _0x497ada={};var _0x14eecc;var _0x537afc;return db[_0xf326('0x30')][_0xf326('0x51')]({'where':{'id':_0x5d23f0[_0xf326('0x47')]['id']}})[_0xf326('0x19')](handleEntityNotFound(_0x39edf8,null))[_0xf326('0x19')](function(_0x6e662){if(_0x6e662){_0x14eecc=_0x6e662;_0x497ada[_0xf326('0x33')]=_[_0xf326('0x48')](db[_0xf326('0x4e')]['rawAttributes']);_0x497ada[_0xf326('0x34')]=_[_0xf326('0x48')](_0x5d23f0['query']);_0x497ada[_0xf326('0x35')]=_['intersection'](_0x497ada[_0xf326('0x33')],_0x497ada[_0xf326('0x34')]);_0x5f1724[_0xf326('0x37')]=_['intersection'](_0x497ada[_0xf326('0x33')],qs[_0xf326('0x38')](_0x5d23f0[_0xf326('0x34')][_0xf326('0x38')]));_0x5f1724[_0xf326('0x37')]=_0x5f1724[_0xf326('0x37')][_0xf326('0x4a')]?_0x5f1724[_0xf326('0x37')]:_0x497ada[_0xf326('0x33')];_0x5f1724[_0xf326('0x3b')]=qs[_0xf326('0x3c')](_0x5d23f0[_0xf326('0x34')][_0xf326('0x3c')]);_0x5f1724[_0xf326('0x3d')]=qs[_0xf326('0x35')](_['pick'](_0x5d23f0[_0xf326('0x34')],_0x497ada[_0xf326('0x35')]));if(_0x5d23f0['query'][_0xf326('0x41')]){_0x5f1724[_0xf326('0x3d')]=_['merge'](_0x5f1724[_0xf326('0x3d')],{'$or':_[_0xf326('0x40')](_0x5f1724[_0xf326('0x37')],function(_0x8dbd96){var _0x2ab607={};_0x2ab607[_0x8dbd96]={'$like':'%'+_0x5d23f0[_0xf326('0x34')][_0xf326('0x41')]+'%'};return _0x2ab607;})});}_0x5f1724=_['merge']({},_0x5f1724,_0x5d23f0[_0xf326('0x42')]);return _0x14eecc[_0xf326('0x53')](_0x5f1724);}})[_0xf326('0x19')](function(_0x3c33d1){if(_0x3c33d1){_0x537afc=_0x3c33d1[_0xf326('0x4a')];if(!_0x5d23f0[_0xf326('0x34')][_0xf326('0x52')](_0xf326('0x39'))){_0x5f1724['limit']=qs[_0xf326('0x3a')](_0x5d23f0[_0xf326('0x34')]['limit']);_0x5f1724[_0xf326('0x25')]=qs['offset'](_0x5d23f0[_0xf326('0x34')][_0xf326('0x25')]);}return _0x14eecc[_0xf326('0x53')](_0x5f1724);}})[_0xf326('0x19')](function(_0x405a52){if(_0x405a52){return _0x405a52?{'count':_0x537afc,'rows':_0x405a52}:null;}})[_0xf326('0x19')](respondWithResult(_0x39edf8,null))[_0xf326('0x21')](handleError(_0x39edf8,null));};
\ No newline at end of file
+var _0x3e9a=['moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','ioredis','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','jayson/promise','client','http','request','then','info','FreshsalesConfiguration,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','result','catch','end','json','offset','undefined','limit','count','status','set','Content-Range','reject','destroy','sendStatus','stack','name','index','FreshsalesConfiguration','rawAttributes','key','model','query','keys','filters','intersection','attributes','fields','nolimit','order','sort','where','pick','filter','merge','map','type','VIRTUAL','includeAll','include','rows','params','length','options','find','create','body','getSubjects','findOne','FreshsalesField','hasOwnProperty','getDescriptions','getFields','rimraf','zip-dir'];(function(_0x5cde4f,_0x325c57){var _0x37b4da=function(_0x2b4599){while(--_0x2b4599){_0x5cde4f['push'](_0x5cde4f['shift']());}};_0x37b4da(++_0x325c57);}(_0x3e9a,0xb0));var _0xa3e9=function(_0x252f3b,_0x16a41e){_0x252f3b=_0x252f3b-0x0;var _0x510747=_0x3e9a[_0x252f3b];return _0x510747;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xa3e9('0x0'));var zipdir=require(_0xa3e9('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xa3e9('0x2'));var BPromise=require(_0xa3e9('0x3'));var Mustache=require(_0xa3e9('0x4'));var util=require(_0xa3e9('0x5'));var path=require(_0xa3e9('0x6'));var sox=require('sox');var csv=require(_0xa3e9('0x7'));var ejs=require(_0xa3e9('0x8'));var fs=require('fs');var fs_extra=require(_0xa3e9('0x9'));var _=require(_0xa3e9('0xa'));var squel=require(_0xa3e9('0xb'));var crypto=require(_0xa3e9('0xc'));var jsforce=require(_0xa3e9('0xd'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xa3e9('0xe'));var Papa=require(_0xa3e9('0xf'));var Redis=require(_0xa3e9('0x10'));var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xa3e9('0x11'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xa3e9('0x12'))(_0xa3e9('0x13'));var utils=require(_0xa3e9('0x14'));var config=require(_0xa3e9('0x15'));var licenseUtil=require(_0xa3e9('0x16'));var db=require(_0xa3e9('0x17'))['db'];var jayson=require(_0xa3e9('0x18'));var client=jayson[_0xa3e9('0x19')][_0xa3e9('0x1a')]({'port':0x232a});function respondWithRpcPromise(_0x102145,_0x2446e8,_0x4c82eb,_0x4fee8b){return new BPromise(function(_0x5ce10c,_0x45f7a7){var _0x42745c=_0x4fee8b||client;return _0x42745c[_0xa3e9('0x1b')](_0x102145,_0x4c82eb)[_0xa3e9('0x1c')](function(_0x2a11a7){logger[_0xa3e9('0x1d')](_0xa3e9('0x1e'),_0x2446e8,'request\x20sent');logger[_0xa3e9('0x1f')]('FreshsalesConfiguration,\x20%s,\x20%s,\x20%s',_0x2446e8,_0xa3e9('0x20'),JSON[_0xa3e9('0x21')](_0x2a11a7));if(_0x2a11a7[_0xa3e9('0x22')]){if(_0x2a11a7['error'][_0xa3e9('0x23')]===0x1f4){logger[_0xa3e9('0x22')](_0xa3e9('0x1e'),_0x2446e8,_0x2a11a7[_0xa3e9('0x22')][_0xa3e9('0x24')]);return _0x45f7a7(_0x2a11a7[_0xa3e9('0x22')][_0xa3e9('0x24')]);}logger['error']('FreshsalesConfiguration,\x20%s,\x20%s',_0x2446e8,_0x2a11a7[_0xa3e9('0x22')]['message']);return _0x5ce10c(_0x2a11a7[_0xa3e9('0x22')][_0xa3e9('0x24')]);}else{logger[_0xa3e9('0x1d')]('FreshsalesConfiguration,\x20%s,\x20%s',_0x2446e8,_0xa3e9('0x20'));_0x5ce10c(_0x2a11a7[_0xa3e9('0x25')][_0xa3e9('0x24')]);}})[_0xa3e9('0x26')](function(_0x20fb62){logger['error'](_0xa3e9('0x1e'),_0x2446e8,_0x20fb62);_0x45f7a7(_0x20fb62);});});}function respondWithStatusCode(_0x260121,_0x1604b8){_0x1604b8=_0x1604b8||0xcc;return function(_0x2ddb04){if(_0x2ddb04){return _0x260121['sendStatus'](_0x1604b8);}return _0x260121['status'](_0x1604b8)[_0xa3e9('0x27')]();};}function respondWithResult(_0x1fca07,_0x138188){_0x138188=_0x138188||0xc8;return function(_0x56653b){if(_0x56653b){return _0x1fca07['status'](_0x138188)[_0xa3e9('0x28')](_0x56653b);}};}function respondWithFilteredResult(_0x54dbe0,_0x34c060){return function(_0x584741){if(_0x584741){var _0x2fdbbc=typeof _0x34c060[_0xa3e9('0x29')]===_0xa3e9('0x2a')&&typeof _0x34c060[_0xa3e9('0x2b')]===_0xa3e9('0x2a');var _0x457673=_0x584741[_0xa3e9('0x2c')];var _0x195821=_0x2fdbbc?0x0:_0x34c060[_0xa3e9('0x29')];var _0x2b884f=_0x2fdbbc?_0x584741[_0xa3e9('0x2c')]:_0x34c060[_0xa3e9('0x29')]+_0x34c060[_0xa3e9('0x2b')];var _0x6aff9a;if(_0x2b884f>=_0x457673){_0x2b884f=_0x457673;_0x6aff9a=0xc8;}else{_0x6aff9a=0xce;}_0x54dbe0[_0xa3e9('0x2d')](_0x6aff9a);return _0x54dbe0[_0xa3e9('0x2e')](_0xa3e9('0x2f'),_0x195821+'-'+_0x2b884f+'/'+_0x457673)[_0xa3e9('0x28')](_0x584741);}return null;};}function patchUpdates(_0x13ef00){return function(_0x5e816f){try{jsonpatch['apply'](_0x5e816f,_0x13ef00,!![]);}catch(_0x2fca25){return BPromise[_0xa3e9('0x30')](_0x2fca25);}return _0x5e816f['save']();};}function saveUpdates(_0x1a248e,_0x4de772){return function(_0x4269f4){if(_0x4269f4){return _0x4269f4['update'](_0x1a248e)[_0xa3e9('0x1c')](function(_0x5a1f6b){return _0x5a1f6b;});}return null;};}function removeEntity(_0x22c224,_0x4c67d7){return function(_0x2deabc){if(_0x2deabc){return _0x2deabc[_0xa3e9('0x31')]()[_0xa3e9('0x1c')](function(){_0x22c224[_0xa3e9('0x2d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4ad2ab,_0x34a739){return function(_0x4d4293){if(!_0x4d4293){_0x4ad2ab[_0xa3e9('0x32')](0x194);}return _0x4d4293;};}function handleError(_0x3b25a6,_0x445b5b){_0x445b5b=_0x445b5b||0x1f4;return function(_0x46b75f){logger[_0xa3e9('0x22')](_0x46b75f[_0xa3e9('0x33')]);if(_0x46b75f[_0xa3e9('0x34')]){delete _0x46b75f[_0xa3e9('0x34')];}_0x3b25a6[_0xa3e9('0x2d')](_0x445b5b)['send'](_0x46b75f);};}exports[_0xa3e9('0x35')]=function(_0x1d7c14,_0x218f5a){var _0x35d3b4={},_0x28b4ee={},_0x378c09={'count':0x0,'rows':[]};var _0x1d8b58=_['map'](db[_0xa3e9('0x36')][_0xa3e9('0x37')],function(_0x202293){return{'name':_0x202293['fieldName'],'type':_0x202293['type'][_0xa3e9('0x38')]};});_0x28b4ee[_0xa3e9('0x39')]=_['map'](_0x1d8b58,_0xa3e9('0x34'));_0x28b4ee[_0xa3e9('0x3a')]=_[_0xa3e9('0x3b')](_0x1d7c14[_0xa3e9('0x3a')]);_0x28b4ee[_0xa3e9('0x3c')]=_[_0xa3e9('0x3d')](_0x28b4ee[_0xa3e9('0x39')],_0x28b4ee[_0xa3e9('0x3a')]);_0x35d3b4[_0xa3e9('0x3e')]=_['intersection'](_0x28b4ee[_0xa3e9('0x39')],qs[_0xa3e9('0x3f')](_0x1d7c14[_0xa3e9('0x3a')][_0xa3e9('0x3f')]));_0x35d3b4[_0xa3e9('0x3e')]=_0x35d3b4[_0xa3e9('0x3e')]['length']?_0x35d3b4['attributes']:_0x28b4ee[_0xa3e9('0x39')];if(!_0x1d7c14[_0xa3e9('0x3a')]['hasOwnProperty'](_0xa3e9('0x40'))){_0x35d3b4[_0xa3e9('0x2b')]=qs['limit'](_0x1d7c14[_0xa3e9('0x3a')]['limit']);_0x35d3b4[_0xa3e9('0x29')]=qs[_0xa3e9('0x29')](_0x1d7c14[_0xa3e9('0x3a')][_0xa3e9('0x29')]);}_0x35d3b4[_0xa3e9('0x41')]=qs[_0xa3e9('0x42')](_0x1d7c14[_0xa3e9('0x3a')][_0xa3e9('0x42')]);_0x35d3b4[_0xa3e9('0x43')]=qs['filters'](_[_0xa3e9('0x44')](_0x1d7c14['query'],_0x28b4ee[_0xa3e9('0x3c')]),_0x1d8b58);if(_0x1d7c14[_0xa3e9('0x3a')][_0xa3e9('0x45')]){_0x35d3b4[_0xa3e9('0x43')]=_[_0xa3e9('0x46')](_0x35d3b4[_0xa3e9('0x43')],{'$or':_[_0xa3e9('0x47')](_0x1d8b58,function(_0x232e18){if(_0x232e18[_0xa3e9('0x48')]!==_0xa3e9('0x49')){var _0x4ddf22={};_0x4ddf22[_0x232e18[_0xa3e9('0x34')]]={'$like':'%'+_0x1d7c14[_0xa3e9('0x3a')]['filter']+'%'};return _0x4ddf22;}})});}_0x35d3b4=_[_0xa3e9('0x46')]({},_0x35d3b4,_0x1d7c14['options']);var _0x2b9760={'where':_0x35d3b4['where']};return db['FreshsalesConfiguration']['count'](_0x2b9760)[_0xa3e9('0x1c')](function(_0x31a77f){_0x378c09[_0xa3e9('0x2c')]=_0x31a77f;if(_0x1d7c14[_0xa3e9('0x3a')][_0xa3e9('0x4a')]){_0x35d3b4[_0xa3e9('0x4b')]=[{'all':!![]}];}return db[_0xa3e9('0x36')]['findAll'](_0x35d3b4);})[_0xa3e9('0x1c')](function(_0x381d2d){_0x378c09[_0xa3e9('0x4c')]=_0x381d2d;return _0x378c09;})[_0xa3e9('0x1c')](respondWithFilteredResult(_0x218f5a,_0x35d3b4))[_0xa3e9('0x26')](handleError(_0x218f5a,null));};exports['show']=function(_0xad51d,_0x23cea1){var _0x501fa6={'raw':![],'where':{'id':_0xad51d[_0xa3e9('0x4d')]['id']}},_0x203654={};_0x203654['model']=_['keys'](db['FreshsalesConfiguration'][_0xa3e9('0x37')]);_0x203654[_0xa3e9('0x3a')]=_[_0xa3e9('0x3b')](_0xad51d[_0xa3e9('0x3a')]);_0x203654[_0xa3e9('0x3c')]=_['intersection'](_0x203654['model'],_0x203654['query']);_0x501fa6[_0xa3e9('0x3e')]=_[_0xa3e9('0x3d')](_0x203654[_0xa3e9('0x39')],qs[_0xa3e9('0x3f')](_0xad51d[_0xa3e9('0x3a')]['fields']));_0x501fa6[_0xa3e9('0x3e')]=_0x501fa6[_0xa3e9('0x3e')][_0xa3e9('0x4e')]?_0x501fa6[_0xa3e9('0x3e')]:_0x203654[_0xa3e9('0x39')];if(_0xad51d[_0xa3e9('0x3a')][_0xa3e9('0x4a')]){_0x501fa6[_0xa3e9('0x4b')]=[{'all':!![]}];}_0x501fa6=_[_0xa3e9('0x46')]({},_0x501fa6,_0xad51d[_0xa3e9('0x4f')]);return db['FreshsalesConfiguration'][_0xa3e9('0x50')](_0x501fa6)[_0xa3e9('0x1c')](handleEntityNotFound(_0x23cea1,null))[_0xa3e9('0x1c')](respondWithResult(_0x23cea1,null))[_0xa3e9('0x26')](handleError(_0x23cea1,null));};exports['create']=function(_0x22cef9,_0x37b685){return db[_0xa3e9('0x36')][_0xa3e9('0x51')](_0x22cef9[_0xa3e9('0x52')],{})['then'](respondWithResult(_0x37b685,0xc9))[_0xa3e9('0x26')](handleError(_0x37b685,null));};exports['update']=function(_0x2f9ae3,_0x57b37d){if(_0x2f9ae3[_0xa3e9('0x52')]['id']){delete _0x2f9ae3[_0xa3e9('0x52')]['id'];}return db['FreshsalesConfiguration'][_0xa3e9('0x50')]({'where':{'id':_0x2f9ae3[_0xa3e9('0x4d')]['id']}})[_0xa3e9('0x1c')](handleEntityNotFound(_0x57b37d,null))[_0xa3e9('0x1c')](saveUpdates(_0x2f9ae3[_0xa3e9('0x52')],null))[_0xa3e9('0x1c')](respondWithResult(_0x57b37d,null))['catch'](handleError(_0x57b37d,null));};exports[_0xa3e9('0x31')]=function(_0x403ada,_0x51d09d){return db['FreshsalesConfiguration'][_0xa3e9('0x50')]({'where':{'id':_0x403ada[_0xa3e9('0x4d')]['id']}})[_0xa3e9('0x1c')](handleEntityNotFound(_0x51d09d,null))[_0xa3e9('0x1c')](removeEntity(_0x51d09d,null))[_0xa3e9('0x26')](handleError(_0x51d09d,null));};exports[_0xa3e9('0x53')]=function(_0x5a8f96,_0xc69f23,_0x14e986){var _0x57cbc1={};var _0x4f3565={};var _0x49b767;var _0x1fcf4d;return db[_0xa3e9('0x36')][_0xa3e9('0x54')]({'where':{'id':_0x5a8f96['params']['id']}})[_0xa3e9('0x1c')](handleEntityNotFound(_0xc69f23,null))['then'](function(_0x2e745b){if(_0x2e745b){_0x49b767=_0x2e745b;_0x4f3565[_0xa3e9('0x39')]=_[_0xa3e9('0x3b')](db[_0xa3e9('0x55')]['rawAttributes']);_0x4f3565[_0xa3e9('0x3a')]=_['keys'](_0x5a8f96[_0xa3e9('0x3a')]);_0x4f3565['filters']=_['intersection'](_0x4f3565[_0xa3e9('0x39')],_0x4f3565[_0xa3e9('0x3a')]);_0x57cbc1[_0xa3e9('0x3e')]=_['intersection'](_0x4f3565[_0xa3e9('0x39')],qs[_0xa3e9('0x3f')](_0x5a8f96[_0xa3e9('0x3a')][_0xa3e9('0x3f')]));_0x57cbc1[_0xa3e9('0x3e')]=_0x57cbc1[_0xa3e9('0x3e')][_0xa3e9('0x4e')]?_0x57cbc1[_0xa3e9('0x3e')]:_0x4f3565[_0xa3e9('0x39')];_0x57cbc1[_0xa3e9('0x41')]=qs[_0xa3e9('0x42')](_0x5a8f96['query'][_0xa3e9('0x42')]);_0x57cbc1[_0xa3e9('0x43')]=qs[_0xa3e9('0x3c')](_[_0xa3e9('0x44')](_0x5a8f96['query'],_0x4f3565[_0xa3e9('0x3c')]));if(_0x5a8f96['query'][_0xa3e9('0x45')]){_0x57cbc1[_0xa3e9('0x43')]=_[_0xa3e9('0x46')](_0x57cbc1[_0xa3e9('0x43')],{'$or':_[_0xa3e9('0x47')](_0x57cbc1[_0xa3e9('0x3e')],function(_0x5648ba){var _0x1421fe={};_0x1421fe[_0x5648ba]={'$like':'%'+_0x5a8f96['query'][_0xa3e9('0x45')]+'%'};return _0x1421fe;})});}_0x57cbc1=_[_0xa3e9('0x46')]({},_0x57cbc1,_0x5a8f96[_0xa3e9('0x4f')]);return _0x49b767[_0xa3e9('0x53')](_0x57cbc1);}})[_0xa3e9('0x1c')](function(_0x59573e){if(_0x59573e){_0x1fcf4d=_0x59573e[_0xa3e9('0x4e')];if(!_0x5a8f96[_0xa3e9('0x3a')][_0xa3e9('0x56')]('nolimit')){_0x57cbc1[_0xa3e9('0x2b')]=qs[_0xa3e9('0x2b')](_0x5a8f96[_0xa3e9('0x3a')][_0xa3e9('0x2b')]);_0x57cbc1[_0xa3e9('0x29')]=qs['offset'](_0x5a8f96[_0xa3e9('0x3a')][_0xa3e9('0x29')]);}return _0x49b767[_0xa3e9('0x53')](_0x57cbc1);}})[_0xa3e9('0x1c')](function(_0xb6ce8e){if(_0xb6ce8e){return _0xb6ce8e?{'count':_0x1fcf4d,'rows':_0xb6ce8e}:null;}})['then'](respondWithResult(_0xc69f23,null))[_0xa3e9('0x26')](handleError(_0xc69f23,null));};exports[_0xa3e9('0x57')]=function(_0x4e7c29,_0x18420e,_0x41e6e4){var _0x2f2ca1={};var _0x18f782={};var _0x28a18a;var _0x3faa3c;return db[_0xa3e9('0x36')][_0xa3e9('0x54')]({'where':{'id':_0x4e7c29[_0xa3e9('0x4d')]['id']}})[_0xa3e9('0x1c')](handleEntityNotFound(_0x18420e,null))[_0xa3e9('0x1c')](function(_0x15c60e){if(_0x15c60e){_0x28a18a=_0x15c60e;_0x18f782[_0xa3e9('0x39')]=_[_0xa3e9('0x3b')](db['FreshsalesField'][_0xa3e9('0x37')]);_0x18f782[_0xa3e9('0x3a')]=_[_0xa3e9('0x3b')](_0x4e7c29[_0xa3e9('0x3a')]);_0x18f782['filters']=_['intersection'](_0x18f782['model'],_0x18f782['query']);_0x2f2ca1[_0xa3e9('0x3e')]=_[_0xa3e9('0x3d')](_0x18f782[_0xa3e9('0x39')],qs['fields'](_0x4e7c29[_0xa3e9('0x3a')][_0xa3e9('0x3f')]));_0x2f2ca1[_0xa3e9('0x3e')]=_0x2f2ca1[_0xa3e9('0x3e')][_0xa3e9('0x4e')]?_0x2f2ca1[_0xa3e9('0x3e')]:_0x18f782[_0xa3e9('0x39')];_0x2f2ca1[_0xa3e9('0x41')]=qs[_0xa3e9('0x42')](_0x4e7c29['query'][_0xa3e9('0x42')]);_0x2f2ca1[_0xa3e9('0x43')]=qs[_0xa3e9('0x3c')](_[_0xa3e9('0x44')](_0x4e7c29['query'],_0x18f782[_0xa3e9('0x3c')]));if(_0x4e7c29[_0xa3e9('0x3a')][_0xa3e9('0x45')]){_0x2f2ca1[_0xa3e9('0x43')]=_[_0xa3e9('0x46')](_0x2f2ca1[_0xa3e9('0x43')],{'$or':_[_0xa3e9('0x47')](_0x2f2ca1[_0xa3e9('0x3e')],function(_0x5863e7){var _0x43c25d={};_0x43c25d[_0x5863e7]={'$like':'%'+_0x4e7c29[_0xa3e9('0x3a')][_0xa3e9('0x45')]+'%'};return _0x43c25d;})});}_0x2f2ca1=_[_0xa3e9('0x46')]({},_0x2f2ca1,_0x4e7c29[_0xa3e9('0x4f')]);return _0x28a18a[_0xa3e9('0x57')](_0x2f2ca1);}})['then'](function(_0x33c9a2){if(_0x33c9a2){_0x3faa3c=_0x33c9a2[_0xa3e9('0x4e')];if(!_0x4e7c29[_0xa3e9('0x3a')][_0xa3e9('0x56')](_0xa3e9('0x40'))){_0x2f2ca1['limit']=qs['limit'](_0x4e7c29[_0xa3e9('0x3a')][_0xa3e9('0x2b')]);_0x2f2ca1[_0xa3e9('0x29')]=qs['offset'](_0x4e7c29['query']['offset']);}return _0x28a18a['getDescriptions'](_0x2f2ca1);}})[_0xa3e9('0x1c')](function(_0x13a62b){if(_0x13a62b){return _0x13a62b?{'count':_0x3faa3c,'rows':_0x13a62b}:null;}})[_0xa3e9('0x1c')](respondWithResult(_0x18420e,null))['catch'](handleError(_0x18420e,null));};exports[_0xa3e9('0x58')]=function(_0x2d9153,_0x5ccd7b,_0x2b60ac){var _0x4f1458={};var _0x4aa074={};var _0x5ab55b;var _0x376748;return db[_0xa3e9('0x36')]['findOne']({'where':{'id':_0x2d9153['params']['id']}})['then'](handleEntityNotFound(_0x5ccd7b,null))[_0xa3e9('0x1c')](function(_0x6f969a){if(_0x6f969a){_0x5ab55b=_0x6f969a;_0x4aa074[_0xa3e9('0x39')]=_['keys'](db[_0xa3e9('0x55')][_0xa3e9('0x37')]);_0x4aa074[_0xa3e9('0x3a')]=_[_0xa3e9('0x3b')](_0x2d9153[_0xa3e9('0x3a')]);_0x4aa074['filters']=_['intersection'](_0x4aa074['model'],_0x4aa074['query']);_0x4f1458[_0xa3e9('0x3e')]=_[_0xa3e9('0x3d')](_0x4aa074[_0xa3e9('0x39')],qs[_0xa3e9('0x3f')](_0x2d9153[_0xa3e9('0x3a')][_0xa3e9('0x3f')]));_0x4f1458[_0xa3e9('0x3e')]=_0x4f1458['attributes'][_0xa3e9('0x4e')]?_0x4f1458[_0xa3e9('0x3e')]:_0x4aa074[_0xa3e9('0x39')];_0x4f1458['order']=qs['sort'](_0x2d9153[_0xa3e9('0x3a')][_0xa3e9('0x42')]);_0x4f1458[_0xa3e9('0x43')]=qs['filters'](_[_0xa3e9('0x44')](_0x2d9153[_0xa3e9('0x3a')],_0x4aa074[_0xa3e9('0x3c')]));if(_0x2d9153[_0xa3e9('0x3a')][_0xa3e9('0x45')]){_0x4f1458[_0xa3e9('0x43')]=_['merge'](_0x4f1458['where'],{'$or':_[_0xa3e9('0x47')](_0x4f1458[_0xa3e9('0x3e')],function(_0x115f67){var _0x2acc51={};_0x2acc51[_0x115f67]={'$like':'%'+_0x2d9153[_0xa3e9('0x3a')][_0xa3e9('0x45')]+'%'};return _0x2acc51;})});}_0x4f1458=_[_0xa3e9('0x46')]({},_0x4f1458,_0x2d9153[_0xa3e9('0x4f')]);return _0x5ab55b[_0xa3e9('0x58')](_0x4f1458);}})['then'](function(_0x4dc9a2){if(_0x4dc9a2){_0x376748=_0x4dc9a2['length'];if(!_0x2d9153['query'][_0xa3e9('0x56')](_0xa3e9('0x40'))){_0x4f1458[_0xa3e9('0x2b')]=qs[_0xa3e9('0x2b')](_0x2d9153[_0xa3e9('0x3a')][_0xa3e9('0x2b')]);_0x4f1458[_0xa3e9('0x29')]=qs[_0xa3e9('0x29')](_0x2d9153[_0xa3e9('0x3a')][_0xa3e9('0x29')]);}return _0x5ab55b[_0xa3e9('0x58')](_0x4f1458);}})[_0xa3e9('0x1c')](function(_0x3a5270){if(_0x3a5270){return _0x3a5270?{'count':_0x376748,'rows':_0x3a5270}:null;}})[_0xa3e9('0x1c')](respondWithResult(_0x5ccd7b,null))[_0xa3e9('0x26')](handleError(_0x5ccd7b,null));};
\ No newline at end of file