Built motion from commit ce9a7520.|2.5.39
[motion2.git] / server / components / import / cm / csv.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 _0xc39f=['catch','Error\x20while\x20creating\x20contact:\x20','stringify','cmContact','checkHopper','insert','scheduledAt','createdAt','updatedAt','select','field','NOW()','ContactId','toString','from','cm_contacts','deletedAt\x20IS\x20NULL','where','ListId\x20=\x20?','phone\x20IS\x20NOT\x20NULL','phone\x20NOT\x20IN\x20(?)','cm_hopper','\x20=\x20?','fromQuery','id\x20IN\x20?','str','calleridnum','cm_hopper_final','into','cm_hopper_black','CmList','Lists','get','dialCheckDuplicateType','always','query','VoiceQueueId','onlyIfOpen','sequelize','all','VoiceQueue','findAll','outbound','Campaign','CampaignId','BlackLists','generalCheckHopper','Error\x20processing\x20rows\x20block:','finally','contact:csv_','resume','resolve','emit','exit','SIGINT','info','CSV\x20import\x20process\x20stopped!','createReadStream','parse','duplicate','CSV\x20parsed\x20correctly!','CSV\x20parse\x20error','Error\x20executing\x20contact\x20csv\x20import:','bluebird','util','squel','papaparse','ioredis','../../../mysqldb','../../../config/environment','../../../config/logger','redis','localhost','../../../api/cmContact/cmContact.socket','register','argv','undefined','Missing\x20filepath\x20parameter!','null','Missing\x20binding\x20parameters!','zipObject','split','Missing\x20socket_timestamp\x20parameter!','error','contact','index','test','isNil','The\x20row\x20is\x20empty\x20or\x20the\x20number\x20of\x20parameters\x20does\x20not\x20match\x20the\x20columns!','errors','length','map','message','join','hasOwnProperty','data','firstName','firstName\x20not\x20specified!','phone','phone\x20not\x20specified!','birthDate','YYYY-MM-DD','isValid','birthDate\x20format\x20is\x20invalid,\x20YYYY-MM-DD\x20format\x20is\x20supported!','email','ListId','CompanyId','find','Duplicate\x20Contact','CmContact','keys','then','push','pick'];(function(_0x40c2ed,_0x4d6195){var _0x1e7636=function(_0x3d0157){while(--_0x3d0157){_0x40c2ed['push'](_0x40c2ed['shift']());}};_0x1e7636(++_0x4d6195);}(_0xc39f,0xb1));var _0xfc39=function(_0x543b5e,_0x1a3848){_0x543b5e=_0x543b5e-0x0;var _0x2ca5a3=_0xc39f[_0x543b5e];return _0x2ca5a3;};'use strict';var BPromise=require(_0xfc39('0x0'));var util=require(_0xfc39('0x1'));var _=require('lodash');var fs=require('fs');var squel=require(_0xfc39('0x2'));var Papa=require(_0xfc39('0x3'));var Redis=require(_0xfc39('0x4'));var db=require(_0xfc39('0x5'))['db'];var config=require(_0xfc39('0x6'));var logger=require(_0xfc39('0x7'))('api');config['redis']=_['defaults'](config[_0xfc39('0x8')],{'host':_0xfc39('0x9'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xfc39('0x8')]));require(_0xfc39('0xa'))[_0xfc39('0xb')](socket);try{if(!process[_0xfc39('0xc')][0x2]||process[_0xfc39('0xc')][0x2]===_0xfc39('0xd')||process[_0xfc39('0xc')][0x2]==='null'){throw new Error(_0xfc39('0xe'));}var FILEPATH=process[_0xfc39('0xc')][0x2];if(!process[_0xfc39('0xc')][0x3]||process[_0xfc39('0xc')][0x3]===_0xfc39('0xd')||process['argv'][0x3]===_0xfc39('0xf')||!process['argv'][0x4]||process[_0xfc39('0xc')][0x4]==='undefined'||process[_0xfc39('0xc')][0x4]===_0xfc39('0xf')){throw new Error(_0xfc39('0x10'));}var FIELDS=_[_0xfc39('0x11')](process['argv'][0x3]['split'](','),process[_0xfc39('0xc')][0x4][_0xfc39('0x12')](','));if(!process[_0xfc39('0xc')][0x5]||process[_0xfc39('0xc')][0x5]===_0xfc39('0xd')||process[_0xfc39('0xc')][0x5]===_0xfc39('0xf')){throw new Error('Missing\x20ListId\x20parameter!');}var LISTID=process[_0xfc39('0xc')][0x5];var COMPANYID=process[_0xfc39('0xc')][0x6]&&process[_0xfc39('0xc')][0x6]!==_0xfc39('0xd')&&process['argv'][0x6]!==_0xfc39('0xf')?process['argv'][0x6]:null;var DUPLICATES=process[_0xfc39('0xc')][0x7]&&process['argv'][0x7]!=='undefined'&&process['argv'][0x7]!=='null'?process[_0xfc39('0xc')][0x7]:null;if(!process[_0xfc39('0xc')][0x8]||process[_0xfc39('0xc')][0x8]===_0xfc39('0xd')||process[_0xfc39('0xc')][0x8]==='null'){throw new Error(_0xfc39('0x13'));}var SOCKET_TIMESTAMP=process[_0xfc39('0xc')][0x8];}catch(_0x13a213){logger[_0xfc39('0x14')](_0x13a213);endCsv();}var total=0x0;var pTotal=0x0;var success=0x0;var errors=0x0;var duplicates=0x0;var rows=[];var hopperContacts='';var promises=[];var index=0x0;var alreadyInvalid=![];function handleCheckRowError(_0x3bfd98,_0x1667b5,_0x27d47e,_0x57f171){var _0x222299={'message':_0x1667b5};_0x222299[_0x3bfd98]=!![];if(_0x27d47e){_0x222299[_0xfc39('0x15')]=_0x27d47e;}if(_0x57f171){_0x222299[_0xfc39('0x16')]=_0x57f171;}return _0x222299;}function isEmail(_0x6b9ede){return/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/[_0xfc39('0x17')](_0x6b9ede);}function checkRow(_0x5811bb,_0x5da90f,_0x5b40e1){return new BPromise(function(_0x5a34e4,_0x5c160d){if(_[_0xfc39('0x18')](_0x5811bb)){return _0x5c160d(handleCheckRowError(_0xfc39('0x14'),_0xfc39('0x19'),null,_0x5b40e1));}if(_0x5811bb[_0xfc39('0x1a')]&&_0x5811bb[_0xfc39('0x1a')][_0xfc39('0x1b')]){var _0x3b463d=_[_0xfc39('0x1c')](_0x5811bb['errors'],_0xfc39('0x1d'))[_0xfc39('0x1e')](';');return _0x5c160d(handleCheckRowError(_0xfc39('0x14'),_0x3b463d,null,_0x5b40e1));}var _0x31750c={};for(var _0x44d89d in FIELDS){if(FIELDS[_0xfc39('0x1f')](_0x44d89d)&&FIELDS[_0x44d89d]){_0x31750c[_0x44d89d]=_0x5811bb[_0xfc39('0x20')][0x0][FIELDS[_0x44d89d]]||_0x5811bb['data'][0x0]['\ufeff'+FIELDS[_0x44d89d]];}}if(!_0x31750c[_0xfc39('0x21')]){return _0x5c160d(handleCheckRowError(_0xfc39('0x14'),_0xfc39('0x22'),null,_0x5b40e1));}if(!_0x31750c[_0xfc39('0x23')]){return _0x5c160d(handleCheckRowError(_0xfc39('0x14'),_0xfc39('0x24'),null,_0x5b40e1));}if(_0x31750c[_0xfc39('0x25')]){var _0x6d810d=moment(_0x31750c[_0xfc39('0x25')],_0xfc39('0x26'));if(!_0x6d810d[_0xfc39('0x27')]()){return _0x5c160d(handleCheckRowError(_0xfc39('0x14'),_0xfc39('0x28'),null,_0x5b40e1));}}if(_0x31750c['email']){if(!isEmail(_0x31750c[_0xfc39('0x29')])){return _0x5c160d(handleCheckRowError('error','email\x20format\x20is\x20not\x20valid!',null,_0x5b40e1));}}_0x31750c[_0xfc39('0x2a')]=LISTID;_0x31750c[_0xfc39('0x2b')]=COMPANYID||undefined;if(DUPLICATES&&DUPLICATES[_0xfc39('0x1b')]&&_0x5da90f){var _0x30735c={};for(var _0x32010a=0x0,_0x125a2c=DUPLICATES['length'];_0x32010a<_0x125a2c;_0x32010a+=0x1){_0x30735c[DUPLICATES[_0x32010a]]=_0x31750c[DUPLICATES[_0x32010a]];}var _0x3cf24a=_[_0xfc39('0x2c')](_0x5da90f,_0x30735c);if(_0x3cf24a){return _0x5c160d(handleCheckRowError('duplicate',_0xfc39('0x2d'),_0x3cf24a,_0x5b40e1));}}return db[_0xfc39('0x2e')]['create'](_0x31750c,{'raw':!![],'hooks':![],'fields':_[_0xfc39('0x2f')](_0x31750c)})[_0xfc39('0x30')](function(_0x3ed21d){if(DUPLICATES&&DUPLICATES[_0xfc39('0x1b')]&&_0x5da90f){_0x5da90f[_0xfc39('0x31')](_[_0xfc39('0x32')](_0x31750c,DUPLICATES));}hopperContacts+=(hopperContacts?',':'')+_0x3ed21d['id'];return _0x5a34e4();})[_0xfc39('0x33')](function(_0x551c5c){return _0x5c160d(handleCheckRowError(_0xfc39('0x14'),_0xfc39('0x34')+(_0x551c5c['message']||JSON[_0xfc39('0x35')](_0x551c5c)),null,_0x5b40e1));});});}function checkHopper(){function _0x4719e2(){return function(_0x277ec9){logger[_0xfc39('0x14')](_0xfc39('0x36'),_0xfc39('0x37'),util['inspect'](_0x277ec9,{'showHidden':![],'depth':null}));};}var _0x196805=function(_0x376eb7,_0x3b26ef){var _0x1c583f=squel[_0xfc39('0x38')]()['into']('cm_hopper')['fromQuery'](['phone',_0xfc39('0x39'),'ContactId',_0xfc39('0x2a'),_0x3b26ef,_0xfc39('0x3a'),_0xfc39('0x3b')],squel[_0xfc39('0x3c')]()[_0xfc39('0x3d')](_0xfc39('0x23'),_0xfc39('0x23'))[_0xfc39('0x3d')](_0xfc39('0x3e'),'scheduledAt')[_0xfc39('0x3d')]('id',_0xfc39('0x3f'))['field'](LISTID[_0xfc39('0x40')](),_0xfc39('0x2a'))[_0xfc39('0x3d')](_0x376eb7['id'][_0xfc39('0x40')](),_0x3b26ef)[_0xfc39('0x3d')](_0xfc39('0x3e'),'createdAt')[_0xfc39('0x3d')](_0xfc39('0x3e'),_0xfc39('0x3b'))[_0xfc39('0x41')](_0xfc39('0x42'))['where'](_0xfc39('0x43'))[_0xfc39('0x44')](_0xfc39('0x45'),LISTID[_0xfc39('0x40')]())[_0xfc39('0x44')](_0xfc39('0x46'))['where'](_0xfc39('0x47'),squel['select']()[_0xfc39('0x3d')](_0xfc39('0x23'))[_0xfc39('0x41')](_0xfc39('0x48'))[_0xfc39('0x44')](_0x3b26ef+_0xfc39('0x49'),_0x376eb7['id'][_0xfc39('0x40')]())))[_0xfc39('0x40')]();return _0x1c583f;};var _0xe5fd24=function(_0x58487b,_0x21249e){var _0x18ef98=squel[_0xfc39('0x38')]()['into'](_0xfc39('0x48'))[_0xfc39('0x4a')]([_0xfc39('0x23'),'scheduledAt',_0xfc39('0x3f'),_0xfc39('0x2a'),_0x21249e,_0xfc39('0x3a'),_0xfc39('0x3b')],squel[_0xfc39('0x3c')]()[_0xfc39('0x3d')](_0xfc39('0x23'),_0xfc39('0x23'))['field'](_0xfc39('0x3e'),_0xfc39('0x39'))[_0xfc39('0x3d')]('id','ContactId')[_0xfc39('0x3d')](LISTID[_0xfc39('0x40')](),_0xfc39('0x2a'))['field'](_0x58487b['id'][_0xfc39('0x40')](),_0x21249e)[_0xfc39('0x3d')](_0xfc39('0x3e'),_0xfc39('0x3a'))[_0xfc39('0x3d')]('NOW()',_0xfc39('0x3b'))[_0xfc39('0x41')](_0xfc39('0x42'))['where'](_0xfc39('0x43'))[_0xfc39('0x44')]('ListId\x20=\x20?',LISTID['toString']())[_0xfc39('0x44')](_0xfc39('0x4b'),squel[_0xfc39('0x4c')](hopperContacts))[_0xfc39('0x44')](_0xfc39('0x46'))['where'](_0xfc39('0x47'),squel[_0xfc39('0x3c')]()['field'](_0xfc39('0x4d'))[_0xfc39('0x41')](_0xfc39('0x4e'))['where'](_0x21249e+'\x20=\x20?',_0x58487b['id'][_0xfc39('0x40')]()))[_0xfc39('0x44')](_0xfc39('0x47'),squel[_0xfc39('0x3c')]()[_0xfc39('0x3d')](_0xfc39('0x23'))['from'](_0xfc39('0x48'))[_0xfc39('0x44')](_0x21249e+_0xfc39('0x49'),_0x58487b['id']['toString']())))[_0xfc39('0x40')]();return _0x18ef98;};function _0x4604ac(_0x51ec4d,_0xe5c783){var _0x4791bf=squel['insert']()['into'](_0xfc39('0x48'))[_0xfc39('0x4a')]([_0xfc39('0x23'),_0xfc39('0x39'),_0xfc39('0x3f'),'ListId',_0xe5c783,_0xfc39('0x3a'),_0xfc39('0x3b')],squel[_0xfc39('0x3c')]()[_0xfc39('0x3d')]('phone','phone')[_0xfc39('0x3d')](_0xfc39('0x3e'),_0xfc39('0x39'))[_0xfc39('0x3d')]('id',_0xfc39('0x3f'))['field'](LISTID[_0xfc39('0x40')](),_0xfc39('0x2a'))['field'](_0x51ec4d['id'][_0xfc39('0x40')](),_0xe5c783)['field'](_0xfc39('0x3e'),_0xfc39('0x3a'))[_0xfc39('0x3d')](_0xfc39('0x3e'),_0xfc39('0x3b'))[_0xfc39('0x41')](_0xfc39('0x42'))[_0xfc39('0x44')]('deletedAt\x20IS\x20NULL')[_0xfc39('0x44')]('ListId\x20=\x20?',LISTID['toString']())[_0xfc39('0x44')](_0xfc39('0x4b'),squel[_0xfc39('0x4c')](hopperContacts))[_0xfc39('0x44')]('phone\x20IS\x20NOT\x20NULL'))['toString']();return _0x4791bf;}function _0x2cde33(_0x2f67bf,_0x2846b3){var _0xf49414=squel[_0xfc39('0x38')]()[_0xfc39('0x4f')](_0xfc39('0x50'))[_0xfc39('0x4a')]([_0xfc39('0x23'),_0xfc39('0x3f'),_0xfc39('0x2a'),_0x2846b3,'createdAt',_0xfc39('0x3b')],squel['select']()[_0xfc39('0x3d')](_0xfc39('0x23'),_0xfc39('0x23'))[_0xfc39('0x3d')]('id',_0xfc39('0x3f'))['field'](LISTID[_0xfc39('0x40')](),_0xfc39('0x2a'))[_0xfc39('0x3d')](_0x2f67bf['id'][_0xfc39('0x40')](),_0x2846b3)['field'](_0xfc39('0x3e'),_0xfc39('0x3a'))[_0xfc39('0x3d')](_0xfc39('0x3e'),_0xfc39('0x3b'))[_0xfc39('0x41')](_0xfc39('0x42'))[_0xfc39('0x44')]('deletedAt\x20IS\x20NULL')[_0xfc39('0x44')](_0xfc39('0x45'),LISTID[_0xfc39('0x40')]())[_0xfc39('0x44')](_0xfc39('0x4b'),squel[_0xfc39('0x4c')](hopperContacts))[_0xfc39('0x44')](_0xfc39('0x46')))['toString']();return _0xf49414;}return db['VoiceQueue']['findAll']({'where':{'type':'outbound'},'attributes':['id','dialCheckDuplicateType'],'include':[{'model':db[_0xfc39('0x51')],'as':_0xfc39('0x52'),'where':{'id':LISTID}}]})[_0xfc39('0x30')](function(_0xd9dd6e){var _0xeed8ae=[];if(_0xd9dd6e){var _0x1ed168;for(var _0x54b4ed=0x0,_0x4c950e;_0x54b4ed<_0xd9dd6e[_0xfc39('0x1b')];_0x54b4ed+=0x1){_0x4c950e=_0xd9dd6e[_0x54b4ed][_0xfc39('0x53')]({'plain':!![]});switch(_0x4c950e[_0xfc39('0x54')]){case _0xfc39('0x55'):_0xeed8ae[_0xfc39('0x31')](db['sequelize'][_0xfc39('0x56')](_0xe5fd24(_0x4c950e,_0xfc39('0x57')))[_0xfc39('0x30')](function(){})['catch'](_0x4719e2()));break;case _0xfc39('0x58'):_0xeed8ae[_0xfc39('0x31')](db[_0xfc39('0x59')]['query'](_0x196805(_0x4c950e,_0xfc39('0x57')))[_0xfc39('0x30')](function(){})[_0xfc39('0x33')](_0x4719e2()));break;default:_0xeed8ae['push'](db[_0xfc39('0x59')][_0xfc39('0x56')](_0x4604ac(_0x4c950e,_0xfc39('0x57')))[_0xfc39('0x30')](function(){})[_0xfc39('0x33')](_0x4719e2()));}}}return _0xeed8ae;})[_0xfc39('0x5a')]()[_0xfc39('0x30')](function(){return db[_0xfc39('0x5b')][_0xfc39('0x5c')]({'where':{'type':_0xfc39('0x5d')},'attributes':['id'],'include':[{'model':db['CmList'],'as':'BlackLists','where':{'id':LISTID}}]})['then'](function(_0x20f5d2){var _0x1ec10c=[];if(_0x20f5d2){var _0x223832;for(var _0xe5ec2f=0x0,_0x2c17cc;_0xe5ec2f<_0x20f5d2[_0xfc39('0x1b')];_0xe5ec2f+=0x1){_0x2c17cc=_0x20f5d2[_0xe5ec2f][_0xfc39('0x53')]({'plain':!![]});_0x1ec10c[_0xfc39('0x31')](db[_0xfc39('0x59')][_0xfc39('0x56')](_0x2cde33(_0x2c17cc,_0xfc39('0x57')))[_0xfc39('0x30')](function(){})['catch'](_0x4719e2()));}}return _0x1ec10c;})[_0xfc39('0x5a')]();})['then'](function(){return db[_0xfc39('0x5e')]['findAll']({'attributes':['id','dialCheckDuplicateType'],'include':[{'model':db[_0xfc39('0x51')],'as':_0xfc39('0x52'),'where':{'id':LISTID}}]})[_0xfc39('0x30')](function(_0x2742b1){var _0x564d91=[];if(_0x2742b1){for(var _0x4c5fea=0x0,_0x30e026;_0x4c5fea<_0x2742b1['length'];_0x4c5fea+=0x1){_0x30e026=_0x2742b1[_0x4c5fea][_0xfc39('0x53')]({'plain':!![]});switch(_0x30e026['dialCheckDuplicateType']){case _0xfc39('0x55'):_0x564d91[_0xfc39('0x31')](db['sequelize']['query'](_0xe5fd24(_0x30e026,_0xfc39('0x5f')))[_0xfc39('0x30')](function(){})['catch'](_0x4719e2()));break;case _0xfc39('0x58'):_0x564d91[_0xfc39('0x31')](db['sequelize'][_0xfc39('0x56')](_0x196805(_0x30e026,'CampaignId'))[_0xfc39('0x30')](function(){})[_0xfc39('0x33')](_0x4719e2()));break;default:_0x564d91[_0xfc39('0x31')](db[_0xfc39('0x59')][_0xfc39('0x56')](_0x4604ac(_0x30e026,_0xfc39('0x5f')))[_0xfc39('0x30')](function(){})[_0xfc39('0x33')](_0x4719e2()));}}}return _0x564d91;})[_0xfc39('0x5a')]();})[_0xfc39('0x30')](function(){return db['Campaign'][_0xfc39('0x5c')]({'attributes':['id'],'include':[{'model':db[_0xfc39('0x51')],'as':_0xfc39('0x60'),'where':{'id':LISTID}}]})[_0xfc39('0x30')](function(_0x4d77ce){var _0x228250=[];if(_0x4d77ce){for(var _0x395ac6=0x0,_0x217b3c;_0x395ac6<_0x4d77ce[_0xfc39('0x1b')];_0x395ac6+=0x1){_0x217b3c=_0x4d77ce[_0x395ac6][_0xfc39('0x53')]({'plain':!![]});_0x228250['push'](db[_0xfc39('0x59')][_0xfc39('0x56')](_0x2cde33(_0x217b3c,_0xfc39('0x5f')))[_0xfc39('0x30')](function(){})['catch'](_0x4719e2()));}}return _0x228250;})[_0xfc39('0x5a')]();})[_0xfc39('0x33')](function(_0x56985f){logger[_0xfc39('0x14')]('cmContact,\x20%s,\x20%s',_0xfc39('0x61'),_0x56985f[_0xfc39('0x1d')]);});}var processPromises=function(_0x1830c1){return BPromise['all'](promises)['then'](function(_0x327fd6){})[_0xfc39('0x33')](function(_0x50346b){logger[_0xfc39('0x14')](_0xfc39('0x62'),JSON[_0xfc39('0x35')](_0x50346b));})[_0xfc39('0x63')](function(){socket['emit'](_0xfc39('0x64')+SOCKET_TIMESTAMP,{'success':success,'errors':errors,'duplicates':duplicates,'rows':rows});promises=[];success=0x0;errors=0x0;duplicates=0x0;rows=[];if(_0x1830c1){return _0x1830c1[_0xfc39('0x65')]();}});};var endCsv=function(){return BPromise[_0xfc39('0x66')]()['then'](function(){if(hopperContacts){return checkHopper();}})[_0xfc39('0x30')](function(){socket[_0xfc39('0x67')](_0xfc39('0x64')+SOCKET_TIMESTAMP,{'finished':!![],'success':success,'errors':errors,'duplicates':duplicates,'rows':rows});try{fs['unlinkSync'](FILEPATH);}catch(_0x4eb554){logger['error']('Unable\x20to\x20delete\x20temp\x20file:',JSON[_0xfc39('0x35')](_0x4eb554));}finally{process[_0xfc39('0x68')](0x0);}});};process['on'](_0xfc39('0x69'),function(){logger[_0xfc39('0x6a')](_0xfc39('0x6b'));endCsv();});function main(){return BPromise[_0xfc39('0x66')]()[_0xfc39('0x30')](function(){if(DUPLICATES){DUPLICATES=DUPLICATES[_0xfc39('0x12')](',');return db[_0xfc39('0x2e')][_0xfc39('0x5c')]({'where':{'ListId':LISTID},'attributes':DUPLICATES,'raw':!![]});}})[_0xfc39('0x30')](function(_0x47d72d){var _0x5679ce=fs[_0xfc39('0x6c')](FILEPATH,{'highWaterMark':0xf*0x400*0x400});Papa[_0xfc39('0x6d')](_0x5679ce,{'header':!![],'skipEmptyLines':!![],'step':function(_0x1984f7,_0x5ebfa3){total+=0x1;var _0x401bb0=total;promises['push'](checkRow(_0x1984f7,_0x47d72d,_0x401bb0)[_0xfc39('0x30')](function(){success+=0x1;})[_0xfc39('0x33')](function(_0x17bf9d){if(_0x17bf9d[_0xfc39('0x14')]){errors+=0x1;delete _0x17bf9d[_0xfc39('0x14')];}else if(_0x17bf9d[_0xfc39('0x6e')]){duplicates+=0x1;delete _0x17bf9d[_0xfc39('0x6e')];}rows[_0xfc39('0x31')](_0x17bf9d);}));if(total%0xc8===0x0){_0x5ebfa3['pause']();return processPromises(_0x5ebfa3);}},'complete':function(){return processPromises()[_0xfc39('0x30')](function(){logger['info'](_0xfc39('0x6f'));endCsv();});},'error':function(_0x126d48,_0xd8e396){logger[_0xfc39('0x6a')](_0xfc39('0x70'),JSON[_0xfc39('0x35')](_0x126d48));endCsv();}});})[_0xfc39('0x33')](function(_0x4aa1c3){logger[_0xfc39('0x14')](_0xfc39('0x71'),JSON[_0xfc39('0x35')](_0x4aa1c3));});}main();