603cf79e8bd69a106f1041045a590ed83f8adda3
[motion2.git] / server / api / intDynamics365Account / intDynamics365Account.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 _0xffae=['PicklistAttributeMetadata','push','all','isNil','BooleanAttributeMetadata','StringAttributeMetadata','DoubleAttributeMetadata','IntegerAttributeMetadata','DateTimeAttributeMetadata','StatusAttributeMetadata','EntityNameAttributeMetadata','statusCode','EntityDefinitions(',')/Attributes(',')/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?','$select=DisplayName,LogicalName&$expand=OptionSet($select=Options)','OptionSet','Options','Label','UserLocalizedLabel','Value','DisplayName',')/Microsoft.Dynamics.CRM.BooleanAttributeMetadata?$select=DisplayName,LogicalName&$expand=OptionSet($select=FalseOption,\x20TrueOption)','TrueOption','true','?$select=DisplayName,LogicalName','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','bluebird','util','path','sox','to-csv','ejs','squel','desk.js','querystring','../../components/parsers/qs','../../config/license/hardware','../../config/environment','../../mysqldb','../../components/integrations/configuration','jayson/promise','http','test','ValidationError','request','info','request\x20sent','debug','Dynamics365Account,\x20%s,\x20%s,\x20%s','error','code','Dynamics365Account,\x20%s,\x20%s','message','result','sendStatus','status','end','count','offset','limit','set','Content-Range','apply','reject','save','then','stack','name','send','index','map','Dynamics365Account','rawAttributes','type','key','model','filters','intersection','query','attributes','fields','length','hasOwnProperty','nolimit','sort','where','pick','filter','include','findAll','rows','catch','show','keys','includeAll','merge','options','create','body','find','params','destroy','getConfigurations','findOne','addConfiguration','AccountId','Subjects','getSubjects','channel','getDescriptions','Dynamics365Field','Descriptions','ticketType','incident','Incident','title','description','ownerid','subject','phonenumber','directioncode','phonecall_activity_parties','accountidyominame','actualserviceunits','contractdetailidname','contractidname','createdbyexternalpartyname','createdbyexternalpartyyominame','createdbyname','createdbyyominame','createdonbehalfbyname','createdonbehalfbyyominame','customeridname','customeridtype','emailaddress','entityimage_url','escalatedon','followupby','importsequencenumber','influencescore','lastonholdtime','modifiedbyexternalpartyname','modifiedbyexternalpartyyominame','modifiedbyname','modifiedon','modifiedonbehalfbyname','msdyn_incidenttypename','msdyn_iotalertname','onholdtime','overriddencreatedon','owneridtype','owneridyominame','primarycontactidname','prioritycodename','productidname','productserialnumber','resolveby','resolvebykpiidname','responseby','responsiblecontactidname','sentimentvalue','slainvokedidname','slaname','socialprofileidname','statecode','statuscode','subjectidname','ticketnumber','timezoneruleversionnumber','transactioncurrencyidname','traversedpath','utcconversiontimezonecode','versionnumber','concat','tenantId','clientId','clientSecret','slice','format','%s/api/data/v9.0/','POST','https://login.microsoftonline.com/','/oauth2/token','username','password','GET','EntityDefinitions?$select=DisplayName,EntitySetName&$filter=SchemaName\x20eq\x20\x27','Bearer\x20','4.0','value','MetadataId',')?$select=LogicalName&$expand=Attributes($select=LogicalName)','includes','LogicalName','forEach','@odata.type','substring','lastIndexOf'];(function(_0x2c91e9,_0x2fb965){var _0x13f0ff=function(_0xb39edf){while(--_0xb39edf){_0x2c91e9['push'](_0x2c91e9['shift']());}};_0x13f0ff(++_0x2fb965);}(_0xffae,0xe5));var _0xeffa=function(_0x3ffbe7,_0x285590){_0x3ffbe7=_0x3ffbe7-0x0;var _0x523639=_0xffae[_0x3ffbe7];return _0x523639;};'use strict';var pdf=require(_0xeffa('0x0'));var emlformat=require(_0xeffa('0x1'));var rimraf=require('rimraf');var zipdir=require(_0xeffa('0x2'));var jsonpatch=require(_0xeffa('0x3'));var rp=require(_0xeffa('0x4'));var moment=require('moment');var BPromise=require(_0xeffa('0x5'));var Mustache=require('mustache');var util=require(_0xeffa('0x6'));var path=require(_0xeffa('0x7'));var sox=require(_0xeffa('0x8'));var csv=require(_0xeffa('0x9'));var ejs=require(_0xeffa('0xa'));var fs=require('fs');var _=require('lodash');var squel=require(_0xeffa('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0xeffa('0xc'));var toCsv=require('to-csv');var querystring=require(_0xeffa('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xeffa('0xe'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xeffa('0xf'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require(_0xeffa('0x10'));var db=require(_0xeffa('0x11'))['db'];var integrations=require(_0xeffa('0x12'));var jayson=require(_0xeffa('0x13'));var client=jayson['client'][_0xeffa('0x14')]({'port':0x232a});function checkPasswordPattern(_0x376b95,_0x201c43,_0x313506){if(_0x313506){var _0x37cf52=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x37cf52[_0xeffa('0x15')](_0x201c43)){return _0x376b95;}else{throw new db['Sequelize'][(_0xeffa('0x16'))]('The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.');}}else{return _0x376b95;}}function respondWithRpcPromise(_0x5edaa9,_0xb0b25c,_0x30fa0c,_0x8358b9){return new BPromise(function(_0x416c19,_0x2b4584){var _0x5cf81b=_0x8358b9||client;return _0x5cf81b[_0xeffa('0x17')](_0x5edaa9,_0x30fa0c)['then'](function(_0x46e624){logger[_0xeffa('0x18')]('Dynamics365Account,\x20%s,\x20%s',_0xb0b25c,_0xeffa('0x19'));logger[_0xeffa('0x1a')](_0xeffa('0x1b'),_0xb0b25c,_0xeffa('0x19'),JSON['stringify'](_0x46e624));if(_0x46e624['error']){if(_0x46e624[_0xeffa('0x1c')][_0xeffa('0x1d')]===0x1f4){logger['error'](_0xeffa('0x1e'),_0xb0b25c,_0x46e624[_0xeffa('0x1c')][_0xeffa('0x1f')]);return _0x2b4584(_0x46e624[_0xeffa('0x1c')]['message']);}logger['error'](_0xeffa('0x1e'),_0xb0b25c,_0x46e624['error'][_0xeffa('0x1f')]);return _0x416c19(_0x46e624['error'][_0xeffa('0x1f')]);}else{logger[_0xeffa('0x18')](_0xeffa('0x1e'),_0xb0b25c,_0xeffa('0x19'));_0x416c19(_0x46e624[_0xeffa('0x20')][_0xeffa('0x1f')]);}})['catch'](function(_0x56217a){logger['error'](_0xeffa('0x1e'),_0xb0b25c,_0x56217a);_0x2b4584(_0x56217a);});});}function respondWithStatusCode(_0x27b10c,_0xb89200){_0xb89200=_0xb89200||0xcc;return function(_0x2df0e9){if(_0x2df0e9){return _0x27b10c[_0xeffa('0x21')](_0xb89200);}return _0x27b10c[_0xeffa('0x22')](_0xb89200)[_0xeffa('0x23')]();};}function respondWithResult(_0x3eb4e8,_0x11deb9){_0x11deb9=_0x11deb9||0xc8;return function(_0x5aa49b){if(_0x5aa49b){return _0x3eb4e8[_0xeffa('0x22')](_0x11deb9)['json'](_0x5aa49b);}};}function respondWithFilteredResult(_0x536149,_0x325cdb){return function(_0x337e53){if(_0x337e53){var _0x21c027=_0x337e53[_0xeffa('0x24')],_0x1a00c1=_0x325cdb[_0xeffa('0x25')],_0x134f08=_0x325cdb[_0xeffa('0x25')]+_0x325cdb[_0xeffa('0x26')],_0x4f3e09;if(_0x134f08>=_0x21c027){_0x134f08=_0x21c027;_0x4f3e09=0xc8;}else{_0x4f3e09=0xce;}_0x536149[_0xeffa('0x22')](_0x4f3e09);return _0x536149[_0xeffa('0x27')](_0xeffa('0x28'),_0x1a00c1+'-'+_0x134f08+'/'+_0x21c027)['json'](_0x337e53);}return null;};}function patchUpdates(_0x21774f){return function(_0x43d0fa){try{jsonpatch[_0xeffa('0x29')](_0x43d0fa,_0x21774f,!![]);}catch(_0x4aa661){return BPromise[_0xeffa('0x2a')](_0x4aa661);}return _0x43d0fa[_0xeffa('0x2b')]();};}function saveUpdates(_0x233777,_0x25c0fc){return function(_0x34840f){if(_0x34840f){return _0x34840f['update'](_0x233777)[_0xeffa('0x2c')](function(_0x2fb6fd){return _0x2fb6fd;});}return null;};}function removeEntity(_0x5456b4,_0x43c89f){return function(_0x5dcb0c){if(_0x5dcb0c){return _0x5dcb0c['destroy']()[_0xeffa('0x2c')](function(){_0x5456b4[_0xeffa('0x22')](0xcc)[_0xeffa('0x23')]();});}};}function handleEntityNotFound(_0x38d858,_0x361aa6){return function(_0x5c10be){if(!_0x5c10be){_0x38d858[_0xeffa('0x21')](0x194);}return _0x5c10be;};}function handleError(_0x593c8d,_0x357101){_0x357101=_0x357101||0x1f4;return function(_0x482144){logger[_0xeffa('0x1c')](_0x482144[_0xeffa('0x2d')]);if(_0x482144[_0xeffa('0x2e')]){delete _0x482144[_0xeffa('0x2e')];}_0x593c8d[_0xeffa('0x22')](_0x357101)[_0xeffa('0x2f')](_0x482144);};}exports[_0xeffa('0x30')]=function(_0x4aa854,_0x3240d3){var _0x1e0fcc={},_0x1e482c={},_0x28278d={'count':0x0,'rows':[]};var _0x1acbb8=_[_0xeffa('0x31')](db[_0xeffa('0x32')][_0xeffa('0x33')],function(_0x3d6a5b){return{'name':_0x3d6a5b['fieldName'],'type':_0x3d6a5b[_0xeffa('0x34')][_0xeffa('0x35')]};});_0x1e482c[_0xeffa('0x36')]=_['map'](_0x1acbb8,'name');_0x1e482c['query']=_['keys'](_0x4aa854['query']);_0x1e482c[_0xeffa('0x37')]=_[_0xeffa('0x38')](_0x1e482c[_0xeffa('0x36')],_0x1e482c[_0xeffa('0x39')]);_0x1e0fcc[_0xeffa('0x3a')]=_[_0xeffa('0x38')](_0x1e482c[_0xeffa('0x36')],qs[_0xeffa('0x3b')](_0x4aa854[_0xeffa('0x39')]['fields']));_0x1e0fcc[_0xeffa('0x3a')]=_0x1e0fcc['attributes'][_0xeffa('0x3c')]?_0x1e0fcc[_0xeffa('0x3a')]:_0x1e482c[_0xeffa('0x36')];if(!_0x4aa854[_0xeffa('0x39')][_0xeffa('0x3d')](_0xeffa('0x3e'))){_0x1e0fcc[_0xeffa('0x26')]=qs['limit'](_0x4aa854[_0xeffa('0x39')]['limit']);_0x1e0fcc[_0xeffa('0x25')]=qs[_0xeffa('0x25')](_0x4aa854[_0xeffa('0x39')][_0xeffa('0x25')]);}_0x1e0fcc['order']=qs['sort'](_0x4aa854['query'][_0xeffa('0x3f')]);_0x1e0fcc[_0xeffa('0x40')]=qs[_0xeffa('0x37')](_[_0xeffa('0x41')](_0x4aa854[_0xeffa('0x39')],_0x1e482c['filters']),_0x1acbb8);if(_0x4aa854[_0xeffa('0x39')][_0xeffa('0x42')]){_0x1e0fcc[_0xeffa('0x40')]=_['merge'](_0x1e0fcc[_0xeffa('0x40')],{'$or':_['map'](_0x1acbb8,function(_0x34a9d8){if(_0x34a9d8[_0xeffa('0x34')]!=='VIRTUAL'){var _0x30ae60={};_0x30ae60[_0x34a9d8[_0xeffa('0x2e')]]={'$like':'%'+_0x4aa854[_0xeffa('0x39')]['filter']+'%'};return _0x30ae60;}})});}_0x1e0fcc=_['merge']({},_0x1e0fcc,_0x4aa854['options']);var _0x5aeb75={'where':_0x1e0fcc[_0xeffa('0x40')]};return db[_0xeffa('0x32')][_0xeffa('0x24')](_0x5aeb75)[_0xeffa('0x2c')](function(_0x13c2e8){_0x28278d[_0xeffa('0x24')]=_0x13c2e8;if(_0x4aa854['query']['includeAll']){_0x1e0fcc[_0xeffa('0x43')]=[{'all':!![]}];}return db[_0xeffa('0x32')][_0xeffa('0x44')](_0x1e0fcc);})[_0xeffa('0x2c')](function(_0x22286c){_0x28278d[_0xeffa('0x45')]=_0x22286c;return _0x28278d;})[_0xeffa('0x2c')](respondWithFilteredResult(_0x3240d3,_0x1e0fcc))[_0xeffa('0x46')](handleError(_0x3240d3,null));};exports[_0xeffa('0x47')]=function(_0x108be6,_0x455cc9){var _0x223125={'raw':![],'where':{'id':_0x108be6['params']['id']}},_0x25c8f5={};_0x25c8f5[_0xeffa('0x36')]=_['keys'](db[_0xeffa('0x32')][_0xeffa('0x33')]);_0x25c8f5[_0xeffa('0x39')]=_[_0xeffa('0x48')](_0x108be6['query']);_0x25c8f5[_0xeffa('0x37')]=_[_0xeffa('0x38')](_0x25c8f5[_0xeffa('0x36')],_0x25c8f5[_0xeffa('0x39')]);_0x223125[_0xeffa('0x3a')]=_[_0xeffa('0x38')](_0x25c8f5[_0xeffa('0x36')],qs[_0xeffa('0x3b')](_0x108be6[_0xeffa('0x39')]['fields']));_0x223125[_0xeffa('0x3a')]=_0x223125['attributes'][_0xeffa('0x3c')]?_0x223125['attributes']:_0x25c8f5[_0xeffa('0x36')];if(_0x108be6[_0xeffa('0x39')][_0xeffa('0x49')]){_0x223125[_0xeffa('0x43')]=[{'all':!![]}];}_0x223125=_[_0xeffa('0x4a')]({},_0x223125,_0x108be6[_0xeffa('0x4b')]);return db[_0xeffa('0x32')]['find'](_0x223125)['then'](handleEntityNotFound(_0x455cc9,null))[_0xeffa('0x2c')](respondWithResult(_0x455cc9,null))['catch'](handleError(_0x455cc9,null));};exports[_0xeffa('0x4c')]=function(_0x273f15,_0xa0f374){return db[_0xeffa('0x32')][_0xeffa('0x4c')](_0x273f15[_0xeffa('0x4d')],{})['then'](respondWithResult(_0xa0f374,0xc9))[_0xeffa('0x46')](handleError(_0xa0f374,null));};exports['update']=function(_0x39e632,_0x46c8c5){if(_0x39e632[_0xeffa('0x4d')]['id']){delete _0x39e632[_0xeffa('0x4d')]['id'];}return db['Dynamics365Account'][_0xeffa('0x4e')]({'where':{'id':_0x39e632[_0xeffa('0x4f')]['id']}})[_0xeffa('0x2c')](handleEntityNotFound(_0x46c8c5,null))['then'](saveUpdates(_0x39e632[_0xeffa('0x4d')],null))[_0xeffa('0x2c')](respondWithResult(_0x46c8c5,null))[_0xeffa('0x46')](handleError(_0x46c8c5,null));};exports[_0xeffa('0x50')]=function(_0x1df54a,_0x52f51e){return db['Dynamics365Account']['find']({'where':{'id':_0x1df54a[_0xeffa('0x4f')]['id']}})[_0xeffa('0x2c')](handleEntityNotFound(_0x52f51e,null))[_0xeffa('0x2c')](removeEntity(_0x52f51e,null))[_0xeffa('0x46')](handleError(_0x52f51e,null));};exports[_0xeffa('0x51')]=function(_0x180d33,_0x56faa0,_0x39d969){var _0x593b23={};var _0x5cea1a={};var _0x1fb7e0;var _0x10be99;return db[_0xeffa('0x32')][_0xeffa('0x52')]({'where':{'id':_0x180d33[_0xeffa('0x4f')]['id']}})[_0xeffa('0x2c')](handleEntityNotFound(_0x56faa0,null))[_0xeffa('0x2c')](function(_0x3d9f98){if(_0x3d9f98){_0x1fb7e0=_0x3d9f98;_0x5cea1a['model']=_[_0xeffa('0x48')](db['Dynamics365Configuration'][_0xeffa('0x33')]);_0x5cea1a[_0xeffa('0x39')]=_['keys'](_0x180d33['query']);_0x5cea1a[_0xeffa('0x37')]=_[_0xeffa('0x38')](_0x5cea1a[_0xeffa('0x36')],_0x5cea1a[_0xeffa('0x39')]);_0x593b23[_0xeffa('0x3a')]=_[_0xeffa('0x38')](_0x5cea1a[_0xeffa('0x36')],qs[_0xeffa('0x3b')](_0x180d33[_0xeffa('0x39')][_0xeffa('0x3b')]));_0x593b23[_0xeffa('0x3a')]=_0x593b23[_0xeffa('0x3a')]['length']?_0x593b23[_0xeffa('0x3a')]:_0x5cea1a[_0xeffa('0x36')];_0x593b23['order']=qs['sort'](_0x180d33[_0xeffa('0x39')][_0xeffa('0x3f')]);_0x593b23['where']=qs[_0xeffa('0x37')](_[_0xeffa('0x41')](_0x180d33[_0xeffa('0x39')],_0x5cea1a[_0xeffa('0x37')]));if(_0x180d33[_0xeffa('0x39')]['filter']){_0x593b23[_0xeffa('0x40')]=_[_0xeffa('0x4a')](_0x593b23[_0xeffa('0x40')],{'$or':_[_0xeffa('0x31')](_0x593b23['attributes'],function(_0x1dfba1){var _0x44e732={};_0x44e732[_0x1dfba1]={'$like':'%'+_0x180d33[_0xeffa('0x39')][_0xeffa('0x42')]+'%'};return _0x44e732;})});}_0x593b23=_['merge']({},_0x593b23,_0x180d33[_0xeffa('0x4b')]);return _0x1fb7e0[_0xeffa('0x51')](_0x593b23);}})[_0xeffa('0x2c')](function(_0x2480af){if(_0x2480af){_0x10be99=_0x2480af[_0xeffa('0x3c')];if(!_0x180d33[_0xeffa('0x39')][_0xeffa('0x3d')]('nolimit')){_0x593b23[_0xeffa('0x26')]=qs[_0xeffa('0x26')](_0x180d33[_0xeffa('0x39')][_0xeffa('0x26')]);_0x593b23[_0xeffa('0x25')]=qs[_0xeffa('0x25')](_0x180d33[_0xeffa('0x39')]['offset']);}return _0x1fb7e0[_0xeffa('0x51')](_0x593b23);}})[_0xeffa('0x2c')](function(_0x1cfdf0){if(_0x1cfdf0){return _0x1cfdf0?{'count':_0x10be99,'rows':_0x1cfdf0}:null;}})[_0xeffa('0x2c')](respondWithResult(_0x56faa0,null))['catch'](handleError(_0x56faa0,null));};exports[_0xeffa('0x53')]=function(_0x242a43,_0x116edf,_0x1f0afb){if(_0x242a43['body']['id']){delete _0x242a43[_0xeffa('0x4d')]['id'];}return db[_0xeffa('0x32')][_0xeffa('0x52')]({'where':{'id':_0x242a43['params']['id']}})['then'](handleEntityNotFound(_0x116edf,null))[_0xeffa('0x2c')](function(_0x16f773){if(_0x16f773){_0x242a43[_0xeffa('0x4d')][_0xeffa('0x54')]=_0x16f773['id'];_0x242a43['body'][_0xeffa('0x55')]=integrations[_0xeffa('0x56')](_0x242a43[_0xeffa('0x4d')][_0xeffa('0x57')],_0x242a43['body'][_0xeffa('0x34')]);_0x242a43[_0xeffa('0x4d')]['Descriptions']=integrations[_0xeffa('0x58')](_0x242a43['body'][_0xeffa('0x57')],_0x242a43[_0xeffa('0x4d')]['type']);return db['Dynamics365Configuration']['create'](_0x242a43[_0xeffa('0x4d')],{'include':[{'model':db['Dynamics365Field'],'as':_0xeffa('0x55')},{'model':db[_0xeffa('0x59')],'as':_0xeffa('0x5a')}]});}return null;})[_0xeffa('0x2c')](respondWithResult(_0x116edf,null))[_0xeffa('0x46')](handleError(_0x116edf,null));};exports['getFields']=function(_0x265fd6,_0x5f516a,_0x2f4ff5){var _0xd7c4ed=_0x265fd6[_0xeffa('0x39')][_0xeffa('0x5b')];var _0xaee7c2=_0xd7c4ed===_0xeffa('0x5c')?_0xeffa('0x5d'):'PhoneCall';var _0x96b6df='';var _0x5ce4da='';var _0x41a2ae='';var _0x57e8bb='';var _0x194f8b='';var _0x59dfd='';var _0x53234a='';var _0x51f585='';var _0x40b96e=[_0xeffa('0x5e'),_0xeffa('0x5f'),'customerid',_0xeffa('0x60'),'caseorigincode',_0xeffa('0x61'),_0xeffa('0x62'),'regardingobjectid',_0xeffa('0x63'),_0xeffa('0x64')];var _0x1935cb=['accountidname',_0xeffa('0x65'),_0xeffa('0x66'),'billedserviceunits','contactidname','contactidyominame',_0xeffa('0x67'),_0xeffa('0x68'),_0xeffa('0x69'),_0xeffa('0x6a'),_0xeffa('0x6b'),_0xeffa('0x6c'),'createdon',_0xeffa('0x6d'),_0xeffa('0x6e'),_0xeffa('0x6f'),_0xeffa('0x70'),'customeridyominame',_0xeffa('0x71'),'entitlementidname','entityimage_timestamp',_0xeffa('0x72'),_0xeffa('0x73'),'exchangerate','firstresponsebykpiidname',_0xeffa('0x74'),_0xeffa('0x75'),_0xeffa('0x76'),'kbarticleidname',_0xeffa('0x77'),'masteridname',_0xeffa('0x78'),_0xeffa('0x79'),_0xeffa('0x7a'),'modifiedbyyominame',_0xeffa('0x7b'),_0xeffa('0x7c'),'modifiedonbehalfbyyominame',_0xeffa('0x7d'),_0xeffa('0x7e'),'numberofchildincidents',_0xeffa('0x7f'),_0xeffa('0x80'),'owneridname',_0xeffa('0x81'),_0xeffa('0x82'),'parentcaseidname',_0xeffa('0x83'),'primarycontactidyominame',_0xeffa('0x84'),_0xeffa('0x85'),_0xeffa('0x86'),_0xeffa('0x87'),_0xeffa('0x88'),_0xeffa('0x89'),_0xeffa('0x8a'),'responsiblecontactidyominame',_0xeffa('0x8b'),_0xeffa('0x8c'),_0xeffa('0x8d'),_0xeffa('0x8e'),_0xeffa('0x8f'),_0xeffa('0x90'),_0xeffa('0x91'),_0xeffa('0x92'),_0xeffa('0x93'),_0xeffa('0x94'),_0xeffa('0x95'),_0xeffa('0x96'),_0xeffa('0x97')];var _0x4fbbce=_0x40b96e[_0xeffa('0x98')](_0x1935cb);return db[_0xeffa('0x32')]['findOne']({'where':{'id':_0x265fd6[_0xeffa('0x4f')]['id']},'attributes':['id','username','password','remoteUri',_0xeffa('0x99'),_0xeffa('0x9a'),_0xeffa('0x9b')]})['then'](handleEntityNotFound(_0x5f516a,null))[_0xeffa('0x2c')](function(_0x2b3bc2){if(_0x2b3bc2){_0x51f585=_0x2b3bc2['remoteUri'];var _0x5259ca=_0x51f585[_0xeffa('0x9c')](-0x1);if(_0x5259ca==='/'){_0x51f585=_0x51f585['substring'](0x0,_0x51f585['lastIndexOf'](_0x5259ca));}_0x53234a=util[_0xeffa('0x9d')](_0xeffa('0x9e'),_0x51f585);var _0x540418={'method':_0xeffa('0x9f'),'uri':_0xeffa('0xa0')+_0x2b3bc2['tenantId']+_0xeffa('0xa1'),'form':{'client_id':_0x2b3bc2[_0xeffa('0x9a')],'resource':_0x51f585,'username':_0x2b3bc2[_0xeffa('0xa2')],'password':_0x2b3bc2['password'],'grant_type':_0xeffa('0xa3'),'client_secret':_0x2b3bc2[_0xeffa('0x9b')]},'json':!![]};return rp(_0x540418);}})[_0xeffa('0x2c')](function(_0x62cde){_0x59dfd=_0x62cde['access_token'];var _0x55508e={'method':_0xeffa('0xa4'),'uri':encodeURI(_0x53234a+_0xeffa('0xa5')+_0xaee7c2+'\x27'),'headers':{'Authorization':_0xeffa('0xa6')+_0x59dfd,'If-None-Match':null,'OData-Version':_0xeffa('0xa7')},'json':!![]};return rp(_0x55508e);})['then'](function(_0x3b7c34){var _0x31eebd=_0x3b7c34[_0xeffa('0xa8')][0x0];var _0x1ba008=_0x31eebd[_0xeffa('0xa9')];var _0x330bbe={'method':_0xeffa('0xa4'),'uri':_0x53234a+'EntityDefinitions('+_0x1ba008+_0xeffa('0xaa'),'headers':{'Authorization':_0xeffa('0xa6')+_0x59dfd,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x330bbe);})[_0xeffa('0x2c')](function(_0x38698a){_0x96b6df=_0x38698a;_0x5ce4da=_0x96b6df['Attributes'];_0x5ce4da=_['remove'](_0x5ce4da,function(_0x55e210){return!_0x4fbbce[_0xeffa('0xab')](_0x55e210[_0xeffa('0xac')]);});var _0x576c74=[];var _0x18370e=[];_0x5ce4da[_0xeffa('0xad')](function(_0x398aa6){if(_0x398aa6[_0xeffa('0xae')]){var _0x4c3221=_0x398aa6[_0xeffa('0xae')][_0xeffa('0xaf')](_0x398aa6[_0xeffa('0xae')][_0xeffa('0xb0')]('.')+0x1);if(_0x4c3221===_0xeffa('0xb1')){_0x576c74[_0xeffa('0xb2')](getSelectList(_0x53234a,_0xd7c4ed,_0x18370e,_0x96b6df[_0xeffa('0xa9')],_0x398aa6['MetadataId'],_0x59dfd));}}});return Promise[_0xeffa('0xb3')](_0x576c74);})[_0xeffa('0x2c')](function(_0x1eb31e){_0x41a2ae=_0x1eb31e[0x0];var _0x35b2b3=[];var _0x53ad26=[];_0x5ce4da['forEach'](function(_0x47e4b2){if(!_[_0xeffa('0xb4')](_0x47e4b2[_0xeffa('0xae')])){var _0x3aff28=_0x47e4b2[_0xeffa('0xae')][_0xeffa('0xaf')](_0x47e4b2[_0xeffa('0xae')]['lastIndexOf']('.')+0x1);if(_0x3aff28===_0xeffa('0xb5')){_0x35b2b3['push'](getBooleanList(_0x53234a,_0xd7c4ed,_0x53ad26,_0x96b6df[_0xeffa('0xa9')],_0x47e4b2[_0xeffa('0xa9')],_0x59dfd));}}});return Promise[_0xeffa('0xb3')](_0x35b2b3);})[_0xeffa('0x2c')](function(_0xb47138){_0x57e8bb=_0xb47138[0x0];var _0x5446b0=[];var _0x2e9216=[];_0x5ce4da[_0xeffa('0xad')](function(_0x4c6a49){if(_0x4c6a49['@odata.type']){var _0x1cf3e8=_0x4c6a49[_0xeffa('0xae')][_0xeffa('0xaf')](_0x4c6a49[_0xeffa('0xae')]['lastIndexOf']('.')+0x1);if(_0x1cf3e8===_0xeffa('0xb6')||_0x1cf3e8===_0xeffa('0xb7')||_0x1cf3e8==='BigIntAttributeMetadata'||_0x1cf3e8===_0xeffa('0xb8')||_0x1cf3e8==='MemoAttributeMetadata'||_0x1cf3e8===_0xeffa('0xb9')||_0x1cf3e8===_0xeffa('0xba')||_0x1cf3e8===_0xeffa('0xbb')||_0x1cf3e8==='StateAttributeMetadata'||_0x1cf3e8==='DecimalAttributeMetadata'){_0x5446b0[_0xeffa('0xb2')](getInputList(_0x53234a,_0xd7c4ed,_0x1cf3e8,_0x2e9216,_0x96b6df[_0xeffa('0xa9')],_0x4c6a49[_0xeffa('0xa9')],_0x59dfd));}}});return Promise[_0xeffa('0xb3')](_0x5446b0);})[_0xeffa('0x2c')](function(_0x1e07cf){_0x194f8b=_0x1e07cf[0x0];var _0x440d32=_0x41a2ae[_0xeffa('0x98')](_0x57e8bb)[_0xeffa('0x98')](_0x194f8b);var _0x49f7f7={'count':_0x440d32[_0xeffa('0x3c')],'rows':_0x440d32};return _0x49f7f7;})['then'](respondWithResult(_0x5f516a,null))['catch'](function(_0x246722){var _0x50fce1=_0x265fd6['query'][_0xeffa('0x15')]?0x1f4:_0x246722[_0xeffa('0xbc')]||0x1f4;logger['error'](_0x246722[_0xeffa('0x2d')]);delete _0x246722[_0xeffa('0x2e')];if(_0x50fce1===0x191){_0x50fce1=0x190;}_0x5f516a[_0xeffa('0x22')](_0x50fce1)[_0xeffa('0x2f')](_0x265fd6[_0xeffa('0x39')]['test']?{'message':'Wrong\x20credentials','statusCode':_0x246722[_0xeffa('0xbc')]}:_0x246722);});};function getSelectList(_0x22d62a,_0x261fe9,_0x467fdc,_0x4f411d,_0xebb149,_0x164a5a){var _0x5c6e5a={'method':_0xeffa('0xa4'),'uri':_0x22d62a+_0xeffa('0xbd')+_0x4f411d+_0xeffa('0xbe')+_0xebb149+_0xeffa('0xbf')+_0xeffa('0xc0'),'headers':{'Authorization':'Bearer\x20'+_0x164a5a,'If-None-Match':null,'OData-Version':_0xeffa('0xa7')},'json':!![]};return rp(_0x5c6e5a)[_0xeffa('0x2c')](function(_0x1b57fd){var _0x1526c0=[];var _0x27235f=_0x1b57fd[_0xeffa('0xc1')][_0xeffa('0xc2')];_0x27235f[_0xeffa('0xad')](function(_0x218635){_0x1526c0['push']({'name':_0x218635[_0xeffa('0xc3')][_0xeffa('0xc4')][_0xeffa('0xc3')],'value':String(_0x218635[_0xeffa('0xc5')])});});var _0x1d0071={'id':_0x261fe9+'_'+_0x1b57fd[_0xeffa('0xac')],'name':_0x1b57fd[_0xeffa('0xc6')][_0xeffa('0xc4')][_0xeffa('0xc3')],'custom':![],'options':_0x1526c0};_0x467fdc[_0xeffa('0xb2')](_0x1d0071);return _0x467fdc;});}function getBooleanList(_0x30503c,_0x3c89c1,_0xeac781,_0x2b266e,_0x1e9f0c,_0x80d2d5){var _0x18da49={'method':_0xeffa('0xa4'),'uri':_0x30503c+'EntityDefinitions('+_0x2b266e+_0xeffa('0xbe')+_0x1e9f0c+_0xeffa('0xc7'),'headers':{'Authorization':'Bearer\x20'+_0x80d2d5,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x18da49)['then'](function(_0x57dfb1){var _0x44ca5a=[];_0x44ca5a[_0xeffa('0xb2')]({'name':_0x57dfb1[_0xeffa('0xc1')][_0xeffa('0xc8')][_0xeffa('0xc3')]['UserLocalizedLabel']['Label'],'value':_0xeffa('0xc9')},{'name':_0x57dfb1['OptionSet']['FalseOption'][_0xeffa('0xc3')]['UserLocalizedLabel'][_0xeffa('0xc3')],'value':'false'});var _0x3b4a11={'id':_0x3c89c1+'_'+_0x57dfb1['LogicalName'],'name':_0x57dfb1['DisplayName'][_0xeffa('0xc4')][_0xeffa('0xc3')],'custom':![],'options':_0x44ca5a};_0xeac781[_0xeffa('0xb2')](_0x3b4a11);return _0xeac781;});}function getInputList(_0x5ba23b,_0x245e63,_0x547b31,_0x2f0cf8,_0x5ed994,_0x90a26,_0x53503c){var _0x4262c5={'method':_0xeffa('0xa4'),'uri':_0x5ba23b+_0xeffa('0xbd')+_0x5ed994+')/Attributes('+_0x90a26+')/Microsoft.Dynamics.CRM.'+_0x547b31+_0xeffa('0xca'),'headers':{'Authorization':'Bearer\x20'+_0x53503c,'If-None-Match':null,'OData-Version':'4.0'},'json':!![]};return rp(_0x4262c5)[_0xeffa('0x2c')](function(_0x421e59){var _0x539583={'id':_0x245e63+'_'+_0x421e59[_0xeffa('0xac')],'name':_0x421e59[_0xeffa('0xc6')][_0xeffa('0xc4')]?_0x421e59[_0xeffa('0xc6')]['UserLocalizedLabel'][_0xeffa('0xc3')]:_0x421e59[_0xeffa('0xac')],'custom':![],'options':[]};_0x2f0cf8[_0xeffa('0xb2')](_0x539583);return _0x2f0cf8;});}