Built motion from commit 10af8726.|2.6.34
[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 _0x8144=['attributes','query','fields','length','hasOwnProperty','nolimit','order','sort','filters','pick','merge','VIRTUAL','options','Plugin','include','show','params','keys','intersection','download','join','root','server/files/plugins','%s.zip','basename','createWriteStream','warning','code','ENOENT','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','pipe','**/*','dirname','node_modules/**/*','attachments/**/*','close','existsSync','Sequelize','Plugin\x20not\x20found','format','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Download\x20completed','Temporary\x20file\x20removed','catch','file','filename','Plugin\x20upload\x20filepath:\x20%s','chmodSync','0777','lstatSync','Invalid\x20plugin\x20structure','isDirectory','some','manifest.json','Plugin\x20manifest\x20missing','readFileSync','Invalid\x20manifest:\x20type\x20missing','Invalid\x20manifest:\x20version\x20not\x20specified','parameters','Invalid\x20manifest:\x20parameters\x20missing','views','admin','agent','Invalid\x20manifest:\x20no\x20view\x20specified','script','scriptName','Invalid\x20manifest:\x20script\x20name\x20missing','scriptPath','Invalid\x20manifest:\x20script\x20path\x20missing','Invalid\x20manifest:\x20invalid\x20type','sidebar','always','icon','icon-apps','version','html','test','plugins','Warning:\x20admin\x20view\x20not\x20specified','Warning:\x20agent\x20view\x20not\x20specified','create','role','body','userProfileId','Unable\x20to\x20retrieve\x20the\x20current\x20user','autoAssociation','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','find','delete','webhookGet','resolve','\x27PATH\x27\x20parameter\x20not\x20specified','port','\x27PORT\x27\x20parameter\x20not\x20specified','hostname','http://localhost:','encoding','method','headers','content-length','endsWith','statusCode','%s%s','content-type','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','papaparse','extract-zip','archiver','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./plugin.socket','register','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','update','then','destroy','get','Plugins','error','stack','name','send','rawAttributes','fieldName','type','model','map'];(function(_0x3e1122,_0x1c458a){var _0x3da9a2=function(_0x193a5e){while(--_0x193a5e){_0x3e1122['push'](_0x3e1122['shift']());}};_0x3da9a2(++_0x1c458a);}(_0x8144,0x113));var _0x4814=function(_0x216cbc,_0x4b0a9e){_0x216cbc=_0x216cbc-0x0;var _0x1a3eaf=_0x8144[_0x216cbc];return _0x1a3eaf;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x4814('0x0'));var zipdir=require(_0x4814('0x1'));var jsonpatch=require(_0x4814('0x2'));var rp=require(_0x4814('0x3'));var moment=require(_0x4814('0x4'));var BPromise=require(_0x4814('0x5'));var Mustache=require(_0x4814('0x6'));var util=require('util');var path=require(_0x4814('0x7'));var sox=require(_0x4814('0x8'));var csv=require(_0x4814('0x9'));var ejs=require(_0x4814('0xa'));var fs=require('fs');var fs_extra=require(_0x4814('0xb'));var _=require(_0x4814('0xc'));var squel=require('squel');var crypto=require(_0x4814('0xd'));var jsforce=require(_0x4814('0xe'));var deskjs=require(_0x4814('0xf'));var toCsv=require('to-csv');var querystring=require(_0x4814('0x10'));var Papa=require(_0x4814('0x11'));var extract=require(_0x4814('0x12'));var rimraf=require(_0x4814('0x0'));var archiver=require(_0x4814('0x13'));var Redis=require(_0x4814('0x14'));var authService=require(_0x4814('0x15'));var qs=require('../../components/parsers/qs');var as=require(_0x4814('0x16'));var hardwareService=require(_0x4814('0x17'));var logger=require(_0x4814('0x18'))(_0x4814('0x19'));var utils=require(_0x4814('0x1a'));var config=require(_0x4814('0x1b'));var licenseUtil=require(_0x4814('0x1c'));var db=require(_0x4814('0x1d'))['db'];config['redis']=_['defaults'](config[_0x4814('0x1e')],{'host':_0x4814('0x1f'),'port':0x18eb});var socket=require(_0x4814('0x20'))(new Redis(config['redis']));require(_0x4814('0x21'))[_0x4814('0x22')](socket);function respondWithStatusCode(_0x362bb4,_0x66df23){_0x66df23=_0x66df23||0xcc;return function(_0x4436ef){if(_0x4436ef){return _0x362bb4[_0x4814('0x23')](_0x66df23);}return _0x362bb4[_0x4814('0x24')](_0x66df23)[_0x4814('0x25')]();};}function respondWithResult(_0x18870b,_0x5afc60){_0x5afc60=_0x5afc60||0xc8;return function(_0x21cecd){if(_0x21cecd){return _0x18870b[_0x4814('0x24')](_0x5afc60)[_0x4814('0x26')](_0x21cecd);}};}function respondWithFilteredResult(_0x52efb3,_0x283223){return function(_0x2d6f30){if(_0x2d6f30){var _0x19f39b=typeof _0x283223[_0x4814('0x27')]===_0x4814('0x28')&&typeof _0x283223[_0x4814('0x29')]===_0x4814('0x28');var _0x5bb7c2=_0x2d6f30[_0x4814('0x2a')];var _0x43017f=_0x19f39b?0x0:_0x283223[_0x4814('0x27')];var _0x2ae75c=_0x19f39b?_0x2d6f30[_0x4814('0x2a')]:_0x283223[_0x4814('0x27')]+_0x283223[_0x4814('0x29')];var _0x26a3b5;if(_0x2ae75c>=_0x5bb7c2){_0x2ae75c=_0x5bb7c2;_0x26a3b5=0xc8;}else{_0x26a3b5=0xce;}_0x52efb3[_0x4814('0x24')](_0x26a3b5);return _0x52efb3['set'](_0x4814('0x2b'),_0x43017f+'-'+_0x2ae75c+'/'+_0x5bb7c2)[_0x4814('0x26')](_0x2d6f30);}return null;};}function patchUpdates(_0x38a607){return function(_0x334ff3){try{jsonpatch[_0x4814('0x2c')](_0x334ff3,_0x38a607,!![]);}catch(_0x2b2a98){return BPromise['reject'](_0x2b2a98);}return _0x334ff3['save']();};}function saveUpdates(_0x350679,_0x448557){return function(_0x5908a7){if(_0x5908a7){return _0x5908a7[_0x4814('0x2d')](_0x350679)[_0x4814('0x2e')](function(_0x392943){return _0x392943;});}return null;};}function removeEntity(_0x29b624,_0x19ca88){return function(_0x2dc360){if(_0x2dc360){return _0x2dc360[_0x4814('0x2f')]()[_0x4814('0x2e')](function(){var _0x2692c8=_0x2dc360[_0x4814('0x30')]({'plain':!![]});var _0x92624e=_0x4814('0x31');return db['UserProfileResource'][_0x4814('0x2f')]({'where':{'type':_0x92624e,'resourceId':_0x2692c8['id']}})['then'](function(){return _0x2dc360;});})['then'](function(){_0x29b624[_0x4814('0x24')](0xcc)[_0x4814('0x25')]();});}};}function handleEntityNotFound(_0x464391,_0xc918c6){return function(_0x17312e){if(!_0x17312e){_0x464391[_0x4814('0x23')](0x194);}return _0x17312e;};}function handleError(_0x40c191,_0x10c0a3){_0x10c0a3=_0x10c0a3||0x1f4;return function(_0x612da4){logger[_0x4814('0x32')](_0x612da4[_0x4814('0x33')]);if(_0x612da4[_0x4814('0x34')]){delete _0x612da4['name'];}_0x40c191[_0x4814('0x24')](_0x10c0a3)[_0x4814('0x35')](_0x612da4);};}exports['index']=function(_0x14e7ad,_0x574207){var _0x2237f3={},_0x566851={},_0x26eb99={'count':0x0,'rows':[]};var _0x184c93=_['map'](db['Plugin'][_0x4814('0x36')],function(_0x95afa0){return{'name':_0x95afa0[_0x4814('0x37')],'type':_0x95afa0[_0x4814('0x38')]['key']};});_0x566851[_0x4814('0x39')]=_[_0x4814('0x3a')](_0x184c93,_0x4814('0x34'));_0x566851['query']=_['keys'](_0x14e7ad['query']);_0x566851['filters']=_['intersection'](_0x566851[_0x4814('0x39')],_0x566851['query']);_0x2237f3[_0x4814('0x3b')]=_['intersection'](_0x566851[_0x4814('0x39')],qs['fields'](_0x14e7ad[_0x4814('0x3c')][_0x4814('0x3d')]));_0x2237f3[_0x4814('0x3b')]=_0x2237f3['attributes'][_0x4814('0x3e')]?_0x2237f3[_0x4814('0x3b')]:_0x566851[_0x4814('0x39')];if(!_0x14e7ad[_0x4814('0x3c')][_0x4814('0x3f')](_0x4814('0x40'))){_0x2237f3[_0x4814('0x29')]=qs['limit'](_0x14e7ad[_0x4814('0x3c')][_0x4814('0x29')]);_0x2237f3[_0x4814('0x27')]=qs[_0x4814('0x27')](_0x14e7ad[_0x4814('0x3c')]['offset']);}_0x2237f3[_0x4814('0x41')]=qs[_0x4814('0x42')](_0x14e7ad[_0x4814('0x3c')][_0x4814('0x42')]);_0x2237f3['where']=qs[_0x4814('0x43')](_[_0x4814('0x44')](_0x14e7ad[_0x4814('0x3c')],_0x566851[_0x4814('0x43')]),_0x184c93);if(_0x14e7ad[_0x4814('0x3c')]['filter']){_0x2237f3['where']=_[_0x4814('0x45')](_0x2237f3['where'],{'$or':_['map'](_0x184c93,function(_0x2b158f){if(_0x2b158f[_0x4814('0x38')]!==_0x4814('0x46')){var _0x34df6b={};_0x34df6b[_0x2b158f[_0x4814('0x34')]]={'$like':'%'+_0x14e7ad[_0x4814('0x3c')]['filter']+'%'};return _0x34df6b;}})});}_0x2237f3=_[_0x4814('0x45')]({},_0x2237f3,_0x14e7ad[_0x4814('0x47')]);var _0x391524={'where':_0x2237f3['where']};return db[_0x4814('0x48')][_0x4814('0x2a')](_0x391524)[_0x4814('0x2e')](function(_0xc1c7c8){_0x26eb99[_0x4814('0x2a')]=_0xc1c7c8;if(_0x14e7ad[_0x4814('0x3c')]['includeAll']){_0x2237f3[_0x4814('0x49')]=[{'all':!![]}];}return db['Plugin']['findAll'](_0x2237f3);})[_0x4814('0x2e')](function(_0x230d78){_0x26eb99['rows']=_0x230d78;return _0x26eb99;})['then'](respondWithFilteredResult(_0x574207,_0x2237f3))['catch'](handleError(_0x574207,null));};exports[_0x4814('0x4a')]=function(_0x4c7504,_0x4a264e){var _0x82d1b4={'raw':!![],'where':{'id':_0x4c7504[_0x4814('0x4b')]['id']}},_0x229ae8={};_0x229ae8[_0x4814('0x39')]=_[_0x4814('0x4c')](db['Plugin'][_0x4814('0x36')]);_0x229ae8[_0x4814('0x3c')]=_[_0x4814('0x4c')](_0x4c7504[_0x4814('0x3c')]);_0x229ae8['filters']=_[_0x4814('0x4d')](_0x229ae8['model'],_0x229ae8[_0x4814('0x3c')]);_0x82d1b4[_0x4814('0x3b')]=_['intersection'](_0x229ae8['model'],qs[_0x4814('0x3d')](_0x4c7504[_0x4814('0x3c')][_0x4814('0x3d')]));_0x82d1b4[_0x4814('0x3b')]=_0x82d1b4['attributes'][_0x4814('0x3e')]?_0x82d1b4[_0x4814('0x3b')]:_0x229ae8['model'];if(_0x4c7504[_0x4814('0x3c')]['includeAll']){_0x82d1b4['include']=[{'all':!![]}];}_0x82d1b4=_[_0x4814('0x45')]({},_0x82d1b4,_0x4c7504[_0x4814('0x47')]);return db[_0x4814('0x48')]['find'](_0x82d1b4)[_0x4814('0x2e')](handleEntityNotFound(_0x4a264e,null))[_0x4814('0x2e')](respondWithResult(_0x4a264e,null))['catch'](handleError(_0x4a264e,null));};exports[_0x4814('0x4e')]=function(_0x3a8313,_0x3a1fe1,_0x466239){return db[_0x4814('0x48')]['find']({'where':{'id':_0x3a8313[_0x4814('0x4b')]['id']},'attributes':['name','path'],'raw':!![]})[_0x4814('0x2e')](handleEntityNotFound(_0x3a1fe1,null))[_0x4814('0x2e')](function(_0x2500a6){if(_0x2500a6){var _0x4341bf=path[_0x4814('0x4f')](config[_0x4814('0x50')],_0x4814('0x51'),util['format'](_0x4814('0x52'),path[_0x4814('0x53')](_0x2500a6[_0x4814('0x7')])));var _0x22524c=fs[_0x4814('0x54')](_0x4341bf);var _0x591758=archiver('zip',{'zlib':{'level':0x9}});_0x591758['on'](_0x4814('0x55'),function(_0xd1f71b){if(_0xd1f71b[_0x4814('0x56')]===_0x4814('0x57')){logger[_0x4814('0x32')](_0xd1f71b);}else{throw new db['Sequelize'][(_0x4814('0x58'))](_0x4814('0x59'));}});_0x591758['on'](_0x4814('0x32'),function(_0xa9b13f){throw new db['Sequelize'][(_0x4814('0x58'))](_0x4814('0x59'));});_0x591758[_0x4814('0x5a')](_0x22524c);_0x591758['glob'](_0x4814('0x5b'),{'cwd':path['join'](config[_0x4814('0x50')],_0x4814('0x51'),path[_0x4814('0x5c')](_0x2500a6[_0x4814('0x7')])),'ignore':[path[_0x4814('0x4f')](path[_0x4814('0x53')](_0x2500a6['path']),_0x4814('0x5d')),path['join'](path['basename'](_0x2500a6[_0x4814('0x7')]),_0x4814('0x5e'))],'nodir':!![]})['finalize']();_0x22524c['on'](_0x4814('0x5f'),function(){if(!fs[_0x4814('0x60')](_0x4341bf)){throw new db[(_0x4814('0x61'))][(_0x4814('0x58'))](_0x4814('0x62'));}return _0x3a1fe1[_0x4814('0x4e')](_0x4341bf,util[_0x4814('0x63')](_0x4814('0x52'),path[_0x4814('0x53')](_0x2500a6['path'])),function(_0x1c76c9){if(_0x1c76c9){throw new db[(_0x4814('0x61'))][(_0x4814('0x58'))](_0x4814('0x64'));}fs[_0x4814('0x65')](_0x4341bf);logger[_0x4814('0x66')](_0x4814('0x67'));logger['info'](_0x4814('0x68'));});});}return null;})[_0x4814('0x69')](handleError(_0x3a1fe1,null));};exports['upload']=function(_0x2df0c7,_0x1833b5,_0x58c4ee){var _0x5e8bc7=path[_0x4814('0x53')](_0x2df0c7[_0x4814('0x6a')]['filename'],path['extname'](_0x2df0c7[_0x4814('0x6a')][_0x4814('0x6b')]));var _0x3982e6=path['join'](config[_0x4814('0x50')],_0x4814('0x51'),_0x2df0c7[_0x4814('0x6a')][_0x4814('0x6b')]);var _0x372472=path[_0x4814('0x4f')](config['root'],_0x4814('0x51'),_0x5e8bc7);logger[_0x4814('0x66')](_0x4814('0x6c'),_0x3982e6);logger[_0x4814('0x66')]('Plugin\x20upload\x20destination:\x20%s',_0x372472);try{fs[_0x4814('0x6d')](_0x3982e6,parseInt(_0x4814('0x6e'),0x8));extract(_0x3982e6,{'dir':_0x372472},function(_0x3eb81a){if(_0x3eb81a){logger[_0x4814('0x32')](_0x3eb81a);handleError(_0x3eb81a,!![]);};var _0x14c122=fs['readdirSync'](_0x372472);if(_0x14c122[_0x4814('0x3e')]>0x1){removeReferences(_0x3982e6,_0x372472);logger[_0x4814('0x32')]('Invalid\x20plugin\x20structure');return _0x58c4ee(new Error('Invalid\x20plugin\x20structure'));}var _0x5be944=fs[_0x4814('0x6f')](path[_0x4814('0x4f')](_0x372472,_0x14c122[0x0]));if(_0x5be944['isFile']()){removeReferences(_0x3982e6,_0x372472);logger[_0x4814('0x32')](_0x4814('0x70'));return _0x58c4ee(new Error(_0x4814('0x70')));}if(_0x5be944[_0x4814('0x71')]()){var _0x28bd93=fs['readdirSync'](path[_0x4814('0x4f')](_0x372472,_0x14c122[0x0]));if(_0x28bd93[_0x4814('0x3e')]===0x0){removeReferences(_0x3982e6,_0x372472);logger[_0x4814('0x32')](_0x4814('0x70'));return _0x58c4ee(new Error(_0x4814('0x70')));}var _0x2d88b5=_0x28bd93[_0x4814('0x72')](function(_0x31e541){return _0x31e541===_0x4814('0x73');});if(!_0x2d88b5){return _0x58c4ee(new Error(_0x4814('0x74')));}var _0x46af00=fs[_0x4814('0x75')](path[_0x4814('0x4f')](_0x372472,_0x14c122[0x0],'manifest.json'));var _0x2245d9=JSON['parse'](_0x46af00);if(_0x4814('0x28')==typeof _0x2245d9['name']){return _0x58c4ee(new Error('Invalid\x20manifest:\x20name\x20missing'));}if(_0x4814('0x28')==typeof _0x2245d9['type']){return _0x58c4ee(new Error(_0x4814('0x76')));}if(_0x4814('0x28')==typeof _0x2245d9['version']){return _0x58c4ee(new Error(_0x4814('0x77')));}if(_0x4814('0x28')==typeof _0x2245d9[_0x4814('0x78')]){return _0x58c4ee(new Error(_0x4814('0x79')));}if(_0x2245d9[_0x4814('0x38')]==='html'){if(_0x4814('0x28')==typeof _0x2245d9[_0x4814('0x78')][_0x4814('0x7a')]){return _0x58c4ee(new Error('Invalid\x20manifest:\x20views\x20missing'));}if(_0x4814('0x28')==typeof _0x2245d9['parameters'][_0x4814('0x7a')][_0x4814('0x7b')]&&_0x4814('0x28')==typeof _0x2245d9[_0x4814('0x78')][_0x4814('0x7a')][_0x4814('0x7c')]){return _0x58c4ee(new Error(_0x4814('0x7d')));}}else if(_0x2245d9[_0x4814('0x38')]===_0x4814('0x7e')){if('undefined'==typeof _0x2245d9[_0x4814('0x78')][_0x4814('0x7f')]){return _0x58c4ee(new Error(_0x4814('0x80')));}if(_0x4814('0x28')==typeof _0x2245d9['parameters'][_0x4814('0x81')]){return _0x58c4ee(new Error(_0x4814('0x82')));}}else{return _0x58c4ee(new Error(_0x4814('0x83')));}var _0x41ae0f=_0x2245d9[_0x4814('0x34')];var _0x7394cd=_0x2245d9['description'];var _0x10866e=_0x2245d9[_0x4814('0x38')];var _0x59a2f6=_0x2245d9['sidebar']?_0x2245d9[_0x4814('0x84')]:_0x4814('0x85');var _0x5436e=_0x2245d9[_0x4814('0x86')]?_0x2245d9[_0x4814('0x86')]:_0x4814('0x87');var _0x42f994='';var _0x4e85e2='';var _0x503184='';var _0x5ee266='';var _0xcefcab=_0x2245d9[_0x4814('0x88')];if(_0x10866e===_0x4814('0x89')){if(_0x4814('0x28')!=typeof _0x2245d9[_0x4814('0x78')]['views']['admin']){var _0x592c5e=_0x2245d9['parameters'][_0x4814('0x7a')][_0x4814('0x7b')];if(!/^(f|ht)tps?:\/\//i[_0x4814('0x8a')](_0x592c5e)){_0x42f994=path[_0x4814('0x4f')](_0x4814('0x8b'),_0x5e8bc7,_0x14c122[0x0],_0x592c5e);}else{_0x42f994=_0x592c5e;}}else{logger[_0x4814('0x66')](_0x4814('0x8c'));}if(_0x4814('0x28')!=typeof _0x2245d9[_0x4814('0x78')]['views']['agent']){var _0x3a173b=_0x2245d9[_0x4814('0x78')][_0x4814('0x7a')][_0x4814('0x7c')];if(!/^(f|ht)tps?:\/\//i[_0x4814('0x8a')](_0x3a173b)){_0x4e85e2=path[_0x4814('0x4f')](_0x4814('0x8b'),_0x5e8bc7,_0x14c122[0x0],_0x3a173b);}else{_0x4e85e2=_0x3a173b;}}else{logger[_0x4814('0x66')](_0x4814('0x8d'));}}else if(_0x10866e===_0x4814('0x7e')){_0x503184=_0x2245d9[_0x4814('0x78')][_0x4814('0x7f')];_0x5ee266=_0x2245d9[_0x4814('0x78')][_0x4814('0x81')];if('undefined'!=typeof _0x2245d9[_0x4814('0x78')][_0x4814('0x7a')]){if(_0x4814('0x28')!=typeof _0x2245d9['parameters']['views']['admin']){var _0x592c5e=_0x2245d9[_0x4814('0x78')][_0x4814('0x7a')][_0x4814('0x7b')];if(!/^(f|ht)tps?:\/\//i['test'](_0x592c5e)){_0x42f994=path[_0x4814('0x4f')](_0x4814('0x8b'),_0x5e8bc7,_0x14c122[0x0],_0x592c5e);}else{_0x42f994=_0x592c5e;}}if(_0x4814('0x28')!=typeof _0x2245d9[_0x4814('0x78')][_0x4814('0x7a')][_0x4814('0x7c')]){var _0x3a173b=_0x2245d9['parameters'][_0x4814('0x7a')]['agent'];if(!/^(f|ht)tps?:\/\//i[_0x4814('0x8a')](_0x3a173b)){_0x4e85e2=path[_0x4814('0x4f')]('plugins',_0x5e8bc7,_0x14c122[0x0],_0x3a173b);}else{_0x4e85e2=_0x3a173b;}}}}var _0x693a2b={'name':_0x41ae0f,'description':_0x7394cd,'path':path[_0x4814('0x4f')](_0x5e8bc7,_0x14c122[0x0]),'type':_0x10866e,'sidebar':_0x59a2f6,'icon':_0x5436e,'adminUrl':_0x42f994,'agentUrl':_0x4e85e2,'scriptName':_0x503184,'scriptPath':_0x5ee266,'version':_0xcefcab};removeReferences(_0x3982e6,null);return db[_0x4814('0x48')][_0x4814('0x8e')](_0x693a2b)['then'](function(_0x4a5226){var _0x2bdbac={'role':_0x2df0c7['body'][_0x4814('0x8f')],'userProfileId':_0x2df0c7[_0x4814('0x90')][_0x4814('0x91')]};if(!_0x2bdbac)throw new Error(_0x4814('0x92'));if(_0x2bdbac[_0x4814('0x8f')]==='user'){var _0x1947b7=_0x4a5226['get']({'plain':!![]});return db['UserProfileSection']['find']({'where':{'name':'Plugins','userProfileId':_0x2bdbac['userProfileId']},'raw':!![]})['then'](function(_0x86a436){if(_0x86a436&&_0x86a436[_0x4814('0x93')]===0x0){return db['UserProfileResource']['create']({'name':_0x1947b7['name'],'resourceId':_0x1947b7['id'],'type':_0x86a436[_0x4814('0x34')],'sectionId':_0x86a436['id']},{})[_0x4814('0x2e')](function(){return _0x4a5226;});}else{return _0x4a5226;}})['catch'](function(_0x2d8567){logger[_0x4814('0x32')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x2d8567);throw _0x2d8567;});}return _0x4a5226;})[_0x4814('0x2e')](respondWithResult(_0x1833b5,null))['catch'](handleError(_0x1833b5,null));}});}catch(_0x3798f5){_0x1833b5[_0x4814('0x24')](0x1f4)[_0x4814('0x35')](_0x3798f5);}};function removeReferences(_0x214714,_0x12e962){try{if(_0x214714){fs[_0x4814('0x65')](_0x214714);logger['info'](_0x4814('0x94'));}if(_0x12e962){rimraf(_0x12e962,function(){});logger[_0x4814('0x66')](_0x4814('0x95'));}}catch(_0x44919b){logger['error'](_0x44919b);}}exports[_0x4814('0x2d')]=function(_0x51b3de,_0x360f7c,_0x206316){return db[_0x4814('0x48')][_0x4814('0x96')]({'where':{'id':_0x51b3de[_0x4814('0x4b')]['id']}})['then'](handleEntityNotFound(_0x360f7c,null))[_0x4814('0x2e')](saveUpdates(_0x51b3de[_0x4814('0x90')],null))[_0x4814('0x2e')](respondWithResult(_0x360f7c,null))[_0x4814('0x69')](handleError(_0x360f7c,null));};exports[_0x4814('0x97')]=function(_0x4fc616,_0x415bd3,_0x4e13e7){return db[_0x4814('0x48')][_0x4814('0x96')]({'where':{'id':_0x4fc616[_0x4814('0x4b')]['id']}})[_0x4814('0x2e')](function(_0x3c7d46){if(_0x3c7d46){return _0x3c7d46[_0x4814('0x2f')]();}})[_0x4814('0x2e')](function(_0x533b53){rimraf(path[_0x4814('0x4f')](config[_0x4814('0x50')],_0x4814('0x51'),path[_0x4814('0x5c')](_0x533b53[_0x4814('0x7')])),function(){});return _0x533b53;})[_0x4814('0x2e')](handleEntityNotFound(_0x415bd3,null))[_0x4814('0x2e')](respondWithStatusCode(_0x415bd3,null))[_0x4814('0x69')](handleError(_0x415bd3,null));};exports[_0x4814('0x98')]=function(_0x32bf7d,_0x43a735,_0x1587db){return BPromise[_0x4814('0x99')]()[_0x4814('0x2e')](function(){if(!_0x32bf7d[_0x4814('0x3c')]['path']){throw new Error(_0x4814('0x9a'));}if(!_0x32bf7d['query'][_0x4814('0x9b')]){throw new Error(_0x4814('0x9c'));}var _0x383f09=_0x32bf7d['query']['hostname']?_0x32bf7d[_0x4814('0x3c')][_0x4814('0x9d')]+':'+_0x32bf7d[_0x4814('0x3c')][_0x4814('0x9b')]:_0x4814('0x9e')+_0x32bf7d[_0x4814('0x3c')][_0x4814('0x9b')];var _0xaff23f=_0x32bf7d['query'][_0x4814('0x26')]?_0x32bf7d[_0x4814('0x3c')]['json']:!![];var _0x17296f=_0x32bf7d['query'][_0x4814('0x9f')]?_0x32bf7d[_0x4814('0x3c')]['encoding']:null;var _0xcff0f7={'method':_0x32bf7d[_0x4814('0xa0')],'uri':util[_0x4814('0x63')]('%s%s',_0x383f09,_0x32bf7d[_0x4814('0x3c')][_0x4814('0x7')]),'json':_0xaff23f,'resolveWithFullResponse':!![],'encoding':_0x17296f,'qs':_0x32bf7d[_0x4814('0x3c')]};if(_0x32bf7d[_0x4814('0xa1')]){_0xcff0f7['headers']=_0x32bf7d[_0x4814('0xa1')];if(_0xcff0f7[_0x4814('0xa1')][_0x4814('0xa2')]){delete _0xcff0f7[_0x4814('0xa1')]['content-length'];}}if(_0xcff0f7[_0x4814('0xa1')]['content-type']){delete _0xcff0f7[_0x4814('0xa1')]['content-type'];}return rp(_0xcff0f7);})['then'](function(_0x326e90){if(_0x326e90){_0x43a735['set'](_0x326e90['headers']);logger[_0x4814('0x66')](_0x326e90[_0x4814('0x90')]);if(_[_0x4814('0xa3')](_0x32bf7d[_0x4814('0x3c')]['path'],_0x4814('0x4e'))&&_0x326e90[_0x4814('0xa4')]==0x1f4){return _0x43a735['sendStatus'](_0x326e90[_0x4814('0xa4')]);}else{return _0x43a735[_0x4814('0x24')](_0x326e90[_0x4814('0xa4')])['send'](_0x326e90[_0x4814('0x90')]);}}else{return _0x43a735[_0x4814('0x23')](0xc8);}})[_0x4814('0x69')](handleError(_0x43a735,null));};exports['webhookPost']=function(_0x5e3be4,_0x4332b2,_0x28b37f){return BPromise[_0x4814('0x99')]()['then'](function(){if(!_0x5e3be4['query'][_0x4814('0x7')]){throw new Error(_0x4814('0x9a'));}if(!_0x5e3be4[_0x4814('0x3c')]['port']){throw new Error(_0x4814('0x9c'));}var _0xa687ec=_0x5e3be4[_0x4814('0x3c')][_0x4814('0x9d')]?_0x5e3be4[_0x4814('0x3c')][_0x4814('0x9d')]+':'+_0x5e3be4[_0x4814('0x3c')][_0x4814('0x9b')]:_0x4814('0x9e')+_0x5e3be4[_0x4814('0x3c')][_0x4814('0x9b')];var _0x2b3bae=_0x5e3be4[_0x4814('0x3c')]['json']?_0x5e3be4[_0x4814('0x3c')][_0x4814('0x26')]:!![];var _0x1c20e8=_0x5e3be4[_0x4814('0x3c')][_0x4814('0x9f')]?_0x5e3be4[_0x4814('0x3c')]['encoding']:null;var _0x145b58={'method':_0x5e3be4[_0x4814('0xa0')],'uri':util['format'](_0x4814('0xa5'),_0xa687ec,_0x5e3be4['query']['path']),'json':_0x2b3bae,'resolveWithFullResponse':!![],'encoding':_0x1c20e8,'body':_0x5e3be4[_0x4814('0x90')]};if(_0x5e3be4['headers']){_0x145b58['headers']=_0x5e3be4[_0x4814('0xa1')];if(_0x145b58[_0x4814('0xa1')][_0x4814('0xa2')]){delete _0x145b58[_0x4814('0xa1')]['content-length'];}}if(_0x145b58[_0x4814('0xa1')][_0x4814('0xa6')]){delete _0x145b58[_0x4814('0xa1')][_0x4814('0xa6')];}return rp(_0x145b58);})[_0x4814('0x2e')](function(_0x1e5126){if(_0x1e5126){_0x4332b2['set'](_0x1e5126[_0x4814('0xa1')]);logger[_0x4814('0x66')](_0x1e5126[_0x4814('0x90')]);return _0x4332b2[_0x4814('0x24')](_0x1e5126['statusCode'])[_0x4814('0x35')](_0x1e5126[_0x4814('0x90')]);}else{return _0x4332b2['sendStatus'](0xc8);}})[_0x4814('0x69')](handleError(_0x4332b2,null));};