Built motion from commit (unavailable).|2.3.8
[motion2.git] / server / api / intZendeskAccount / intZendeskAccount.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 _0x92f2=['error','code','message','result','catch','sendStatus','status','json','offset','limit','set','Content-Range','apply','reject','save','destroy','end','name','send','index','ZendeskAccount','model','keys','query','attributes','intersection','fields','hasOwnProperty','order','sort','where','filters','filter','merge','map','type','key','VIRTUAL','field','options','count','include','findAll','show','params','rawAttributes','includeAll','create','body','find','getConfigurations','findOne','ZendeskConfiguration','length','pick','nolimit','addConfiguration','Subjects','getSubjects','Descriptions','getDescriptions','channel','ZendeskField','getFields','password','token','authType','remoteUri','slice','substring','lastIndexOf','GET','format','%s/%s','ticket_fields','Basic\x20%s','%s:%s','username','headers','toString','base64','Sequelize','ValidationError','description','group','assignee','remove','position','title','system_field_options','custom_field_options','test','statusCode','getFields,\x20%s,\x20%s,\x20%s','stringify','Wrong\x20credentials','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','ejs','lodash','squel','crypto','to-csv','querystring','ioredis','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','../../components/integrations/configuration','jayson/promise','client','http','then','info','ZendeskAccount,\x20%s,\x20%s','request\x20sent','debug','ZendeskAccount,\x20%s,\x20%s,\x20%s'];(function(_0x1ec153,_0x6aa9de){var _0x24359b=function(_0x77fa3f){while(--_0x77fa3f){_0x1ec153['push'](_0x1ec153['shift']());}};_0x24359b(++_0x6aa9de);}(_0x92f2,0x15e));var _0x292f=function(_0x2f5ac5,_0x1ee939){_0x2f5ac5=_0x2f5ac5-0x0;var _0x37c9a8=_0x92f2[_0x2f5ac5];return _0x37c9a8;};'use strict';var pdf=require(_0x292f('0x0'));var emlformat=require(_0x292f('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x292f('0x2'));var jsonpatch=require(_0x292f('0x3'));var rp=require(_0x292f('0x4'));var moment=require(_0x292f('0x5'));var BPromise=require(_0x292f('0x6'));var Mustache=require('mustache');var util=require(_0x292f('0x7'));var path=require(_0x292f('0x8'));var sox=require(_0x292f('0x9'));var csv=require('to-csv');var ejs=require(_0x292f('0xa'));var fs=require('fs');var _=require(_0x292f('0xb'));var squel=require(_0x292f('0xc'));var crypto=require(_0x292f('0xd'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x292f('0xe'));var querystring=require(_0x292f('0xf'));var Papa=require('papaparse');var authService=require('../../components/auth/service');var hardwareService=require('../../config/license/hardware');var Redis=require(_0x292f('0x10'));var qs=require('../../components/parsers/qs');var logger=require(_0x292f('0x11'))('api');var utils=require(_0x292f('0x12'));var config=require(_0x292f('0x13'));var db=require(_0x292f('0x14'))['db'];var integrations=require(_0x292f('0x15'));var jayson=require(_0x292f('0x16'));var client=jayson[_0x292f('0x17')][_0x292f('0x18')]({'port':0x232a});function respondWithRpcPromise(_0x304fb2,_0x393a7e,_0x44bf1d,_0x4a30f0){return new BPromise(function(_0x3e3c6d,_0xbbb0fe){var _0x578db6=_0x4a30f0||client;return _0x578db6['request'](_0x304fb2,_0x44bf1d)[_0x292f('0x19')](function(_0x8724a5){logger[_0x292f('0x1a')](_0x292f('0x1b'),_0x393a7e,_0x292f('0x1c'));logger[_0x292f('0x1d')](_0x292f('0x1e'),_0x393a7e,_0x292f('0x1c'),JSON['stringify'](_0x8724a5));if(_0x8724a5[_0x292f('0x1f')]){if(_0x8724a5[_0x292f('0x1f')][_0x292f('0x20')]===0x1f4){logger[_0x292f('0x1f')]('ZendeskAccount,\x20%s,\x20%s',_0x393a7e,_0x8724a5['error'][_0x292f('0x21')]);return _0xbbb0fe(_0x8724a5[_0x292f('0x1f')][_0x292f('0x21')]);}logger[_0x292f('0x1f')](_0x292f('0x1b'),_0x393a7e,_0x8724a5[_0x292f('0x1f')][_0x292f('0x21')]);return _0x3e3c6d(_0x8724a5[_0x292f('0x1f')][_0x292f('0x21')]);}else{logger[_0x292f('0x1a')](_0x292f('0x1b'),_0x393a7e,_0x292f('0x1c'));_0x3e3c6d(_0x8724a5[_0x292f('0x22')]['message']);}})[_0x292f('0x23')](function(_0x11dab6){logger[_0x292f('0x1f')](_0x292f('0x1b'),_0x393a7e,_0x11dab6);_0xbbb0fe(_0x11dab6);});});}function respondWithStatusCode(_0x9133fa,_0x511d60){_0x511d60=_0x511d60||0xcc;return function(_0x4a9f36){if(_0x4a9f36){return _0x9133fa[_0x292f('0x24')](_0x511d60);}return _0x9133fa[_0x292f('0x25')](_0x511d60)['end']();};}function respondWithResult(_0x401808,_0x112e5a){_0x112e5a=_0x112e5a||0xc8;return function(_0x17f799){if(_0x17f799){return _0x401808['status'](_0x112e5a)[_0x292f('0x26')](_0x17f799);}};}function respondWithFilteredResult(_0x2ca528,_0x3140b3){return function(_0x32ba5a){if(_0x32ba5a){var _0x10060e=_0x32ba5a['count'],_0xd0a67a=_0x3140b3[_0x292f('0x27')],_0x44a6eb=_0x3140b3[_0x292f('0x27')]+_0x3140b3[_0x292f('0x28')],_0x439b4c;if(_0x44a6eb>=_0x10060e){_0x44a6eb=_0x10060e;_0x439b4c=0xc8;}else{_0x439b4c=0xce;}_0x2ca528[_0x292f('0x25')](_0x439b4c);return _0x2ca528[_0x292f('0x29')](_0x292f('0x2a'),_0xd0a67a+'-'+_0x44a6eb+'/'+_0x10060e)[_0x292f('0x26')](_0x32ba5a);}return null;};}function patchUpdates(_0x2ffde3){return function(_0x135e6c){try{jsonpatch[_0x292f('0x2b')](_0x135e6c,_0x2ffde3,!![]);}catch(_0x2d3b58){return BPromise[_0x292f('0x2c')](_0x2d3b58);}return _0x135e6c[_0x292f('0x2d')]();};}function saveUpdates(_0x49309d,_0x125bd6){return function(_0x2dce00){if(_0x2dce00){return _0x2dce00['update'](_0x49309d)[_0x292f('0x19')](function(_0x47d244){return _0x47d244;});}return null;};}function removeEntity(_0x5239c0,_0x19b766){return function(_0x408447){if(_0x408447){return _0x408447[_0x292f('0x2e')]()[_0x292f('0x19')](function(){_0x5239c0[_0x292f('0x25')](0xcc)[_0x292f('0x2f')]();});}};}function handleEntityNotFound(_0x4d0f78,_0x59d8a0){return function(_0x26314a){if(!_0x26314a){_0x4d0f78[_0x292f('0x24')](0x194);}return _0x26314a;};}function handleError(_0x4227b0,_0xb24059){_0xb24059=_0xb24059||0x1f4;return function(_0x5ee378){logger[_0x292f('0x1f')](_0x5ee378['stack']);if(_0x5ee378[_0x292f('0x30')]){delete _0x5ee378[_0x292f('0x30')];}_0x4227b0['status'](_0xb24059)[_0x292f('0x31')](_0x5ee378);};}exports[_0x292f('0x32')]=function(_0x3ab1f6,_0x2a0f07){var _0x10c5a7={},_0x5014f3={},_0x593e0e={'count':0x0,'rows':[]};var _0x55b424=db[_0x292f('0x33')]['rawAttributes'];_0x5014f3[_0x292f('0x34')]=_[_0x292f('0x35')](_0x55b424);_0x5014f3[_0x292f('0x36')]=_[_0x292f('0x35')](_0x3ab1f6[_0x292f('0x36')]);_0x5014f3['filters']=_['intersection'](_0x5014f3[_0x292f('0x34')],_0x5014f3[_0x292f('0x36')]);_0x10c5a7[_0x292f('0x37')]=_[_0x292f('0x38')](_0x5014f3[_0x292f('0x34')],qs[_0x292f('0x39')](_0x3ab1f6[_0x292f('0x36')]['fields']));_0x10c5a7[_0x292f('0x37')]=_0x10c5a7['attributes']['length']?_0x10c5a7[_0x292f('0x37')]:_0x5014f3[_0x292f('0x34')];if(!_0x3ab1f6['query'][_0x292f('0x3a')]('nolimit')){_0x10c5a7[_0x292f('0x28')]=qs[_0x292f('0x28')](_0x3ab1f6['query']['limit']);_0x10c5a7[_0x292f('0x27')]=qs[_0x292f('0x27')](_0x3ab1f6[_0x292f('0x36')]['offset']);}_0x10c5a7[_0x292f('0x3b')]=qs[_0x292f('0x3c')](_0x3ab1f6[_0x292f('0x36')]['sort']);_0x10c5a7[_0x292f('0x3d')]=qs[_0x292f('0x3e')](_['pick'](_0x3ab1f6[_0x292f('0x36')],_0x5014f3['filters']));if(_0x3ab1f6[_0x292f('0x36')][_0x292f('0x3f')]){_0x10c5a7[_0x292f('0x3d')]=_[_0x292f('0x40')](_0x10c5a7[_0x292f('0x3d')],{'$or':_[_0x292f('0x41')](_0x55b424,function(_0x5b7dcb){if(_0x5b7dcb[_0x292f('0x42')][_0x292f('0x43')]!==_0x292f('0x44')){var _0x34f430={};_0x34f430[_0x5b7dcb[_0x292f('0x45')]]={'$like':'%'+_0x3ab1f6[_0x292f('0x36')][_0x292f('0x3f')]+'%'};return _0x34f430;}})});}_0x10c5a7=_['merge']({},_0x10c5a7,_0x3ab1f6[_0x292f('0x46')]);var _0x886eef={'where':_0x10c5a7[_0x292f('0x3d')]};return db[_0x292f('0x33')][_0x292f('0x47')](_0x886eef)[_0x292f('0x19')](function(_0xc5783d){_0x593e0e['count']=_0xc5783d;if(_0x3ab1f6[_0x292f('0x36')]['includeAll']){_0x10c5a7[_0x292f('0x48')]=[{'all':!![]}];}return db[_0x292f('0x33')][_0x292f('0x49')](_0x10c5a7);})['then'](function(_0x99662a){_0x593e0e['rows']=_0x99662a;return _0x593e0e;})['then'](respondWithFilteredResult(_0x2a0f07,_0x10c5a7))[_0x292f('0x23')](handleError(_0x2a0f07,null));};exports[_0x292f('0x4a')]=function(_0x5dfec7,_0x3f32e3){var _0x2a87c8={'raw':![],'where':{'id':_0x5dfec7[_0x292f('0x4b')]['id']}},_0x12a8b7={};_0x12a8b7[_0x292f('0x34')]=_[_0x292f('0x35')](db['ZendeskAccount'][_0x292f('0x4c')]);_0x12a8b7[_0x292f('0x36')]=_['keys'](_0x5dfec7[_0x292f('0x36')]);_0x12a8b7['filters']=_['intersection'](_0x12a8b7[_0x292f('0x34')],_0x12a8b7[_0x292f('0x36')]);_0x2a87c8[_0x292f('0x37')]=_[_0x292f('0x38')](_0x12a8b7['model'],qs[_0x292f('0x39')](_0x5dfec7[_0x292f('0x36')]['fields']));_0x2a87c8[_0x292f('0x37')]=_0x2a87c8[_0x292f('0x37')]['length']?_0x2a87c8[_0x292f('0x37')]:_0x12a8b7[_0x292f('0x34')];if(_0x5dfec7[_0x292f('0x36')][_0x292f('0x4d')]){_0x2a87c8['include']=[{'all':!![]}];}_0x2a87c8=_['merge']({},_0x2a87c8,_0x5dfec7[_0x292f('0x46')]);return db[_0x292f('0x33')]['find'](_0x2a87c8)[_0x292f('0x19')](handleEntityNotFound(_0x3f32e3,null))[_0x292f('0x19')](respondWithResult(_0x3f32e3,null))[_0x292f('0x23')](handleError(_0x3f32e3,null));};exports[_0x292f('0x4e')]=function(_0xd2630e,_0x52fe46){return db[_0x292f('0x33')][_0x292f('0x4e')](_0xd2630e['body'],{})[_0x292f('0x19')](respondWithResult(_0x52fe46,0xc9))[_0x292f('0x23')](handleError(_0x52fe46,null));};exports['update']=function(_0x361e54,_0x1ca1ca){if(_0x361e54['body']['id']){delete _0x361e54[_0x292f('0x4f')]['id'];}return db[_0x292f('0x33')]['find']({'where':{'id':_0x361e54['params']['id']}})['then'](handleEntityNotFound(_0x1ca1ca,null))['then'](saveUpdates(_0x361e54['body'],null))[_0x292f('0x19')](respondWithResult(_0x1ca1ca,null))[_0x292f('0x23')](handleError(_0x1ca1ca,null));};exports['destroy']=function(_0x5c94ed,_0x2fccc3){return db[_0x292f('0x33')][_0x292f('0x50')]({'where':{'id':_0x5c94ed[_0x292f('0x4b')]['id']}})[_0x292f('0x19')](handleEntityNotFound(_0x2fccc3,null))['then'](removeEntity(_0x2fccc3,null))['catch'](handleError(_0x2fccc3,null));};exports[_0x292f('0x51')]=function(_0x1f88b4,_0x4990d2,_0x1faf42){var _0x154a9a={};var _0x208d61={};var _0x41ead6;var _0x2934db;return db[_0x292f('0x33')][_0x292f('0x52')]({'where':{'id':_0x1f88b4[_0x292f('0x4b')]['id']}})['then'](handleEntityNotFound(_0x4990d2,null))[_0x292f('0x19')](function(_0x2a9db2){if(_0x2a9db2){_0x41ead6=_0x2a9db2;_0x208d61[_0x292f('0x34')]=_[_0x292f('0x35')](db[_0x292f('0x53')][_0x292f('0x4c')]);_0x208d61[_0x292f('0x36')]=_[_0x292f('0x35')](_0x1f88b4[_0x292f('0x36')]);_0x208d61[_0x292f('0x3e')]=_[_0x292f('0x38')](_0x208d61[_0x292f('0x34')],_0x208d61[_0x292f('0x36')]);_0x154a9a[_0x292f('0x37')]=_[_0x292f('0x38')](_0x208d61['model'],qs[_0x292f('0x39')](_0x1f88b4['query'][_0x292f('0x39')]));_0x154a9a[_0x292f('0x37')]=_0x154a9a[_0x292f('0x37')][_0x292f('0x54')]?_0x154a9a[_0x292f('0x37')]:_0x208d61['model'];_0x154a9a[_0x292f('0x3b')]=qs[_0x292f('0x3c')](_0x1f88b4[_0x292f('0x36')][_0x292f('0x3c')]);_0x154a9a[_0x292f('0x3d')]=qs['filters'](_[_0x292f('0x55')](_0x1f88b4['query'],_0x208d61[_0x292f('0x3e')]));if(_0x1f88b4['query'][_0x292f('0x3f')]){_0x154a9a['where']=_['merge'](_0x154a9a['where'],{'$or':_[_0x292f('0x41')](_0x154a9a[_0x292f('0x37')],function(_0xcb3059){var _0x2ba965={};_0x2ba965[_0xcb3059]={'$like':'%'+_0x1f88b4[_0x292f('0x36')]['filter']+'%'};return _0x2ba965;})});}_0x154a9a=_[_0x292f('0x40')]({},_0x154a9a,_0x1f88b4[_0x292f('0x46')]);return _0x41ead6['getConfigurations'](_0x154a9a);}})[_0x292f('0x19')](function(_0x546d64){if(_0x546d64){_0x2934db=_0x546d64[_0x292f('0x54')];if(!_0x1f88b4[_0x292f('0x36')][_0x292f('0x3a')](_0x292f('0x56'))){_0x154a9a[_0x292f('0x28')]=qs[_0x292f('0x28')](_0x1f88b4[_0x292f('0x36')][_0x292f('0x28')]);_0x154a9a[_0x292f('0x27')]=qs[_0x292f('0x27')](_0x1f88b4[_0x292f('0x36')][_0x292f('0x27')]);}return _0x41ead6['getConfigurations'](_0x154a9a);}})['then'](function(_0x7d4902){if(_0x7d4902){return _0x7d4902?{'count':_0x2934db,'rows':_0x7d4902}:null;}})[_0x292f('0x19')](respondWithResult(_0x4990d2,null))[_0x292f('0x23')](handleError(_0x4990d2,null));};exports[_0x292f('0x57')]=function(_0x460f10,_0x35cf11,_0x5b6eea){if(_0x460f10[_0x292f('0x4f')]['id']){delete _0x460f10[_0x292f('0x4f')]['id'];}return db[_0x292f('0x33')][_0x292f('0x52')]({'where':{'id':_0x460f10[_0x292f('0x4b')]['id']}})['then'](handleEntityNotFound(_0x35cf11,null))[_0x292f('0x19')](function(_0x2256fa){if(_0x2256fa){_0x460f10[_0x292f('0x4f')]['AccountId']=_0x2256fa['id'];_0x460f10[_0x292f('0x4f')][_0x292f('0x58')]=integrations[_0x292f('0x59')](_0x460f10[_0x292f('0x4f')]['channel'],_0x460f10[_0x292f('0x4f')][_0x292f('0x42')]);_0x460f10[_0x292f('0x4f')][_0x292f('0x5a')]=integrations[_0x292f('0x5b')](_0x460f10[_0x292f('0x4f')][_0x292f('0x5c')],_0x460f10[_0x292f('0x4f')]['type']);return db[_0x292f('0x53')][_0x292f('0x4e')](_0x460f10[_0x292f('0x4f')],{'include':[{'model':db[_0x292f('0x5d')],'as':'Subjects'},{'model':db[_0x292f('0x5d')],'as':_0x292f('0x5a')}]});}return null;})['then'](respondWithResult(_0x35cf11,null))[_0x292f('0x23')](handleError(_0x35cf11,null));};exports[_0x292f('0x5e')]=function(_0x4ed6fe,_0x3f6a31,_0x1d6464){var _0x572699='';return db[_0x292f('0x33')][_0x292f('0x52')]({'where':{'id':_0x4ed6fe['params']['id']},'attributes':['id','username',_0x292f('0x5f'),_0x292f('0x60'),_0x292f('0x61'),_0x292f('0x62')]})[_0x292f('0x19')](handleEntityNotFound(_0x3f6a31,null))['then'](function(_0x4ecfb6){if(_0x4ecfb6){_0x572699=_0x4ecfb6['remoteUri'];var _0x10fe0d=_0x572699[_0x292f('0x63')](-0x1);if(_0x10fe0d==='/'){_0x572699=_0x572699[_0x292f('0x64')](0x0,_0x572699[_0x292f('0x65')](_0x10fe0d));}var _0x49d7a3={'method':_0x292f('0x66'),'uri':util[_0x292f('0x67')](_0x292f('0x68'),_0x572699,_0x292f('0x69')),'json':!![]};switch(_0x4ecfb6[_0x292f('0x61')]){case'password':_0x49d7a3['headers']={'Authorization':util[_0x292f('0x67')](_0x292f('0x6a'),new Buffer(util[_0x292f('0x67')](_0x292f('0x6b'),_0x4ecfb6[_0x292f('0x6c')],_0x4ecfb6[_0x292f('0x5f')]))['toString']('base64'))};break;case _0x292f('0x60'):_0x49d7a3[_0x292f('0x6d')]={'Authorization':util[_0x292f('0x67')](_0x292f('0x6a'),new Buffer(util[_0x292f('0x67')]('%s/token:%s',_0x4ecfb6[_0x292f('0x6c')],_0x4ecfb6[_0x292f('0x60')]))[_0x292f('0x6e')](_0x292f('0x6f')))};break;default:throw new db[(_0x292f('0x70'))][(_0x292f('0x71'))]('Unknown\x20authentication\x20type');}return rp(_0x49d7a3);}})[_0x292f('0x19')](function(_0x33e09d){if(_0x33e09d){var _0x2c2319=['subject',_0x292f('0x72'),_0x292f('0x73'),_0x292f('0x74')];_[_0x292f('0x75')](_0x33e09d[_0x292f('0x69')],function(_0x802560){return _0x2c2319['includes'](_0x802560[_0x292f('0x42')]);});return{'count':_0x33e09d['ticket_fields'][_0x292f('0x54')],'rows':_['map'](_0x33e09d[_0x292f('0x69')],function(_0x3bc12f){return{'id':_0x3bc12f['id'],'name':_0x3bc12f[_0x292f('0x76')]>0x7?_0x3bc12f[_0x292f('0x77')]:_0x3bc12f[_0x292f('0x42')],'custom':_0x3bc12f['position']>0x7?!![]:![],'options':_0x3bc12f[_0x292f('0x78')]?_0x3bc12f[_0x292f('0x78')]:_0x3bc12f[_0x292f('0x79')]?_0x3bc12f[_0x292f('0x79')]:[]};})};}})[_0x292f('0x19')](respondWithResult(_0x3f6a31,null))[_0x292f('0x23')](function(_0x255c5d){var _0x153877=_0x4ed6fe[_0x292f('0x36')][_0x292f('0x7a')]?0x1f4:_0x255c5d[_0x292f('0x7b')]||0x1f4;logger[_0x292f('0x1f')](_0x292f('0x7c'),'getFields',_0x153877,JSON[_0x292f('0x7d')](_0x255c5d));delete _0x255c5d[_0x292f('0x30')];if(_0x153877===0x191){_0x153877=0x190;}_0x3f6a31['status'](_0x153877)[_0x292f('0x31')](_0x4ed6fe[_0x292f('0x36')][_0x292f('0x7a')]?{'message':_0x292f('0x7e'),'statusCode':_0x255c5d[_0x292f('0x7b')]}:_0x255c5d);});};