Built motion from commit (unavailable).|2.3.1
[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 _0x4f03=['extract-zip','archiver','../../components/parsers/qs','../../config/logger','../../mysqldb','redis','localhost','socket.io-emitter','./plugin.socket','register','sendStatus','status','json','count','offset','limit','set','Content-Range','reject','update','then','destroy','get','Plugins','UserProfileResource','end','error','name','rawAttributes','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','merge','map','type','field','filter','options','Plugin','includeAll','include','findAll','rows','catch','show','params','find','download','root','format','%s.zip','basename','createWriteStream','warning','ENOENT','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','Sequelize','pipe','glob','**/*','server/files/plugins','dirname','node_modules/**/*','join','finalize','existsSync','Plugin\x20not\x20found','Error\x20while\x20downloading\x20the\x20plugin','info','file','filename','extname','Plugin\x20upload\x20filepath:\x20%s','Plugin\x20upload\x20destination:\x20%s','chmodSync','0777','readdirSync','Invalid\x20plugin\x20structure','lstatSync','isFile','some','manifest.json','readFileSync','parse','undefined','Invalid\x20manifest:\x20name\x20missing','Invalid\x20manifest:\x20type\x20missing','version','Invalid\x20manifest:\x20version\x20not\x20specified','Invalid\x20manifest:\x20parameters\x20missing','html','views','Invalid\x20manifest:\x20views\x20missing','parameters','Invalid\x20manifest:\x20no\x20view\x20specified','script','Invalid\x20manifest:\x20script\x20name\x20missing','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','description','sidebar','always','icon','icon-apps','admin','test','plugins','Warning:\x20admin\x20view\x20not\x20specified','agent','scriptPath','create','body','role','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','send','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','resolve','\x27PATH\x27\x20parameter\x20not\x20specified','port','hostname','method','%s%s','headers','content-length','endsWith','statusCode','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','ioredis'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0x4f03,0x8e));var _0x34f0=function(_0x5c38cd,_0x5a6b4e){_0x5c38cd=_0x5c38cd-0x0;var _0xc985ef=_0x4f03[_0x5c38cd];return _0xc985ef;};'use strict';var pdf=require(_0x34f0('0x0'));var emlformat=require(_0x34f0('0x1'));var rimraf=require(_0x34f0('0x2'));var zipdir=require(_0x34f0('0x3'));var jsonpatch=require(_0x34f0('0x4'));var rp=require('request-promise');var moment=require(_0x34f0('0x5'));var BPromise=require(_0x34f0('0x6'));var Mustache=require(_0x34f0('0x7'));var util=require('util');var path=require(_0x34f0('0x8'));var sox=require(_0x34f0('0x9'));var csv=require(_0x34f0('0xa'));var ejs=require(_0x34f0('0xb'));var fs=require('fs');var _=require(_0x34f0('0xc'));var squel=require(_0x34f0('0xd'));var crypto=require(_0x34f0('0xe'));var jsforce=require(_0x34f0('0xf'));var deskjs=require(_0x34f0('0x10'));var toCsv=require(_0x34f0('0xa'));var querystring=require(_0x34f0('0x11'));var Papa=require(_0x34f0('0x12'));var authService=require(_0x34f0('0x13'));var hardwareService=require('../../config/license/hardware');var Redis=require(_0x34f0('0x14'));var extract=require(_0x34f0('0x15'));var rimraf=require(_0x34f0('0x2'));var archiver=require(_0x34f0('0x16'));var qs=require(_0x34f0('0x17'));var logger=require(_0x34f0('0x18'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x34f0('0x19'))['db'];config['redis']=_['defaults'](config[_0x34f0('0x1a')],{'host':_0x34f0('0x1b'),'port':0x18eb});var socket=require(_0x34f0('0x1c'))(new Redis(config[_0x34f0('0x1a')]));require(_0x34f0('0x1d'))[_0x34f0('0x1e')](socket);function respondWithStatusCode(_0x2fc0d6,_0x3b8452){_0x3b8452=_0x3b8452||0xcc;return function(_0x50c8c7){if(_0x50c8c7){return _0x2fc0d6[_0x34f0('0x1f')](_0x3b8452);}return _0x2fc0d6[_0x34f0('0x20')](_0x3b8452)['end']();};}function respondWithResult(_0x3e1c73,_0x25e43c){_0x25e43c=_0x25e43c||0xc8;return function(_0x292938){if(_0x292938){return _0x3e1c73[_0x34f0('0x20')](_0x25e43c)[_0x34f0('0x21')](_0x292938);}};}function respondWithFilteredResult(_0x21a4fe,_0x13386b){return function(_0x57f548){if(_0x57f548){var _0x33060b=_0x57f548[_0x34f0('0x22')],_0x1b6135=_0x13386b[_0x34f0('0x23')],_0x1b1876=_0x13386b[_0x34f0('0x23')]+_0x13386b[_0x34f0('0x24')],_0x5ef091;if(_0x1b1876>=_0x33060b){_0x1b1876=_0x33060b;_0x5ef091=0xc8;}else{_0x5ef091=0xce;}_0x21a4fe[_0x34f0('0x20')](_0x5ef091);return _0x21a4fe[_0x34f0('0x25')](_0x34f0('0x26'),_0x1b6135+'-'+_0x1b1876+'/'+_0x33060b)['json'](_0x57f548);}return null;};}function patchUpdates(_0x1b69ff){return function(_0x44ec42){try{jsonpatch['apply'](_0x44ec42,_0x1b69ff,!![]);}catch(_0x45d1e0){return BPromise[_0x34f0('0x27')](_0x45d1e0);}return _0x44ec42['save']();};}function saveUpdates(_0x2ae0bd,_0x12aead){return function(_0x2d32e8){if(_0x2d32e8){return _0x2d32e8[_0x34f0('0x28')](_0x2ae0bd)[_0x34f0('0x29')](function(_0x46767e){return _0x46767e;});}return null;};}function removeEntity(_0x3b1298,_0x386dd6){return function(_0x507366){if(_0x507366){return _0x507366[_0x34f0('0x2a')]()[_0x34f0('0x29')](function(){var _0x20d615=_0x507366[_0x34f0('0x2b')]({'plain':!![]});var _0x409336=_0x34f0('0x2c');return db[_0x34f0('0x2d')][_0x34f0('0x2a')]({'where':{'type':_0x409336,'resourceId':_0x20d615['id']}})['then'](function(){return _0x507366;});})[_0x34f0('0x29')](function(){_0x3b1298[_0x34f0('0x20')](0xcc)[_0x34f0('0x2e')]();});}};}function handleEntityNotFound(_0x13df57,_0x1c5c49){return function(_0x46385e){if(!_0x46385e){_0x13df57['sendStatus'](0x194);}return _0x46385e;};}function handleError(_0x17b255,_0x2cdb19){_0x2cdb19=_0x2cdb19||0x1f4;return function(_0x15c2ee){logger[_0x34f0('0x2f')](_0x15c2ee['stack']);if(_0x15c2ee[_0x34f0('0x30')]){delete _0x15c2ee[_0x34f0('0x30')];}_0x17b255['status'](_0x2cdb19)['send'](_0x15c2ee);};}exports['index']=function(_0x287723,_0x4ba482){var _0x29b954={},_0x1bec12={},_0xc27bc7={'count':0x0,'rows':[]};var _0x1825ff=db['Plugin'][_0x34f0('0x31')];_0x1bec12[_0x34f0('0x32')]=_[_0x34f0('0x33')](_0x1825ff);_0x1bec12[_0x34f0('0x34')]=_[_0x34f0('0x33')](_0x287723[_0x34f0('0x34')]);_0x1bec12[_0x34f0('0x35')]=_[_0x34f0('0x36')](_0x1bec12['model'],_0x1bec12['query']);_0x29b954[_0x34f0('0x37')]=_[_0x34f0('0x36')](_0x1bec12['model'],qs[_0x34f0('0x38')](_0x287723[_0x34f0('0x34')]['fields']));_0x29b954[_0x34f0('0x37')]=_0x29b954[_0x34f0('0x37')][_0x34f0('0x39')]?_0x29b954[_0x34f0('0x37')]:_0x1bec12['model'];if(!_0x287723[_0x34f0('0x34')][_0x34f0('0x3a')](_0x34f0('0x3b'))){_0x29b954[_0x34f0('0x24')]=qs['limit'](_0x287723['query'][_0x34f0('0x24')]);_0x29b954[_0x34f0('0x23')]=qs['offset'](_0x287723[_0x34f0('0x34')][_0x34f0('0x23')]);}_0x29b954[_0x34f0('0x3c')]=qs[_0x34f0('0x3d')](_0x287723['query']['sort']);_0x29b954[_0x34f0('0x3e')]=qs[_0x34f0('0x35')](_['pick'](_0x287723[_0x34f0('0x34')],_0x1bec12[_0x34f0('0x35')]));if(_0x287723[_0x34f0('0x34')]['filter']){_0x29b954[_0x34f0('0x3e')]=_[_0x34f0('0x3f')](_0x29b954[_0x34f0('0x3e')],{'$or':_[_0x34f0('0x40')](_0x1825ff,function(_0x318f12){if(_0x318f12[_0x34f0('0x41')]['key']!=='VIRTUAL'){var _0x3b51f1={};_0x3b51f1[_0x318f12[_0x34f0('0x42')]]={'$like':'%'+_0x287723['query'][_0x34f0('0x43')]+'%'};return _0x3b51f1;}})});}_0x29b954=_[_0x34f0('0x3f')]({},_0x29b954,_0x287723[_0x34f0('0x44')]);var _0xa621f0={'where':_0x29b954[_0x34f0('0x3e')]};return db[_0x34f0('0x45')][_0x34f0('0x22')](_0xa621f0)['then'](function(_0x28df47){_0xc27bc7[_0x34f0('0x22')]=_0x28df47;if(_0x287723[_0x34f0('0x34')][_0x34f0('0x46')]){_0x29b954[_0x34f0('0x47')]=[{'all':!![]}];}return db[_0x34f0('0x45')][_0x34f0('0x48')](_0x29b954);})[_0x34f0('0x29')](function(_0x30d758){_0xc27bc7[_0x34f0('0x49')]=_0x30d758;return _0xc27bc7;})[_0x34f0('0x29')](respondWithFilteredResult(_0x4ba482,_0x29b954))[_0x34f0('0x4a')](handleError(_0x4ba482,null));};exports[_0x34f0('0x4b')]=function(_0x58d459,_0x2139b0){var _0x1369d3={'raw':!![],'where':{'id':_0x58d459[_0x34f0('0x4c')]['id']}},_0x8c996c={};_0x8c996c['model']=_[_0x34f0('0x33')](db[_0x34f0('0x45')][_0x34f0('0x31')]);_0x8c996c[_0x34f0('0x34')]=_['keys'](_0x58d459[_0x34f0('0x34')]);_0x8c996c[_0x34f0('0x35')]=_['intersection'](_0x8c996c['model'],_0x8c996c['query']);_0x1369d3[_0x34f0('0x37')]=_[_0x34f0('0x36')](_0x8c996c['model'],qs[_0x34f0('0x38')](_0x58d459[_0x34f0('0x34')][_0x34f0('0x38')]));_0x1369d3['attributes']=_0x1369d3[_0x34f0('0x37')][_0x34f0('0x39')]?_0x1369d3[_0x34f0('0x37')]:_0x8c996c[_0x34f0('0x32')];if(_0x58d459[_0x34f0('0x34')][_0x34f0('0x46')]){_0x1369d3['include']=[{'all':!![]}];}_0x1369d3=_[_0x34f0('0x3f')]({},_0x1369d3,_0x58d459['options']);return db['Plugin'][_0x34f0('0x4d')](_0x1369d3)[_0x34f0('0x29')](handleEntityNotFound(_0x2139b0,null))[_0x34f0('0x29')](respondWithResult(_0x2139b0,null))['catch'](handleError(_0x2139b0,null));};exports[_0x34f0('0x4e')]=function(_0x5a8e20,_0x284e3a,_0x4aedba){return db[_0x34f0('0x45')][_0x34f0('0x4d')]({'where':{'id':_0x5a8e20[_0x34f0('0x4c')]['id']},'attributes':[_0x34f0('0x30'),_0x34f0('0x8')],'raw':!![]})[_0x34f0('0x29')](handleEntityNotFound(_0x284e3a,null))[_0x34f0('0x29')](function(_0x1effb6){if(_0x1effb6){var _0x1c1960=path['join'](config[_0x34f0('0x4f')],'server/files/plugins',util[_0x34f0('0x50')](_0x34f0('0x51'),path[_0x34f0('0x52')](_0x1effb6[_0x34f0('0x8')])));var _0x3ea572=fs[_0x34f0('0x53')](_0x1c1960);var _0x562ddb=archiver('zip',{'zlib':{'level':0x9}});_0x562ddb['on'](_0x34f0('0x54'),function(_0x5682cd){if(_0x5682cd['code']===_0x34f0('0x55')){logger[_0x34f0('0x2f')](_0x5682cd);}else{throw new db['Sequelize'][(_0x34f0('0x56'))](_0x34f0('0x57'));}});_0x562ddb['on'](_0x34f0('0x2f'),function(_0x337228){throw new db[(_0x34f0('0x58'))][(_0x34f0('0x56'))](_0x34f0('0x57'));});_0x562ddb[_0x34f0('0x59')](_0x3ea572);_0x562ddb[_0x34f0('0x5a')](_0x34f0('0x5b'),{'cwd':path['join'](config['root'],_0x34f0('0x5c'),path[_0x34f0('0x5d')](_0x1effb6['path'])),'ignore':[path['join'](path[_0x34f0('0x52')](_0x1effb6[_0x34f0('0x8')]),_0x34f0('0x5e')),path[_0x34f0('0x5f')](path[_0x34f0('0x52')](_0x1effb6['path']),'attachments/**/*')],'nodir':!![]})[_0x34f0('0x60')]();_0x3ea572['on']('close',function(){if(!fs[_0x34f0('0x61')](_0x1c1960)){throw new db[(_0x34f0('0x58'))][(_0x34f0('0x56'))](_0x34f0('0x62'));}return _0x284e3a[_0x34f0('0x4e')](_0x1c1960,util[_0x34f0('0x50')](_0x34f0('0x51'),path['basename'](_0x1effb6[_0x34f0('0x8')])),function(_0x5ef868){if(_0x5ef868){throw new db[(_0x34f0('0x58'))][(_0x34f0('0x56'))](_0x34f0('0x63'));}fs['unlinkSync'](_0x1c1960);logger[_0x34f0('0x64')]('Download\x20completed');logger[_0x34f0('0x64')]('Temporary\x20file\x20removed');});});}return null;})[_0x34f0('0x4a')](handleError(_0x284e3a,null));};exports['upload']=function(_0x12851c,_0x88a54b,_0x1a78f6){var _0x33d64c=path['basename'](_0x12851c[_0x34f0('0x65')][_0x34f0('0x66')],path[_0x34f0('0x67')](_0x12851c[_0x34f0('0x65')][_0x34f0('0x66')]));var _0x45a428=path['join'](config[_0x34f0('0x4f')],_0x34f0('0x5c'),_0x12851c[_0x34f0('0x65')][_0x34f0('0x66')]);var _0x865e4a=path[_0x34f0('0x5f')](config[_0x34f0('0x4f')],_0x34f0('0x5c'),_0x33d64c);logger['info'](_0x34f0('0x68'),_0x45a428);logger['info'](_0x34f0('0x69'),_0x865e4a);try{fs[_0x34f0('0x6a')](_0x45a428,parseInt(_0x34f0('0x6b'),0x8));extract(_0x45a428,{'dir':_0x865e4a},function(_0x80fe32){if(_0x80fe32){logger[_0x34f0('0x2f')](_0x80fe32);handleError(_0x80fe32,!![]);};var _0x21fde0=fs[_0x34f0('0x6c')](_0x865e4a);if(_0x21fde0['length']>0x1){removeReferences(_0x45a428,_0x865e4a);logger[_0x34f0('0x2f')](_0x34f0('0x6d'));return _0x1a78f6(new Error(_0x34f0('0x6d')));}var _0x24e651=fs[_0x34f0('0x6e')](path[_0x34f0('0x5f')](_0x865e4a,_0x21fde0[0x0]));if(_0x24e651[_0x34f0('0x6f')]()){removeReferences(_0x45a428,_0x865e4a);logger[_0x34f0('0x2f')](_0x34f0('0x6d'));return _0x1a78f6(new Error(_0x34f0('0x6d')));}if(_0x24e651['isDirectory']()){var _0x581b27=fs[_0x34f0('0x6c')](path[_0x34f0('0x5f')](_0x865e4a,_0x21fde0[0x0]));if(_0x581b27[_0x34f0('0x39')]===0x0){removeReferences(_0x45a428,_0x865e4a);logger[_0x34f0('0x2f')](_0x34f0('0x6d'));return _0x1a78f6(new Error(_0x34f0('0x6d')));}var _0x70b92=_0x581b27[_0x34f0('0x70')](function(_0x426555){return _0x426555===_0x34f0('0x71');});if(!_0x70b92){return _0x1a78f6(new Error('Plugin\x20manifest\x20missing'));}var _0x27a659=fs[_0x34f0('0x72')](path[_0x34f0('0x5f')](_0x865e4a,_0x21fde0[0x0],'manifest.json'));var _0x2d551e=JSON[_0x34f0('0x73')](_0x27a659);if(_0x34f0('0x74')==typeof _0x2d551e[_0x34f0('0x30')]){return _0x1a78f6(new Error(_0x34f0('0x75')));}if(_0x34f0('0x74')==typeof _0x2d551e[_0x34f0('0x41')]){return _0x1a78f6(new Error(_0x34f0('0x76')));}if('undefined'==typeof _0x2d551e[_0x34f0('0x77')]){return _0x1a78f6(new Error(_0x34f0('0x78')));}if(_0x34f0('0x74')==typeof _0x2d551e['parameters']){return _0x1a78f6(new Error(_0x34f0('0x79')));}if(_0x2d551e[_0x34f0('0x41')]===_0x34f0('0x7a')){if(_0x34f0('0x74')==typeof _0x2d551e['parameters'][_0x34f0('0x7b')]){return _0x1a78f6(new Error(_0x34f0('0x7c')));}if('undefined'==typeof _0x2d551e[_0x34f0('0x7d')][_0x34f0('0x7b')]['admin']&&_0x34f0('0x74')==typeof _0x2d551e[_0x34f0('0x7d')][_0x34f0('0x7b')]['agent']){return _0x1a78f6(new Error(_0x34f0('0x7e')));}}else if(_0x2d551e[_0x34f0('0x41')]===_0x34f0('0x7f')){if('undefined'==typeof _0x2d551e[_0x34f0('0x7d')]['scriptName']){return _0x1a78f6(new Error(_0x34f0('0x80')));}if('undefined'==typeof _0x2d551e[_0x34f0('0x7d')]['scriptPath']){return _0x1a78f6(new Error(_0x34f0('0x81')));}}else{return _0x1a78f6(new Error(_0x34f0('0x82')));}var _0xf6c708=_0x2d551e[_0x34f0('0x30')];var _0x46bddd=_0x2d551e[_0x34f0('0x83')];var _0x15047f=_0x2d551e[_0x34f0('0x41')];var _0x1a925d=_0x2d551e[_0x34f0('0x84')]?_0x2d551e['sidebar']:_0x34f0('0x85');var _0x295f96=_0x2d551e['icon']?_0x2d551e[_0x34f0('0x86')]:_0x34f0('0x87');var _0x1c36b2='';var _0x811dc3='';var _0x1f4e32='';var _0x557d08='';var _0x3dfbac=_0x2d551e[_0x34f0('0x77')];if(_0x15047f==='html'){if(_0x34f0('0x74')!=typeof _0x2d551e[_0x34f0('0x7d')][_0x34f0('0x7b')][_0x34f0('0x88')]){var _0x542e67=_0x2d551e[_0x34f0('0x7d')][_0x34f0('0x7b')][_0x34f0('0x88')];if(!/^(f|ht)tps?:\/\//i[_0x34f0('0x89')](_0x542e67)){_0x1c36b2=path[_0x34f0('0x5f')](_0x34f0('0x8a'),_0x33d64c,_0x21fde0[0x0],_0x542e67);}else{_0x1c36b2=_0x542e67;}}else{logger['info'](_0x34f0('0x8b'));}if('undefined'!=typeof _0x2d551e[_0x34f0('0x7d')]['views']['agent']){var _0x503a97=_0x2d551e['parameters'][_0x34f0('0x7b')][_0x34f0('0x8c')];if(!/^(f|ht)tps?:\/\//i[_0x34f0('0x89')](_0x503a97)){_0x811dc3=path[_0x34f0('0x5f')](_0x34f0('0x8a'),_0x33d64c,_0x21fde0[0x0],_0x503a97);}else{_0x811dc3=_0x503a97;}}else{logger[_0x34f0('0x64')]('Warning:\x20agent\x20view\x20not\x20specified');}}else if(_0x15047f===_0x34f0('0x7f')){_0x1f4e32=_0x2d551e['parameters']['scriptName'];_0x557d08=_0x2d551e[_0x34f0('0x7d')][_0x34f0('0x8d')];if(_0x34f0('0x74')!=typeof _0x2d551e[_0x34f0('0x7d')]['views']){if(_0x34f0('0x74')!=typeof _0x2d551e[_0x34f0('0x7d')][_0x34f0('0x7b')][_0x34f0('0x88')]){var _0x542e67=_0x2d551e[_0x34f0('0x7d')][_0x34f0('0x7b')][_0x34f0('0x88')];if(!/^(f|ht)tps?:\/\//i[_0x34f0('0x89')](_0x542e67)){_0x1c36b2=path[_0x34f0('0x5f')](_0x34f0('0x8a'),_0x33d64c,_0x21fde0[0x0],_0x542e67);}else{_0x1c36b2=_0x542e67;}}if(_0x34f0('0x74')!=typeof _0x2d551e[_0x34f0('0x7d')][_0x34f0('0x7b')][_0x34f0('0x8c')]){var _0x503a97=_0x2d551e[_0x34f0('0x7d')]['views'][_0x34f0('0x8c')];if(!/^(f|ht)tps?:\/\//i['test'](_0x503a97)){_0x811dc3=path[_0x34f0('0x5f')](_0x34f0('0x8a'),_0x33d64c,_0x21fde0[0x0],_0x503a97);}else{_0x811dc3=_0x503a97;}}}}var _0x1c18e7={'name':_0xf6c708,'description':_0x46bddd,'path':path[_0x34f0('0x5f')](_0x33d64c,_0x21fde0[0x0]),'type':_0x15047f,'sidebar':_0x1a925d,'icon':_0x295f96,'adminUrl':_0x1c36b2,'agentUrl':_0x811dc3,'scriptName':_0x1f4e32,'scriptPath':_0x557d08,'version':_0x3dfbac};removeReferences(_0x45a428,null);return db[_0x34f0('0x45')][_0x34f0('0x8e')](_0x1c18e7)[_0x34f0('0x29')](function(_0x6d15f4){var _0x5e2869={'role':_0x12851c[_0x34f0('0x8f')][_0x34f0('0x90')],'userProfileId':_0x12851c['body']['userProfileId']};if(!_0x5e2869)throw new Error(_0x34f0('0x91'));if(_0x5e2869[_0x34f0('0x90')]==='user'){var _0x390b01=_0x6d15f4[_0x34f0('0x2b')]({'plain':!![]});return db[_0x34f0('0x92')][_0x34f0('0x4d')]({'where':{'name':_0x34f0('0x2c'),'userProfileId':_0x5e2869[_0x34f0('0x93')]},'raw':!![]})['then'](function(_0x154926){if(_0x154926&&_0x154926[_0x34f0('0x94')]===0x0){return db[_0x34f0('0x2d')][_0x34f0('0x8e')]({'name':_0x390b01[_0x34f0('0x30')],'resourceId':_0x390b01['id'],'type':_0x154926[_0x34f0('0x30')],'sectionId':_0x154926['id']},{})[_0x34f0('0x29')](function(){return _0x6d15f4;});}else{return _0x6d15f4;}})[_0x34f0('0x4a')](function(_0x54f965){logger['error'](_0x34f0('0x95'),_0x54f965);throw _0x54f965;});}return _0x6d15f4;})[_0x34f0('0x29')](respondWithResult(_0x88a54b,null))[_0x34f0('0x4a')](handleError(_0x88a54b,null));}});}catch(_0x56fc83){_0x88a54b['status'](0x1f4)[_0x34f0('0x96')](_0x56fc83);}};function removeReferences(_0x56ebeb,_0xf37057){try{if(_0x56ebeb){fs['unlinkSync'](_0x56ebeb);logger[_0x34f0('0x64')](_0x34f0('0x97'));}if(_0xf37057){rimraf(_0xf37057,function(){});logger[_0x34f0('0x64')](_0x34f0('0x98'));}}catch(_0x37cb85){logger[_0x34f0('0x2f')](_0x37cb85);}}exports[_0x34f0('0x28')]=function(_0xee08f6,_0x4acd4e,_0x103223){return db[_0x34f0('0x45')]['find']({'where':{'id':_0xee08f6[_0x34f0('0x4c')]['id']}})[_0x34f0('0x29')](handleEntityNotFound(_0x4acd4e,null))[_0x34f0('0x29')](saveUpdates(_0xee08f6[_0x34f0('0x8f')],null))[_0x34f0('0x29')](respondWithResult(_0x4acd4e,null))[_0x34f0('0x4a')](handleError(_0x4acd4e,null));};exports['delete']=function(_0x3d9b8e,_0x13182c,_0x45979e){return db['Plugin']['find']({'where':{'id':_0x3d9b8e[_0x34f0('0x4c')]['id']}})[_0x34f0('0x29')](function(_0x37ac9f){if(_0x37ac9f){return _0x37ac9f[_0x34f0('0x2a')]();}})[_0x34f0('0x29')](function(_0x483818){rimraf(path[_0x34f0('0x5f')](config[_0x34f0('0x4f')],_0x34f0('0x5c'),path[_0x34f0('0x5d')](_0x483818['path'])),function(){});return _0x483818;})[_0x34f0('0x29')](handleEntityNotFound(_0x13182c,null))[_0x34f0('0x29')](respondWithStatusCode(_0x13182c,null))[_0x34f0('0x4a')](handleError(_0x13182c,null));};exports['webhookGet']=function(_0x2b569c,_0x282e4c,_0x3c51a9){return BPromise[_0x34f0('0x99')]()[_0x34f0('0x29')](function(){if(!_0x2b569c[_0x34f0('0x34')][_0x34f0('0x8')]){throw new Error(_0x34f0('0x9a'));}if(!_0x2b569c[_0x34f0('0x34')][_0x34f0('0x9b')]){throw new Error('\x27PORT\x27\x20parameter\x20not\x20specified');}var _0x27ec55=_0x2b569c[_0x34f0('0x34')][_0x34f0('0x9c')]?_0x2b569c[_0x34f0('0x34')]['hostname']+':'+_0x2b569c[_0x34f0('0x34')][_0x34f0('0x9b')]:'http://localhost:'+_0x2b569c[_0x34f0('0x34')][_0x34f0('0x9b')];var _0x55a453=_0x2b569c[_0x34f0('0x34')][_0x34f0('0x21')]?_0x2b569c[_0x34f0('0x34')][_0x34f0('0x21')]:!![];var _0x3950ed=_0x2b569c[_0x34f0('0x34')]['encoding']?_0x2b569c[_0x34f0('0x34')]['encoding']:null;var _0x4be45b={'method':_0x2b569c[_0x34f0('0x9d')],'uri':util[_0x34f0('0x50')](_0x34f0('0x9e'),_0x27ec55,_0x2b569c[_0x34f0('0x34')][_0x34f0('0x8')]),'json':_0x55a453,'resolveWithFullResponse':!![],'encoding':_0x3950ed,'qs':_0x2b569c[_0x34f0('0x34')]};if(_0x2b569c[_0x34f0('0x9f')]){_0x4be45b[_0x34f0('0x9f')]=_0x2b569c[_0x34f0('0x9f')];if(_0x4be45b[_0x34f0('0x9f')][_0x34f0('0xa0')]){delete _0x4be45b[_0x34f0('0x9f')][_0x34f0('0xa0')];}}return rp(_0x4be45b);})[_0x34f0('0x29')](function(_0x5daaaf){if(_0x5daaaf){_0x282e4c[_0x34f0('0x25')](_0x5daaaf['headers']);logger[_0x34f0('0x64')](_0x5daaaf[_0x34f0('0x8f')]);if(_[_0x34f0('0xa1')](_0x2b569c['query'][_0x34f0('0x8')],_0x34f0('0x4e'))&&_0x5daaaf[_0x34f0('0xa2')]==0x1f4){return _0x282e4c[_0x34f0('0x1f')](_0x5daaaf[_0x34f0('0xa2')]);}else{return _0x282e4c['status'](_0x5daaaf[_0x34f0('0xa2')])[_0x34f0('0x96')](_0x5daaaf['body']);}}else{return _0x282e4c[_0x34f0('0x1f')](0xc8);}})['catch'](handleError(_0x282e4c,null));};exports['webhookPost']=function(_0x548bd2,_0x923ee,_0x283ec3){return BPromise[_0x34f0('0x99')]()[_0x34f0('0x29')](function(){if(!_0x548bd2[_0x34f0('0x34')]['path']){throw new Error('\x27PATH\x27\x20parameter\x20not\x20specified');}if(!_0x548bd2['query'][_0x34f0('0x9b')]){throw new Error('\x27PORT\x27\x20parameter\x20not\x20specified');}var _0x303020=_0x548bd2[_0x34f0('0x34')][_0x34f0('0x9c')]?_0x548bd2[_0x34f0('0x34')][_0x34f0('0x9c')]+':'+_0x548bd2[_0x34f0('0x34')][_0x34f0('0x9b')]:'http://localhost:'+_0x548bd2[_0x34f0('0x34')][_0x34f0('0x9b')];var _0x4b4ef5=_0x548bd2[_0x34f0('0x34')][_0x34f0('0x21')]?_0x548bd2[_0x34f0('0x34')][_0x34f0('0x21')]:!![];var _0x413003=_0x548bd2['query']['encoding']?_0x548bd2['query']['encoding']:null;var _0x3452b3={'method':_0x548bd2[_0x34f0('0x9d')],'uri':util[_0x34f0('0x50')](_0x34f0('0x9e'),_0x303020,_0x548bd2['query'][_0x34f0('0x8')]),'json':_0x4b4ef5,'resolveWithFullResponse':!![],'encoding':_0x413003,'body':_0x548bd2[_0x34f0('0x8f')]};if(_0x548bd2[_0x34f0('0x9f')]){_0x3452b3['headers']=_0x548bd2[_0x34f0('0x9f')];if(_0x3452b3[_0x34f0('0x9f')]['content-length']){delete _0x3452b3[_0x34f0('0x9f')][_0x34f0('0xa0')];}}return rp(_0x3452b3);})[_0x34f0('0x29')](function(_0x250b8a){if(_0x250b8a){_0x923ee[_0x34f0('0x25')](_0x250b8a[_0x34f0('0x9f')]);logger[_0x34f0('0x64')](_0x250b8a['body']);return _0x923ee['status'](_0x250b8a[_0x34f0('0xa2')])[_0x34f0('0x96')](_0x250b8a[_0x34f0('0x8f')]);}else{return _0x923ee[_0x34f0('0x1f')](0xc8);}})[_0x34f0('0x4a')](handleError(_0x923ee,null));};