a275da74e88b8d8a4faeb40ac36bc9a1450efe5d
[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 _0x934c=['lstatSync','isDirectory','readdirSync','Plugin\x20manifest\x20missing','readFileSync','manifest.json','Invalid\x20manifest:\x20name\x20missing','Invalid\x20manifest:\x20type\x20missing','version','Invalid\x20manifest:\x20version\x20not\x20specified','parameters','html','views','Invalid\x20manifest:\x20views\x20missing','admin','script','scriptName','Invalid\x20manifest:\x20script\x20name\x20missing','scriptPath','Invalid\x20manifest:\x20invalid\x20type','sidebar','always','icon-apps','plugins','Warning:\x20admin\x20view\x20not\x20specified','agent','Warning:\x20agent\x20view\x20not\x20specified','body','role','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','Plugins','UserProfileResource','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','Zip\x20archive\x20removed','Extracted\x20folder\x20removed','update','delete','dirname','\x27PATH\x27\x20parameter\x20not\x20specified','port','\x27PORT\x27\x20parameter\x20not\x20specified','hostname','http://localhost:','encoding','method','%s%s','headers','content-length','content-type','endsWith','statusCode','resolve','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','papaparse','extract-zip','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','socket.io-emitter','redis','./plugin.socket','register','status','json','limit','undefined','offset','count','set','Content-Range','save','then','get','sendStatus','error','stack','name','send','index','Plugin','rawAttributes','fieldName','type','key','model','map','query','keys','filters','intersection','attributes','length','nolimit','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','fields','find','download','params','join','root','server/files/plugins','format','%s.zip','basename','createWriteStream','code','ENOENT','Sequelize','Error','Error\x20while\x20generating\x20the\x20zip\x20archive','pipe','**/*','attachments/**/*','finalize','close','existsSync','Error\x20while\x20downloading\x20the\x20plugin','unlinkSync','info','Download\x20completed','file','extname','filename','Plugin\x20upload\x20destination:\x20%s','chmodSync','Invalid\x20plugin\x20structure'];(function(_0x214bd7,_0x9d5a1a){var _0x1f3be5=function(_0xf53540){while(--_0xf53540){_0x214bd7['push'](_0x214bd7['shift']());}};_0x1f3be5(++_0x9d5a1a);}(_0x934c,0xd3));var _0xc934=function(_0x385b4e,_0x206ce9){_0x385b4e=_0x385b4e-0x0;var _0x593af1=_0x934c[_0x385b4e];return _0x593af1;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xc934('0x0'));var zipdir=require(_0xc934('0x1'));var jsonpatch=require(_0xc934('0x2'));var rp=require('request-promise');var moment=require(_0xc934('0x3'));var BPromise=require(_0xc934('0x4'));var Mustache=require(_0xc934('0x5'));var util=require('util');var path=require(_0xc934('0x6'));var sox=require(_0xc934('0x7'));var csv=require(_0xc934('0x8'));var ejs=require(_0xc934('0x9'));var fs=require('fs');var fs_extra=require(_0xc934('0xa'));var _=require(_0xc934('0xb'));var squel=require('squel');var crypto=require(_0xc934('0xc'));var jsforce=require(_0xc934('0xd'));var deskjs=require(_0xc934('0xe'));var toCsv=require(_0xc934('0x8'));var querystring=require('querystring');var Papa=require(_0xc934('0xf'));var extract=require(_0xc934('0x10'));var rimraf=require(_0xc934('0x0'));var archiver=require('archiver');var Redis=require('ioredis');var authService=require(_0xc934('0x11'));var qs=require('../../components/parsers/qs');var as=require(_0xc934('0x12'));var hardwareService=require(_0xc934('0x13'));var logger=require(_0xc934('0x14'))('api');var utils=require(_0xc934('0x15'));var config=require(_0xc934('0x16'));var licenseUtil=require(_0xc934('0x17'));var db=require(_0xc934('0x18'))['db'];config['redis']=_[_0xc934('0x19')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xc934('0x1a'))(new Redis(config[_0xc934('0x1b')]));require(_0xc934('0x1c'))[_0xc934('0x1d')](socket);function respondWithStatusCode(_0x241d66,_0x4aadec){_0x4aadec=_0x4aadec||0xcc;return function(_0xab32ce){if(_0xab32ce){return _0x241d66['sendStatus'](_0x4aadec);}return _0x241d66[_0xc934('0x1e')](_0x4aadec)['end']();};}function respondWithResult(_0x4549a3,_0x3194e6){_0x3194e6=_0x3194e6||0xc8;return function(_0x184123){if(_0x184123){return _0x4549a3[_0xc934('0x1e')](_0x3194e6)[_0xc934('0x1f')](_0x184123);}};}function respondWithFilteredResult(_0x3cfaf2,_0x3a3ce8){return function(_0xbe012a){if(_0xbe012a){var _0x3c6442=typeof _0x3a3ce8['offset']==='undefined'&&typeof _0x3a3ce8[_0xc934('0x20')]===_0xc934('0x21');var _0x4c5f35=_0xbe012a['count'];var _0x18d4a9=_0x3c6442?0x0:_0x3a3ce8[_0xc934('0x22')];var _0x206790=_0x3c6442?_0xbe012a[_0xc934('0x23')]:_0x3a3ce8[_0xc934('0x22')]+_0x3a3ce8[_0xc934('0x20')];var _0x434226;if(_0x206790>=_0x4c5f35){_0x206790=_0x4c5f35;_0x434226=0xc8;}else{_0x434226=0xce;}_0x3cfaf2[_0xc934('0x1e')](_0x434226);return _0x3cfaf2[_0xc934('0x24')](_0xc934('0x25'),_0x18d4a9+'-'+_0x206790+'/'+_0x4c5f35)['json'](_0xbe012a);}return null;};}function patchUpdates(_0x34dd90){return function(_0x4d210b){try{jsonpatch['apply'](_0x4d210b,_0x34dd90,!![]);}catch(_0x7ce53f){return BPromise['reject'](_0x7ce53f);}return _0x4d210b[_0xc934('0x26')]();};}function saveUpdates(_0x77b675,_0x11f081){return function(_0x92904a){if(_0x92904a){return _0x92904a['update'](_0x77b675)[_0xc934('0x27')](function(_0x53a72c){return _0x53a72c;});}return null;};}function removeEntity(_0x35fffe,_0x2525cf){return function(_0x51858f){if(_0x51858f){return _0x51858f['destroy']()[_0xc934('0x27')](function(){var _0x553025=_0x51858f[_0xc934('0x28')]({'plain':!![]});var _0x3fb339='Plugins';return db['UserProfileResource']['destroy']({'where':{'type':_0x3fb339,'resourceId':_0x553025['id']}})[_0xc934('0x27')](function(){return _0x51858f;});})[_0xc934('0x27')](function(){_0x35fffe['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x5a8d51,_0x553de8){return function(_0x5057cd){if(!_0x5057cd){_0x5a8d51[_0xc934('0x29')](0x194);}return _0x5057cd;};}function handleError(_0x341692,_0x443947){_0x443947=_0x443947||0x1f4;return function(_0x578a03){logger[_0xc934('0x2a')](_0x578a03[_0xc934('0x2b')]);if(_0x578a03['name']){delete _0x578a03[_0xc934('0x2c')];}_0x341692['status'](_0x443947)[_0xc934('0x2d')](_0x578a03);};}exports[_0xc934('0x2e')]=function(_0x3876ff,_0x51a41f){var _0x12ad58={},_0x3fbe1b={},_0x264970={'count':0x0,'rows':[]};var _0x2a05a5=_['map'](db[_0xc934('0x2f')][_0xc934('0x30')],function(_0x5d7669){return{'name':_0x5d7669[_0xc934('0x31')],'type':_0x5d7669[_0xc934('0x32')][_0xc934('0x33')]};});_0x3fbe1b[_0xc934('0x34')]=_[_0xc934('0x35')](_0x2a05a5,_0xc934('0x2c'));_0x3fbe1b[_0xc934('0x36')]=_[_0xc934('0x37')](_0x3876ff[_0xc934('0x36')]);_0x3fbe1b[_0xc934('0x38')]=_[_0xc934('0x39')](_0x3fbe1b[_0xc934('0x34')],_0x3fbe1b[_0xc934('0x36')]);_0x12ad58[_0xc934('0x3a')]=_['intersection'](_0x3fbe1b[_0xc934('0x34')],qs['fields'](_0x3876ff[_0xc934('0x36')]['fields']));_0x12ad58[_0xc934('0x3a')]=_0x12ad58['attributes'][_0xc934('0x3b')]?_0x12ad58[_0xc934('0x3a')]:_0x3fbe1b[_0xc934('0x34')];if(!_0x3876ff[_0xc934('0x36')]['hasOwnProperty'](_0xc934('0x3c'))){_0x12ad58['limit']=qs[_0xc934('0x20')](_0x3876ff['query'][_0xc934('0x20')]);_0x12ad58[_0xc934('0x22')]=qs[_0xc934('0x22')](_0x3876ff[_0xc934('0x36')][_0xc934('0x22')]);}_0x12ad58['order']=qs[_0xc934('0x3d')](_0x3876ff[_0xc934('0x36')][_0xc934('0x3d')]);_0x12ad58[_0xc934('0x3e')]=qs[_0xc934('0x38')](_[_0xc934('0x3f')](_0x3876ff['query'],_0x3fbe1b[_0xc934('0x38')]),_0x2a05a5);if(_0x3876ff['query'][_0xc934('0x40')]){_0x12ad58[_0xc934('0x3e')]=_[_0xc934('0x41')](_0x12ad58[_0xc934('0x3e')],{'$or':_['map'](_0x2a05a5,function(_0x5c07c5){if(_0x5c07c5['type']!==_0xc934('0x42')){var _0x26727e={};_0x26727e[_0x5c07c5['name']]={'$like':'%'+_0x3876ff['query'][_0xc934('0x40')]+'%'};return _0x26727e;}})});}_0x12ad58=_['merge']({},_0x12ad58,_0x3876ff[_0xc934('0x43')]);var _0x241d1c={'where':_0x12ad58[_0xc934('0x3e')]};return db['Plugin'][_0xc934('0x23')](_0x241d1c)['then'](function(_0x133589){_0x264970[_0xc934('0x23')]=_0x133589;if(_0x3876ff[_0xc934('0x36')][_0xc934('0x44')]){_0x12ad58[_0xc934('0x45')]=[{'all':!![]}];}return db[_0xc934('0x2f')][_0xc934('0x46')](_0x12ad58);})[_0xc934('0x27')](function(_0x30e383){_0x264970[_0xc934('0x47')]=_0x30e383;return _0x264970;})[_0xc934('0x27')](respondWithFilteredResult(_0x51a41f,_0x12ad58))[_0xc934('0x48')](handleError(_0x51a41f,null));};exports['show']=function(_0x2bf832,_0x2c89ff){var _0x30491a={'raw':!![],'where':{'id':_0x2bf832['params']['id']}},_0x2634f8={};_0x2634f8['model']=_['keys'](db[_0xc934('0x2f')]['rawAttributes']);_0x2634f8[_0xc934('0x36')]=_[_0xc934('0x37')](_0x2bf832[_0xc934('0x36')]);_0x2634f8[_0xc934('0x38')]=_['intersection'](_0x2634f8[_0xc934('0x34')],_0x2634f8[_0xc934('0x36')]);_0x30491a[_0xc934('0x3a')]=_[_0xc934('0x39')](_0x2634f8[_0xc934('0x34')],qs[_0xc934('0x49')](_0x2bf832[_0xc934('0x36')][_0xc934('0x49')]));_0x30491a[_0xc934('0x3a')]=_0x30491a['attributes'][_0xc934('0x3b')]?_0x30491a[_0xc934('0x3a')]:_0x2634f8['model'];if(_0x2bf832[_0xc934('0x36')][_0xc934('0x44')]){_0x30491a['include']=[{'all':!![]}];}_0x30491a=_[_0xc934('0x41')]({},_0x30491a,_0x2bf832[_0xc934('0x43')]);return db['Plugin'][_0xc934('0x4a')](_0x30491a)['then'](handleEntityNotFound(_0x2c89ff,null))[_0xc934('0x27')](respondWithResult(_0x2c89ff,null))[_0xc934('0x48')](handleError(_0x2c89ff,null));};exports[_0xc934('0x4b')]=function(_0x3fcc1f,_0x5397c8,_0x4ad659){return db[_0xc934('0x2f')]['find']({'where':{'id':_0x3fcc1f[_0xc934('0x4c')]['id']},'attributes':[_0xc934('0x2c'),_0xc934('0x6')],'raw':!![]})[_0xc934('0x27')](handleEntityNotFound(_0x5397c8,null))[_0xc934('0x27')](function(_0xd31cae){if(_0xd31cae){var _0x17e324=path[_0xc934('0x4d')](config[_0xc934('0x4e')],_0xc934('0x4f'),util[_0xc934('0x50')](_0xc934('0x51'),path[_0xc934('0x52')](_0xd31cae['path'])));var _0x56b115=fs[_0xc934('0x53')](_0x17e324);var _0x180c81=archiver('zip',{'zlib':{'level':0x9}});_0x180c81['on']('warning',function(_0x358752){if(_0x358752[_0xc934('0x54')]===_0xc934('0x55')){logger[_0xc934('0x2a')](_0x358752);}else{throw new db[(_0xc934('0x56'))]['Error']('Error\x20while\x20generating\x20the\x20zip\x20archive');}});_0x180c81['on'](_0xc934('0x2a'),function(_0x438dc8){throw new db[(_0xc934('0x56'))][(_0xc934('0x57'))](_0xc934('0x58'));});_0x180c81[_0xc934('0x59')](_0x56b115);_0x180c81['glob'](_0xc934('0x5a'),{'cwd':path[_0xc934('0x4d')](config[_0xc934('0x4e')],_0xc934('0x4f'),path['dirname'](_0xd31cae[_0xc934('0x6')])),'ignore':[path['join'](path[_0xc934('0x52')](_0xd31cae[_0xc934('0x6')]),'node_modules/**/*'),path[_0xc934('0x4d')](path['basename'](_0xd31cae['path']),_0xc934('0x5b'))],'nodir':!![]})[_0xc934('0x5c')]();_0x56b115['on'](_0xc934('0x5d'),function(){if(!fs[_0xc934('0x5e')](_0x17e324)){throw new db[(_0xc934('0x56'))][(_0xc934('0x57'))]('Plugin\x20not\x20found');}return _0x5397c8[_0xc934('0x4b')](_0x17e324,util['format']('%s.zip',path[_0xc934('0x52')](_0xd31cae[_0xc934('0x6')])),function(_0x5b023f){if(_0x5b023f){throw new db[(_0xc934('0x56'))][(_0xc934('0x57'))](_0xc934('0x5f'));}fs[_0xc934('0x60')](_0x17e324);logger[_0xc934('0x61')](_0xc934('0x62'));logger[_0xc934('0x61')]('Temporary\x20file\x20removed');});});}return null;})[_0xc934('0x48')](handleError(_0x5397c8,null));};exports['upload']=function(_0x4f62fd,_0x2f774e,_0x61c282){var _0x3fd31e=path[_0xc934('0x52')](_0x4f62fd[_0xc934('0x63')]['filename'],path[_0xc934('0x64')](_0x4f62fd['file'][_0xc934('0x65')]));var _0x1b4547=path[_0xc934('0x4d')](config[_0xc934('0x4e')],'server/files/plugins',_0x4f62fd[_0xc934('0x63')][_0xc934('0x65')]);var _0x465bf9=path['join'](config['root'],_0xc934('0x4f'),_0x3fd31e);logger[_0xc934('0x61')]('Plugin\x20upload\x20filepath:\x20%s',_0x1b4547);logger['info'](_0xc934('0x66'),_0x465bf9);try{fs[_0xc934('0x67')](_0x1b4547,parseInt('0777',0x8));extract(_0x1b4547,{'dir':_0x465bf9},function(_0x1a2f6c){if(_0x1a2f6c){logger[_0xc934('0x2a')](_0x1a2f6c);handleError(_0x1a2f6c,!![]);};var _0x558b4f=fs['readdirSync'](_0x465bf9);if(_0x558b4f[_0xc934('0x3b')]>0x1){removeReferences(_0x1b4547,_0x465bf9);logger[_0xc934('0x2a')]('Invalid\x20plugin\x20structure');return _0x61c282(new Error(_0xc934('0x68')));}var _0x14a222=fs[_0xc934('0x69')](path[_0xc934('0x4d')](_0x465bf9,_0x558b4f[0x0]));if(_0x14a222['isFile']()){removeReferences(_0x1b4547,_0x465bf9);logger[_0xc934('0x2a')](_0xc934('0x68'));return _0x61c282(new Error('Invalid\x20plugin\x20structure'));}if(_0x14a222[_0xc934('0x6a')]()){var _0x2b72ab=fs[_0xc934('0x6b')](path['join'](_0x465bf9,_0x558b4f[0x0]));if(_0x2b72ab[_0xc934('0x3b')]===0x0){removeReferences(_0x1b4547,_0x465bf9);logger[_0xc934('0x2a')]('Invalid\x20plugin\x20structure');return _0x61c282(new Error('Invalid\x20plugin\x20structure'));}var _0x2fe2f2=_0x2b72ab['some'](function(_0x4c6b4a){return _0x4c6b4a==='manifest.json';});if(!_0x2fe2f2){return _0x61c282(new Error(_0xc934('0x6c')));}var _0xe03750=fs[_0xc934('0x6d')](path[_0xc934('0x4d')](_0x465bf9,_0x558b4f[0x0],_0xc934('0x6e')));var _0x318981=JSON['parse'](_0xe03750);if(_0xc934('0x21')==typeof _0x318981[_0xc934('0x2c')]){return _0x61c282(new Error(_0xc934('0x6f')));}if('undefined'==typeof _0x318981[_0xc934('0x32')]){return _0x61c282(new Error(_0xc934('0x70')));}if(_0xc934('0x21')==typeof _0x318981[_0xc934('0x71')]){return _0x61c282(new Error(_0xc934('0x72')));}if(_0xc934('0x21')==typeof _0x318981[_0xc934('0x73')]){return _0x61c282(new Error('Invalid\x20manifest:\x20parameters\x20missing'));}if(_0x318981['type']===_0xc934('0x74')){if(_0xc934('0x21')==typeof _0x318981[_0xc934('0x73')][_0xc934('0x75')]){return _0x61c282(new Error(_0xc934('0x76')));}if(_0xc934('0x21')==typeof _0x318981[_0xc934('0x73')][_0xc934('0x75')][_0xc934('0x77')]&&'undefined'==typeof _0x318981[_0xc934('0x73')][_0xc934('0x75')]['agent']){return _0x61c282(new Error('Invalid\x20manifest:\x20no\x20view\x20specified'));}}else if(_0x318981[_0xc934('0x32')]===_0xc934('0x78')){if(_0xc934('0x21')==typeof _0x318981[_0xc934('0x73')][_0xc934('0x79')]){return _0x61c282(new Error(_0xc934('0x7a')));}if(_0xc934('0x21')==typeof _0x318981[_0xc934('0x73')][_0xc934('0x7b')]){return _0x61c282(new Error('Invalid\x20manifest:\x20script\x20path\x20missing'));}}else{return _0x61c282(new Error(_0xc934('0x7c')));}var _0x153b57=_0x318981['name'];var _0x10e5ad=_0x318981['description'];var _0x4fa1d5=_0x318981[_0xc934('0x32')];var _0x4f140d=_0x318981[_0xc934('0x7d')]?_0x318981[_0xc934('0x7d')]:_0xc934('0x7e');var _0x3806f2=_0x318981['icon']?_0x318981['icon']:_0xc934('0x7f');var _0x18277e='';var _0x52a7ac='';var _0x365041='';var _0x14b707='';var _0xf135c5=_0x318981['version'];if(_0x4fa1d5===_0xc934('0x74')){if(_0xc934('0x21')!=typeof _0x318981[_0xc934('0x73')][_0xc934('0x75')][_0xc934('0x77')]){var _0x4649dc=_0x318981[_0xc934('0x73')][_0xc934('0x75')]['admin'];if(!/^(f|ht)tps?:\/\//i['test'](_0x4649dc)){_0x18277e=path[_0xc934('0x4d')](_0xc934('0x80'),_0x3fd31e,_0x558b4f[0x0],_0x4649dc);}else{_0x18277e=_0x4649dc;}}else{logger[_0xc934('0x61')](_0xc934('0x81'));}if(_0xc934('0x21')!=typeof _0x318981['parameters']['views'][_0xc934('0x82')]){var _0x181661=_0x318981[_0xc934('0x73')][_0xc934('0x75')]['agent'];if(!/^(f|ht)tps?:\/\//i['test'](_0x181661)){_0x52a7ac=path[_0xc934('0x4d')](_0xc934('0x80'),_0x3fd31e,_0x558b4f[0x0],_0x181661);}else{_0x52a7ac=_0x181661;}}else{logger[_0xc934('0x61')](_0xc934('0x83'));}}else if(_0x4fa1d5===_0xc934('0x78')){_0x365041=_0x318981[_0xc934('0x73')][_0xc934('0x79')];_0x14b707=_0x318981['parameters']['scriptPath'];if(_0xc934('0x21')!=typeof _0x318981['parameters'][_0xc934('0x75')]){if(_0xc934('0x21')!=typeof _0x318981[_0xc934('0x73')][_0xc934('0x75')][_0xc934('0x77')]){var _0x4649dc=_0x318981[_0xc934('0x73')][_0xc934('0x75')]['admin'];if(!/^(f|ht)tps?:\/\//i['test'](_0x4649dc)){_0x18277e=path[_0xc934('0x4d')]('plugins',_0x3fd31e,_0x558b4f[0x0],_0x4649dc);}else{_0x18277e=_0x4649dc;}}if('undefined'!=typeof _0x318981[_0xc934('0x73')][_0xc934('0x75')][_0xc934('0x82')]){var _0x181661=_0x318981['parameters'][_0xc934('0x75')]['agent'];if(!/^(f|ht)tps?:\/\//i['test'](_0x181661)){_0x52a7ac=path[_0xc934('0x4d')]('plugins',_0x3fd31e,_0x558b4f[0x0],_0x181661);}else{_0x52a7ac=_0x181661;}}}}var _0x31357f={'name':_0x153b57,'description':_0x10e5ad,'path':path[_0xc934('0x4d')](_0x3fd31e,_0x558b4f[0x0]),'type':_0x4fa1d5,'sidebar':_0x4f140d,'icon':_0x3806f2,'adminUrl':_0x18277e,'agentUrl':_0x52a7ac,'scriptName':_0x365041,'scriptPath':_0x14b707,'version':_0xf135c5};removeReferences(_0x1b4547,null);return db[_0xc934('0x2f')]['create'](_0x31357f)[_0xc934('0x27')](function(_0x20fd70){var _0x56f926={'role':_0x4f62fd[_0xc934('0x84')][_0xc934('0x85')],'userProfileId':_0x4f62fd['body']['userProfileId']};if(!_0x56f926)throw new Error(_0xc934('0x86'));if(_0x56f926[_0xc934('0x85')]===_0xc934('0x87')){var _0x496774=_0x20fd70['get']({'plain':!![]});return db['UserProfileSection'][_0xc934('0x4a')]({'where':{'name':_0xc934('0x88'),'userProfileId':_0x56f926['userProfileId']},'raw':!![]})[_0xc934('0x27')](function(_0x59f7f3){if(_0x59f7f3&&_0x59f7f3['autoAssociation']===0x0){return db[_0xc934('0x89')]['create']({'name':_0x496774[_0xc934('0x2c')],'resourceId':_0x496774['id'],'type':_0x59f7f3['name'],'sectionId':_0x59f7f3['id']},{})[_0xc934('0x27')](function(){return _0x20fd70;});}else{return _0x20fd70;}})[_0xc934('0x48')](function(_0x4e595c){logger[_0xc934('0x2a')](_0xc934('0x8a'),_0x4e595c);throw _0x4e595c;});}return _0x20fd70;})[_0xc934('0x27')](respondWithResult(_0x2f774e,null))[_0xc934('0x48')](handleError(_0x2f774e,null));}});}catch(_0x184043){_0x2f774e['status'](0x1f4)[_0xc934('0x2d')](_0x184043);}};function removeReferences(_0x40345a,_0xb33187){try{if(_0x40345a){fs[_0xc934('0x60')](_0x40345a);logger[_0xc934('0x61')](_0xc934('0x8b'));}if(_0xb33187){rimraf(_0xb33187,function(){});logger['info'](_0xc934('0x8c'));}}catch(_0x444596){logger[_0xc934('0x2a')](_0x444596);}}exports[_0xc934('0x8d')]=function(_0x242914,_0x361cfb,_0x3ea320){return db[_0xc934('0x2f')]['find']({'where':{'id':_0x242914[_0xc934('0x4c')]['id']}})['then'](handleEntityNotFound(_0x361cfb,null))[_0xc934('0x27')](saveUpdates(_0x242914[_0xc934('0x84')],null))['then'](respondWithResult(_0x361cfb,null))['catch'](handleError(_0x361cfb,null));};exports[_0xc934('0x8e')]=function(_0x356922,_0x340254,_0xceac4){return db[_0xc934('0x2f')][_0xc934('0x4a')]({'where':{'id':_0x356922['params']['id']}})[_0xc934('0x27')](function(_0x4159d1){if(_0x4159d1){return _0x4159d1['destroy']();}})[_0xc934('0x27')](function(_0x4fae62){rimraf(path[_0xc934('0x4d')](config[_0xc934('0x4e')],_0xc934('0x4f'),path[_0xc934('0x8f')](_0x4fae62[_0xc934('0x6')])),function(){});return _0x4fae62;})[_0xc934('0x27')](handleEntityNotFound(_0x340254,null))[_0xc934('0x27')](respondWithStatusCode(_0x340254,null))[_0xc934('0x48')](handleError(_0x340254,null));};exports['webhookGet']=function(_0x55acff,_0x1b0337,_0x8f40e9){return BPromise['resolve']()[_0xc934('0x27')](function(){if(!_0x55acff[_0xc934('0x36')][_0xc934('0x6')]){throw new Error(_0xc934('0x90'));}if(!_0x55acff[_0xc934('0x36')][_0xc934('0x91')]){throw new Error(_0xc934('0x92'));}var _0x4fd2e1=_0x55acff[_0xc934('0x36')][_0xc934('0x93')]?_0x55acff[_0xc934('0x36')]['hostname']+':'+_0x55acff[_0xc934('0x36')][_0xc934('0x91')]:_0xc934('0x94')+_0x55acff[_0xc934('0x36')][_0xc934('0x91')];var _0x5ef64d=_0x55acff[_0xc934('0x36')][_0xc934('0x1f')]?_0x55acff[_0xc934('0x36')][_0xc934('0x1f')]:!![];var _0x379205=_0x55acff[_0xc934('0x36')][_0xc934('0x95')]?_0x55acff[_0xc934('0x36')][_0xc934('0x95')]:null;var _0x3c3bfc={'method':_0x55acff[_0xc934('0x96')],'uri':util[_0xc934('0x50')](_0xc934('0x97'),_0x4fd2e1,_0x55acff['query'][_0xc934('0x6')]),'json':_0x5ef64d,'resolveWithFullResponse':!![],'encoding':_0x379205,'qs':_0x55acff['query']};if(_0x55acff[_0xc934('0x98')]){_0x3c3bfc[_0xc934('0x98')]=_0x55acff[_0xc934('0x98')];if(_0x3c3bfc[_0xc934('0x98')][_0xc934('0x99')]){delete _0x3c3bfc[_0xc934('0x98')][_0xc934('0x99')];}}if(_0x3c3bfc[_0xc934('0x98')][_0xc934('0x9a')]){delete _0x3c3bfc['headers'][_0xc934('0x9a')];}return rp(_0x3c3bfc);})[_0xc934('0x27')](function(_0x54d9bd){if(_0x54d9bd){_0x1b0337['set'](_0x54d9bd[_0xc934('0x98')]);logger[_0xc934('0x61')](_0x54d9bd[_0xc934('0x84')]);if(_[_0xc934('0x9b')](_0x55acff[_0xc934('0x36')][_0xc934('0x6')],_0xc934('0x4b'))&&_0x54d9bd[_0xc934('0x9c')]==0x1f4){return _0x1b0337[_0xc934('0x29')](_0x54d9bd[_0xc934('0x9c')]);}else{return _0x1b0337['status'](_0x54d9bd[_0xc934('0x9c')])[_0xc934('0x2d')](_0x54d9bd[_0xc934('0x84')]);}}else{return _0x1b0337[_0xc934('0x29')](0xc8);}})[_0xc934('0x48')](handleError(_0x1b0337,null));};exports['webhookPost']=function(_0x18471e,_0x29be35,_0x3aa57b){return BPromise[_0xc934('0x9d')]()['then'](function(){if(!_0x18471e['query']['path']){throw new Error(_0xc934('0x90'));}if(!_0x18471e[_0xc934('0x36')][_0xc934('0x91')]){throw new Error(_0xc934('0x92'));}var _0x18ef46=_0x18471e[_0xc934('0x36')]['hostname']?_0x18471e[_0xc934('0x36')][_0xc934('0x93')]+':'+_0x18471e['query'][_0xc934('0x91')]:'http://localhost:'+_0x18471e[_0xc934('0x36')][_0xc934('0x91')];var _0x351682=_0x18471e[_0xc934('0x36')]['json']?_0x18471e[_0xc934('0x36')][_0xc934('0x1f')]:!![];var _0x26c565=_0x18471e['query'][_0xc934('0x95')]?_0x18471e[_0xc934('0x36')][_0xc934('0x95')]:null;var _0xffa283={'method':_0x18471e['method'],'uri':util[_0xc934('0x50')](_0xc934('0x97'),_0x18ef46,_0x18471e[_0xc934('0x36')][_0xc934('0x6')]),'json':_0x351682,'resolveWithFullResponse':!![],'encoding':_0x26c565,'body':_0x18471e[_0xc934('0x84')]};if(_0x18471e[_0xc934('0x98')]){_0xffa283[_0xc934('0x98')]=_0x18471e['headers'];if(_0xffa283[_0xc934('0x98')]['content-length']){delete _0xffa283[_0xc934('0x98')][_0xc934('0x99')];}}if(_0xffa283['headers']['content-type']){delete _0xffa283[_0xc934('0x98')]['content-type'];}return rp(_0xffa283);})[_0xc934('0x27')](function(_0x202088){if(_0x202088){_0x29be35[_0xc934('0x24')](_0x202088[_0xc934('0x98')]);logger['info'](_0x202088[_0xc934('0x84')]);return _0x29be35[_0xc934('0x1e')](_0x202088[_0xc934('0x9c')])['send'](_0x202088[_0xc934('0x84')]);}else{return _0x29be35[_0xc934('0x29')](0xc8);}})['catch'](handleError(_0x29be35,null));};