f8dfbba6b1ec132d5e7955339578755dbeb12089
[motion2.git] / server / api / plugin / plugin.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x4525=['ioredis','../../components/auth/service','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','register','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','save','update','then','destroy','get','Plugins','UserProfileResource','error','stack','name','index','map','Plugin','rawAttributes','fieldName','type','key','model','keys','query','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter','merge','options','count','includeAll','rows','catch','show','params','find','join','root','server/files/plugins','format','basename','createWriteStream','code','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','**/*','dirname','node_modules/**/*','attachments/**/*','existsSync','Plugin\x20not\x20found','%s.zip','unlinkSync','info','Download\x20completed','Temporary\x20file\x20removed','upload','file','filename','extname','0777','readdirSync','Invalid\x20plugin\x20structure','lstatSync','isFile','some','readFileSync','manifest.json','parse','undefined','Invalid\x20manifest:\x20type\x20missing','Invalid\x20manifest:\x20version\x20not\x20specified','parameters','html','views','Invalid\x20manifest:\x20views\x20missing','admin','agent','Invalid\x20manifest:\x20no\x20view\x20specified','scriptName','scriptPath','Invalid\x20manifest:\x20invalid\x20type','description','sidebar','always','icon','icon-apps','version','plugins','test','Warning:\x20agent\x20view\x20not\x20specified','script','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','send','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','delete','resolve','port','\x27PORT\x27\x20parameter\x20not\x20specified','hostname','http://localhost:','encoding','method','%s%s','headers','content-length','content-type','endsWith','statusCode','webhookPost','\x27PATH\x27\x20parameter\x20not\x20specified','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','path','sox','to-csv','ejs','squel','jsforce','desk.js','querystring','papaparse','archiver'];(function(_0x1fbe59,_0x45dd45){var _0x315b32=function(_0x403fe){while(--_0x403fe){_0x1fbe59['push'](_0x1fbe59['shift']());}};_0x315b32(++_0x45dd45);}(_0x4525,0x133));var _0x5452=function(_0x3a24c3,_0x4d15d8){_0x3a24c3=_0x3a24c3-0x0;var _0x43d391=_0x4525[_0x3a24c3];return _0x43d391;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x5452('0x0'));var rimraf=require(_0x5452('0x1'));var zipdir=require(_0x5452('0x2'));var jsonpatch=require(_0x5452('0x3'));var rp=require(_0x5452('0x4'));var moment=require('moment');var BPromise=require(_0x5452('0x5'));var Mustache=require('mustache');var util=require(_0x5452('0x6'));var path=require(_0x5452('0x7'));var sox=require(_0x5452('0x8'));var csv=require(_0x5452('0x9'));var ejs=require(_0x5452('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0x5452('0xb'));var crypto=require('crypto');var jsforce=require(_0x5452('0xc'));var deskjs=require(_0x5452('0xd'));var toCsv=require(_0x5452('0x9'));var querystring=require(_0x5452('0xe'));var Papa=require(_0x5452('0xf'));var extract=require('extract-zip');var rimraf=require('rimraf');var archiver=require(_0x5452('0x10'));var Redis=require(_0x5452('0x11'));var authService=require(_0x5452('0x12'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5452('0x13'));var logger=require(_0x5452('0x14'))('api');var utils=require(_0x5452('0x15'));var config=require(_0x5452('0x16'));var db=require(_0x5452('0x17'))['db'];config[_0x5452('0x18')]=_[_0x5452('0x19')](config[_0x5452('0x18')],{'host':'localhost','port':0x18eb});var socket=require(_0x5452('0x1a'))(new Redis(config[_0x5452('0x18')]));require('./plugin.socket')[_0x5452('0x1b')](socket);function respondWithStatusCode(_0x580665,_0x572e5b){_0x572e5b=_0x572e5b||0xcc;return function(_0x9b48bc){if(_0x9b48bc){return _0x580665[_0x5452('0x1c')](_0x572e5b);}return _0x580665[_0x5452('0x1d')](_0x572e5b)[_0x5452('0x1e')]();};}function respondWithResult(_0x57a859,_0x448840){_0x448840=_0x448840||0xc8;return function(_0x351a72){if(_0x351a72){return _0x57a859[_0x5452('0x1d')](_0x448840)[_0x5452('0x1f')](_0x351a72);}};}function respondWithFilteredResult(_0x48a974,_0x5c49e8){return function(_0x1bce02){if(_0x1bce02){var _0x3ca82c=_0x1bce02['count'],_0x12e473=_0x5c49e8[_0x5452('0x20')],_0x470bc7=_0x5c49e8[_0x5452('0x20')]+_0x5c49e8[_0x5452('0x21')],_0x4ca6d0;if(_0x470bc7>=_0x3ca82c){_0x470bc7=_0x3ca82c;_0x4ca6d0=0xc8;}else{_0x4ca6d0=0xce;}_0x48a974['status'](_0x4ca6d0);return _0x48a974[_0x5452('0x22')](_0x5452('0x23'),_0x12e473+'-'+_0x470bc7+'/'+_0x3ca82c)[_0x5452('0x1f')](_0x1bce02);}return null;};}function patchUpdates(_0x5b2dd1){return function(_0x2b10c4){try{jsonpatch[_0x5452('0x24')](_0x2b10c4,_0x5b2dd1,!![]);}catch(_0x44cd93){return BPromise['reject'](_0x44cd93);}return _0x2b10c4[_0x5452('0x25')]();};}function saveUpdates(_0x237f04,_0xf8491e){return function(_0x5beb76){if(_0x5beb76){return _0x5beb76[_0x5452('0x26')](_0x237f04)[_0x5452('0x27')](function(_0x587f53){return _0x587f53;});}return null;};}function removeEntity(_0x3382db,_0x102b6e){return function(_0xd7a779){if(_0xd7a779){return _0xd7a779[_0x5452('0x28')]()[_0x5452('0x27')](function(){var _0x231d27=_0xd7a779[_0x5452('0x29')]({'plain':!![]});var _0x182408=_0x5452('0x2a');return db[_0x5452('0x2b')][_0x5452('0x28')]({'where':{'type':_0x182408,'resourceId':_0x231d27['id']}})[_0x5452('0x27')](function(){return _0xd7a779;});})['then'](function(){_0x3382db[_0x5452('0x1d')](0xcc)[_0x5452('0x1e')]();});}};}function handleEntityNotFound(_0x573dd4,_0x1878fc){return function(_0x241b87){if(!_0x241b87){_0x573dd4[_0x5452('0x1c')](0x194);}return _0x241b87;};}function handleError(_0x3ef6e3,_0x37c41d){_0x37c41d=_0x37c41d||0x1f4;return function(_0x519f7b){logger[_0x5452('0x2c')](_0x519f7b[_0x5452('0x2d')]);if(_0x519f7b[_0x5452('0x2e')]){delete _0x519f7b[_0x5452('0x2e')];}_0x3ef6e3['status'](_0x37c41d)['send'](_0x519f7b);};}exports[_0x5452('0x2f')]=function(_0x3b6970,_0x1fd0ea){var _0x376cbb={},_0x4ecbad={},_0x1f1bf7={'count':0x0,'rows':[]};var _0x533dce=_[_0x5452('0x30')](db[_0x5452('0x31')][_0x5452('0x32')],function(_0x3fb3e6){return{'name':_0x3fb3e6[_0x5452('0x33')],'type':_0x3fb3e6[_0x5452('0x34')][_0x5452('0x35')]};});_0x4ecbad[_0x5452('0x36')]=_[_0x5452('0x30')](_0x533dce,'name');_0x4ecbad['query']=_[_0x5452('0x37')](_0x3b6970[_0x5452('0x38')]);_0x4ecbad['filters']=_['intersection'](_0x4ecbad[_0x5452('0x36')],_0x4ecbad[_0x5452('0x38')]);_0x376cbb[_0x5452('0x39')]=_[_0x5452('0x3a')](_0x4ecbad[_0x5452('0x36')],qs[_0x5452('0x3b')](_0x3b6970['query'][_0x5452('0x3b')]));_0x376cbb[_0x5452('0x39')]=_0x376cbb['attributes'][_0x5452('0x3c')]?_0x376cbb[_0x5452('0x39')]:_0x4ecbad[_0x5452('0x36')];if(!_0x3b6970[_0x5452('0x38')][_0x5452('0x3d')](_0x5452('0x3e'))){_0x376cbb[_0x5452('0x21')]=qs[_0x5452('0x21')](_0x3b6970[_0x5452('0x38')][_0x5452('0x21')]);_0x376cbb[_0x5452('0x20')]=qs[_0x5452('0x20')](_0x3b6970[_0x5452('0x38')][_0x5452('0x20')]);}_0x376cbb[_0x5452('0x3f')]=qs[_0x5452('0x40')](_0x3b6970[_0x5452('0x38')][_0x5452('0x40')]);_0x376cbb['where']=qs[_0x5452('0x41')](_[_0x5452('0x42')](_0x3b6970[_0x5452('0x38')],_0x4ecbad[_0x5452('0x41')]),_0x533dce);if(_0x3b6970[_0x5452('0x38')][_0x5452('0x43')]){_0x376cbb['where']=_[_0x5452('0x44')](_0x376cbb['where'],{'$or':_[_0x5452('0x30')](_0x533dce,function(_0x58c38d){if(_0x58c38d[_0x5452('0x34')]!=='VIRTUAL'){var _0x35a372={};_0x35a372[_0x58c38d[_0x5452('0x2e')]]={'$like':'%'+_0x3b6970[_0x5452('0x38')][_0x5452('0x43')]+'%'};return _0x35a372;}})});}_0x376cbb=_[_0x5452('0x44')]({},_0x376cbb,_0x3b6970[_0x5452('0x45')]);var _0x431234={'where':_0x376cbb['where']};return db[_0x5452('0x31')][_0x5452('0x46')](_0x431234)['then'](function(_0x384ba7){_0x1f1bf7[_0x5452('0x46')]=_0x384ba7;if(_0x3b6970[_0x5452('0x38')][_0x5452('0x47')]){_0x376cbb['include']=[{'all':!![]}];}return db[_0x5452('0x31')]['findAll'](_0x376cbb);})[_0x5452('0x27')](function(_0x50e182){_0x1f1bf7[_0x5452('0x48')]=_0x50e182;return _0x1f1bf7;})['then'](respondWithFilteredResult(_0x1fd0ea,_0x376cbb))[_0x5452('0x49')](handleError(_0x1fd0ea,null));};exports[_0x5452('0x4a')]=function(_0x1c2956,_0x4e8259){var _0x501ae7={'raw':!![],'where':{'id':_0x1c2956[_0x5452('0x4b')]['id']}},_0xc5a256={};_0xc5a256[_0x5452('0x36')]=_[_0x5452('0x37')](db['Plugin'][_0x5452('0x32')]);_0xc5a256[_0x5452('0x38')]=_['keys'](_0x1c2956['query']);_0xc5a256['filters']=_['intersection'](_0xc5a256[_0x5452('0x36')],_0xc5a256['query']);_0x501ae7[_0x5452('0x39')]=_[_0x5452('0x3a')](_0xc5a256['model'],qs[_0x5452('0x3b')](_0x1c2956[_0x5452('0x38')][_0x5452('0x3b')]));_0x501ae7[_0x5452('0x39')]=_0x501ae7[_0x5452('0x39')][_0x5452('0x3c')]?_0x501ae7[_0x5452('0x39')]:_0xc5a256['model'];if(_0x1c2956[_0x5452('0x38')][_0x5452('0x47')]){_0x501ae7['include']=[{'all':!![]}];}_0x501ae7=_[_0x5452('0x44')]({},_0x501ae7,_0x1c2956[_0x5452('0x45')]);return db[_0x5452('0x31')][_0x5452('0x4c')](_0x501ae7)['then'](handleEntityNotFound(_0x4e8259,null))[_0x5452('0x27')](respondWithResult(_0x4e8259,null))[_0x5452('0x49')](handleError(_0x4e8259,null));};exports['download']=function(_0x2e5686,_0x541122,_0xad81ec){return db['Plugin'][_0x5452('0x4c')]({'where':{'id':_0x2e5686[_0x5452('0x4b')]['id']},'attributes':[_0x5452('0x2e'),_0x5452('0x7')],'raw':!![]})[_0x5452('0x27')](handleEntityNotFound(_0x541122,null))[_0x5452('0x27')](function(_0x54bf35){if(_0x54bf35){var _0x293d11=path[_0x5452('0x4d')](config[_0x5452('0x4e')],_0x5452('0x4f'),util[_0x5452('0x50')]('%s.zip',path[_0x5452('0x51')](_0x54bf35[_0x5452('0x7')])));var _0x567358=fs[_0x5452('0x52')](_0x293d11);var _0x470c76=archiver('zip',{'zlib':{'level':0x9}});_0x470c76['on']('warning',function(_0x46f11f){if(_0x46f11f[_0x5452('0x53')]===_0x5452('0x54')){logger[_0x5452('0x2c')](_0x46f11f);}else{throw new db[(_0x5452('0x55'))][(_0x5452('0x56'))]('Error\x20while\x20generating\x20the\x20zip\x20archive');}});_0x470c76['on'](_0x5452('0x2c'),function(_0x7a4d5e){throw new db[(_0x5452('0x55'))]['Error'](_0x5452('0x57'));});_0x470c76['pipe'](_0x567358);_0x470c76['glob'](_0x5452('0x58'),{'cwd':path[_0x5452('0x4d')](config['root'],_0x5452('0x4f'),path[_0x5452('0x59')](_0x54bf35[_0x5452('0x7')])),'ignore':[path[_0x5452('0x4d')](path[_0x5452('0x51')](_0x54bf35[_0x5452('0x7')]),_0x5452('0x5a')),path['join'](path[_0x5452('0x51')](_0x54bf35[_0x5452('0x7')]),_0x5452('0x5b'))],'nodir':!![]})['finalize']();_0x567358['on']('close',function(){if(!fs[_0x5452('0x5c')](_0x293d11)){throw new db[(_0x5452('0x55'))][(_0x5452('0x56'))](_0x5452('0x5d'));}return _0x541122['download'](_0x293d11,util['format'](_0x5452('0x5e'),path[_0x5452('0x51')](_0x54bf35[_0x5452('0x7')])),function(_0x30dbc2){if(_0x30dbc2){throw new db['Sequelize'][(_0x5452('0x56'))]('Error\x20while\x20downloading\x20the\x20plugin');}fs[_0x5452('0x5f')](_0x293d11);logger[_0x5452('0x60')](_0x5452('0x61'));logger[_0x5452('0x60')](_0x5452('0x62'));});});}return null;})[_0x5452('0x49')](handleError(_0x541122,null));};exports[_0x5452('0x63')]=function(_0x47ffcf,_0xf0c93e,_0x39c2fe){var _0x28376f=path['basename'](_0x47ffcf[_0x5452('0x64')][_0x5452('0x65')],path[_0x5452('0x66')](_0x47ffcf['file'][_0x5452('0x65')]));var _0x541fe9=path[_0x5452('0x4d')](config[_0x5452('0x4e')],_0x5452('0x4f'),_0x47ffcf[_0x5452('0x64')][_0x5452('0x65')]);var _0x51f0cb=path[_0x5452('0x4d')](config['root'],_0x5452('0x4f'),_0x28376f);logger['info']('Plugin\x20upload\x20filepath:\x20%s',_0x541fe9);logger[_0x5452('0x60')]('Plugin\x20upload\x20destination:\x20%s',_0x51f0cb);try{fs['chmodSync'](_0x541fe9,parseInt(_0x5452('0x67'),0x8));extract(_0x541fe9,{'dir':_0x51f0cb},function(_0x4ba2de){if(_0x4ba2de){logger['error'](_0x4ba2de);handleError(_0x4ba2de,!![]);};var _0x4a192d=fs[_0x5452('0x68')](_0x51f0cb);if(_0x4a192d[_0x5452('0x3c')]>0x1){removeReferences(_0x541fe9,_0x51f0cb);logger[_0x5452('0x2c')](_0x5452('0x69'));return _0x39c2fe(new Error('Invalid\x20plugin\x20structure'));}var _0x1342d9=fs[_0x5452('0x6a')](path[_0x5452('0x4d')](_0x51f0cb,_0x4a192d[0x0]));if(_0x1342d9[_0x5452('0x6b')]()){removeReferences(_0x541fe9,_0x51f0cb);logger[_0x5452('0x2c')](_0x5452('0x69'));return _0x39c2fe(new Error(_0x5452('0x69')));}if(_0x1342d9['isDirectory']()){var _0x2d4be9=fs[_0x5452('0x68')](path['join'](_0x51f0cb,_0x4a192d[0x0]));if(_0x2d4be9['length']===0x0){removeReferences(_0x541fe9,_0x51f0cb);logger[_0x5452('0x2c')](_0x5452('0x69'));return _0x39c2fe(new Error(_0x5452('0x69')));}var _0x3bb962=_0x2d4be9[_0x5452('0x6c')](function(_0x3239de){return _0x3239de==='manifest.json';});if(!_0x3bb962){return _0x39c2fe(new Error('Plugin\x20manifest\x20missing'));}var _0x45ea6b=fs[_0x5452('0x6d')](path[_0x5452('0x4d')](_0x51f0cb,_0x4a192d[0x0],_0x5452('0x6e')));var _0x4d9eab=JSON[_0x5452('0x6f')](_0x45ea6b);if(_0x5452('0x70')==typeof _0x4d9eab[_0x5452('0x2e')]){return _0x39c2fe(new Error('Invalid\x20manifest:\x20name\x20missing'));}if('undefined'==typeof _0x4d9eab[_0x5452('0x34')]){return _0x39c2fe(new Error(_0x5452('0x71')));}if(_0x5452('0x70')==typeof _0x4d9eab['version']){return _0x39c2fe(new Error(_0x5452('0x72')));}if('undefined'==typeof _0x4d9eab[_0x5452('0x73')]){return _0x39c2fe(new Error('Invalid\x20manifest:\x20parameters\x20missing'));}if(_0x4d9eab[_0x5452('0x34')]===_0x5452('0x74')){if('undefined'==typeof _0x4d9eab[_0x5452('0x73')][_0x5452('0x75')]){return _0x39c2fe(new Error(_0x5452('0x76')));}if(_0x5452('0x70')==typeof _0x4d9eab[_0x5452('0x73')][_0x5452('0x75')][_0x5452('0x77')]&&'undefined'==typeof _0x4d9eab['parameters']['views'][_0x5452('0x78')]){return _0x39c2fe(new Error(_0x5452('0x79')));}}else if(_0x4d9eab[_0x5452('0x34')]==='script'){if('undefined'==typeof _0x4d9eab[_0x5452('0x73')][_0x5452('0x7a')]){return _0x39c2fe(new Error('Invalid\x20manifest:\x20script\x20name\x20missing'));}if('undefined'==typeof _0x4d9eab[_0x5452('0x73')][_0x5452('0x7b')]){return _0x39c2fe(new Error('Invalid\x20manifest:\x20script\x20path\x20missing'));}}else{return _0x39c2fe(new Error(_0x5452('0x7c')));}var _0x169299=_0x4d9eab[_0x5452('0x2e')];var _0x11c5fe=_0x4d9eab[_0x5452('0x7d')];var _0x14f202=_0x4d9eab[_0x5452('0x34')];var _0x183e7e=_0x4d9eab[_0x5452('0x7e')]?_0x4d9eab[_0x5452('0x7e')]:_0x5452('0x7f');var _0x5615c2=_0x4d9eab['icon']?_0x4d9eab[_0x5452('0x80')]:_0x5452('0x81');var _0x659c2c='';var _0x21eb62='';var _0x334c68='';var _0xc931a3='';var _0x473977=_0x4d9eab[_0x5452('0x82')];if(_0x14f202===_0x5452('0x74')){if(_0x5452('0x70')!=typeof _0x4d9eab[_0x5452('0x73')][_0x5452('0x75')][_0x5452('0x77')]){var _0x2cc35f=_0x4d9eab['parameters'][_0x5452('0x75')][_0x5452('0x77')];if(!/^(f|ht)tps?:\/\//i['test'](_0x2cc35f)){_0x659c2c=path[_0x5452('0x4d')](_0x5452('0x83'),_0x28376f,_0x4a192d[0x0],_0x2cc35f);}else{_0x659c2c=_0x2cc35f;}}else{logger[_0x5452('0x60')]('Warning:\x20admin\x20view\x20not\x20specified');}if('undefined'!=typeof _0x4d9eab['parameters'][_0x5452('0x75')][_0x5452('0x78')]){var _0x41920a=_0x4d9eab[_0x5452('0x73')][_0x5452('0x75')][_0x5452('0x78')];if(!/^(f|ht)tps?:\/\//i[_0x5452('0x84')](_0x41920a)){_0x21eb62=path[_0x5452('0x4d')](_0x5452('0x83'),_0x28376f,_0x4a192d[0x0],_0x41920a);}else{_0x21eb62=_0x41920a;}}else{logger[_0x5452('0x60')](_0x5452('0x85'));}}else if(_0x14f202===_0x5452('0x86')){_0x334c68=_0x4d9eab[_0x5452('0x73')]['scriptName'];_0xc931a3=_0x4d9eab[_0x5452('0x73')]['scriptPath'];if(_0x5452('0x70')!=typeof _0x4d9eab[_0x5452('0x73')][_0x5452('0x75')]){if('undefined'!=typeof _0x4d9eab[_0x5452('0x73')][_0x5452('0x75')][_0x5452('0x77')]){var _0x2cc35f=_0x4d9eab['parameters'][_0x5452('0x75')][_0x5452('0x77')];if(!/^(f|ht)tps?:\/\//i[_0x5452('0x84')](_0x2cc35f)){_0x659c2c=path[_0x5452('0x4d')](_0x5452('0x83'),_0x28376f,_0x4a192d[0x0],_0x2cc35f);}else{_0x659c2c=_0x2cc35f;}}if(_0x5452('0x70')!=typeof _0x4d9eab[_0x5452('0x73')]['views']['agent']){var _0x41920a=_0x4d9eab[_0x5452('0x73')]['views']['agent'];if(!/^(f|ht)tps?:\/\//i[_0x5452('0x84')](_0x41920a)){_0x21eb62=path[_0x5452('0x4d')](_0x5452('0x83'),_0x28376f,_0x4a192d[0x0],_0x41920a);}else{_0x21eb62=_0x41920a;}}}}var _0x52ec12={'name':_0x169299,'description':_0x11c5fe,'path':path[_0x5452('0x4d')](_0x28376f,_0x4a192d[0x0]),'type':_0x14f202,'sidebar':_0x183e7e,'icon':_0x5615c2,'adminUrl':_0x659c2c,'agentUrl':_0x21eb62,'scriptName':_0x334c68,'scriptPath':_0xc931a3,'version':_0x473977};removeReferences(_0x541fe9,null);return db[_0x5452('0x31')][_0x5452('0x87')](_0x52ec12)[_0x5452('0x27')](function(_0x130a2c){var _0x2cab53={'role':_0x47ffcf[_0x5452('0x88')]['role'],'userProfileId':_0x47ffcf[_0x5452('0x88')]['userProfileId']};if(!_0x2cab53)throw new Error(_0x5452('0x89'));if(_0x2cab53[_0x5452('0x8a')]===_0x5452('0x8b')){var _0x4d857c=_0x130a2c[_0x5452('0x29')]({'plain':!![]});return db[_0x5452('0x8c')][_0x5452('0x4c')]({'where':{'name':_0x5452('0x2a'),'userProfileId':_0x2cab53['userProfileId']},'raw':!![]})[_0x5452('0x27')](function(_0x3d1199){if(_0x3d1199&&_0x3d1199[_0x5452('0x8d')]===0x0){return db[_0x5452('0x2b')][_0x5452('0x87')]({'name':_0x4d857c[_0x5452('0x2e')],'resourceId':_0x4d857c['id'],'type':_0x3d1199[_0x5452('0x2e')],'sectionId':_0x3d1199['id']},{})[_0x5452('0x27')](function(){return _0x130a2c;});}else{return _0x130a2c;}})[_0x5452('0x49')](function(_0x5acc90){logger['error'](_0x5452('0x8e'),_0x5acc90);throw _0x5acc90;});}return _0x130a2c;})[_0x5452('0x27')](respondWithResult(_0xf0c93e,null))[_0x5452('0x49')](handleError(_0xf0c93e,null));}});}catch(_0x504f34){_0xf0c93e[_0x5452('0x1d')](0x1f4)[_0x5452('0x8f')](_0x504f34);}};function removeReferences(_0x169f29,_0xd192c6){try{if(_0x169f29){fs[_0x5452('0x5f')](_0x169f29);logger[_0x5452('0x60')](_0x5452('0x90'));}if(_0xd192c6){rimraf(_0xd192c6,function(){});logger[_0x5452('0x60')](_0x5452('0x91'));}}catch(_0x16cf83){logger[_0x5452('0x2c')](_0x16cf83);}}exports[_0x5452('0x26')]=function(_0x3be660,_0x1b7423,_0x1beef8){return db[_0x5452('0x31')][_0x5452('0x4c')]({'where':{'id':_0x3be660[_0x5452('0x4b')]['id']}})[_0x5452('0x27')](handleEntityNotFound(_0x1b7423,null))['then'](saveUpdates(_0x3be660[_0x5452('0x88')],null))[_0x5452('0x27')](respondWithResult(_0x1b7423,null))[_0x5452('0x49')](handleError(_0x1b7423,null));};exports[_0x5452('0x92')]=function(_0x1de489,_0x1db1d8,_0x452d6d){return db[_0x5452('0x31')]['find']({'where':{'id':_0x1de489['params']['id']}})[_0x5452('0x27')](function(_0x446d1c){if(_0x446d1c){return _0x446d1c['destroy']();}})[_0x5452('0x27')](function(_0x55278c){rimraf(path[_0x5452('0x4d')](config[_0x5452('0x4e')],_0x5452('0x4f'),path[_0x5452('0x59')](_0x55278c[_0x5452('0x7')])),function(){});return _0x55278c;})[_0x5452('0x27')](handleEntityNotFound(_0x1db1d8,null))[_0x5452('0x27')](respondWithStatusCode(_0x1db1d8,null))[_0x5452('0x49')](handleError(_0x1db1d8,null));};exports['webhookGet']=function(_0x158452,_0x26cb48,_0x3ee19a){return BPromise[_0x5452('0x93')]()[_0x5452('0x27')](function(){if(!_0x158452[_0x5452('0x38')][_0x5452('0x7')]){throw new Error('\x27PATH\x27\x20parameter\x20not\x20specified');}if(!_0x158452[_0x5452('0x38')][_0x5452('0x94')]){throw new Error(_0x5452('0x95'));}var _0x1c21c1=_0x158452[_0x5452('0x38')][_0x5452('0x96')]?_0x158452[_0x5452('0x38')][_0x5452('0x96')]+':'+_0x158452[_0x5452('0x38')][_0x5452('0x94')]:_0x5452('0x97')+_0x158452[_0x5452('0x38')]['port'];var _0x25a0e7=_0x158452['query'][_0x5452('0x1f')]?_0x158452['query']['json']:!![];var _0x399aa0=_0x158452[_0x5452('0x38')][_0x5452('0x98')]?_0x158452[_0x5452('0x38')][_0x5452('0x98')]:null;var _0x122a5a={'method':_0x158452[_0x5452('0x99')],'uri':util[_0x5452('0x50')](_0x5452('0x9a'),_0x1c21c1,_0x158452['query'][_0x5452('0x7')]),'json':_0x25a0e7,'resolveWithFullResponse':!![],'encoding':_0x399aa0,'qs':_0x158452['query']};if(_0x158452[_0x5452('0x9b')]){_0x122a5a['headers']=_0x158452[_0x5452('0x9b')];if(_0x122a5a['headers'][_0x5452('0x9c')]){delete _0x122a5a['headers'][_0x5452('0x9c')];}}if(_0x122a5a[_0x5452('0x9b')][_0x5452('0x9d')]){delete _0x122a5a['headers'][_0x5452('0x9d')];}return rp(_0x122a5a);})[_0x5452('0x27')](function(_0x1f9999){if(_0x1f9999){_0x26cb48[_0x5452('0x22')](_0x1f9999[_0x5452('0x9b')]);logger['info'](_0x1f9999[_0x5452('0x88')]);if(_[_0x5452('0x9e')](_0x158452[_0x5452('0x38')][_0x5452('0x7')],'download')&&_0x1f9999[_0x5452('0x9f')]==0x1f4){return _0x26cb48['sendStatus'](_0x1f9999[_0x5452('0x9f')]);}else{return _0x26cb48['status'](_0x1f9999[_0x5452('0x9f')])[_0x5452('0x8f')](_0x1f9999[_0x5452('0x88')]);}}else{return _0x26cb48['sendStatus'](0xc8);}})['catch'](handleError(_0x26cb48,null));};exports[_0x5452('0xa0')]=function(_0x2bd7c8,_0x1304a0,_0x2fa6c1){return BPromise['resolve']()[_0x5452('0x27')](function(){if(!_0x2bd7c8[_0x5452('0x38')][_0x5452('0x7')]){throw new Error(_0x5452('0xa1'));}if(!_0x2bd7c8['query'][_0x5452('0x94')]){throw new Error(_0x5452('0x95'));}var _0x5db2c9=_0x2bd7c8[_0x5452('0x38')]['hostname']?_0x2bd7c8[_0x5452('0x38')]['hostname']+':'+_0x2bd7c8['query']['port']:_0x5452('0x97')+_0x2bd7c8['query'][_0x5452('0x94')];var _0x56a3f8=_0x2bd7c8['query'][_0x5452('0x1f')]?_0x2bd7c8[_0x5452('0x38')][_0x5452('0x1f')]:!![];var _0x552742=_0x2bd7c8[_0x5452('0x38')][_0x5452('0x98')]?_0x2bd7c8[_0x5452('0x38')]['encoding']:null;var _0x57afdd={'method':_0x2bd7c8[_0x5452('0x99')],'uri':util[_0x5452('0x50')](_0x5452('0x9a'),_0x5db2c9,_0x2bd7c8['query']['path']),'json':_0x56a3f8,'resolveWithFullResponse':!![],'encoding':_0x552742,'body':_0x2bd7c8[_0x5452('0x88')]};if(_0x2bd7c8[_0x5452('0x9b')]){_0x57afdd['headers']=_0x2bd7c8[_0x5452('0x9b')];if(_0x57afdd[_0x5452('0x9b')]['content-length']){delete _0x57afdd[_0x5452('0x9b')][_0x5452('0x9c')];}}if(_0x57afdd[_0x5452('0x9b')][_0x5452('0x9d')]){delete _0x57afdd[_0x5452('0x9b')][_0x5452('0x9d')];}return rp(_0x57afdd);})[_0x5452('0x27')](function(_0x5d6238){if(_0x5d6238){_0x1304a0[_0x5452('0x22')](_0x5d6238[_0x5452('0x9b')]);logger[_0x5452('0x60')](_0x5d6238['body']);return _0x1304a0[_0x5452('0x1d')](_0x5d6238[_0x5452('0x9f')])['send'](_0x5d6238[_0x5452('0x88')]);}else{return _0x1304a0[_0x5452('0x1c')](0xc8);}})[_0x5452('0x49')](handleError(_0x1304a0,null));};