Built motion from commit 52c8a02d.|2.6.29
[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 _0x4c10=['cmContact','inspect','insert','into','cm_hopper','fromQuery','ContactId','createdAt','select','field','NOW()','scheduledAt','toString','updatedAt','from','cm_contacts','where','deletedAt\x20IS\x20NULL','ListId\x20=\x20?','phone\x20IS\x20NOT\x20NULL','phone\x20NOT\x20IN\x20(?)','\x20=\x20?','str','calleridnum','cm_hopper_final','cm_hopper_black','id\x20IN\x20?','VoiceQueue','findAll','outbound','dialCheckDuplicateType','CmList','Lists','always','query','VoiceQueueId','catch','sequelize','all','BlackLists','Campaign','CampaignId','get','cmContact,\x20%s,\x20%s','generalCheckHopper','Error\x20processing\x20rows\x20block:','finally','emit','contact:csv_','resume','resolve','exit','SIGINT','info','CSV\x20import\x20process\x20stopped!','createReadStream','parse','CSV\x20parsed\x20correctly!','CSV\x20parse\x20error','Error\x20executing\x20contact\x20csv\x20import:','util','lodash','squel','papaparse','ioredis','../../../config/environment','redis','../../../api/cmContact/cmContact.socket','register','argv','null','undefined','zipObject','split','Missing\x20ListId\x20parameter!','Missing\x20socket_timestamp\x20parameter!','index','test','isNil','error','errors','length','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','email\x20format\x20is\x20not\x20valid!','ListId','CompanyId','duplicate','Duplicate\x20Contact','CmContact','keys','then','push','Error\x20while\x20creating\x20contact:\x20','stringify'];(function(_0x42cae2,_0x284ef8){var _0x5f256f=function(_0x41abc8){while(--_0x41abc8){_0x42cae2['push'](_0x42cae2['shift']());}};_0x5f256f(++_0x284ef8);}(_0x4c10,0x17a));var _0x04c1=function(_0x5cdf51,_0x2ce86c){_0x5cdf51=_0x5cdf51-0x0;var _0x470a5f=_0x4c10[_0x5cdf51];return _0x470a5f;};'use strict';var BPromise=require('bluebird');var util=require(_0x04c1('0x0'));var _=require(_0x04c1('0x1'));var fs=require('fs');var squel=require(_0x04c1('0x2'));var Papa=require(_0x04c1('0x3'));var Redis=require(_0x04c1('0x4'));var db=require('../../../mysqldb')['db'];var config=require(_0x04c1('0x5'));var logger=require('../../../config/logger')('api');config['redis']=_['defaults'](config[_0x04c1('0x6')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x04c1('0x6')]));require(_0x04c1('0x7'))[_0x04c1('0x8')](socket);try{if(!process[_0x04c1('0x9')][0x2]||process[_0x04c1('0x9')][0x2]==='undefined'||process[_0x04c1('0x9')][0x2]===_0x04c1('0xa')){throw new Error('Missing\x20filepath\x20parameter!');}var FILEPATH=process[_0x04c1('0x9')][0x2];if(!process[_0x04c1('0x9')][0x3]||process['argv'][0x3]==='undefined'||process[_0x04c1('0x9')][0x3]===_0x04c1('0xa')||!process['argv'][0x4]||process[_0x04c1('0x9')][0x4]===_0x04c1('0xb')||process['argv'][0x4]===_0x04c1('0xa')){throw new Error('Missing\x20binding\x20parameters!');}var FIELDS=_[_0x04c1('0xc')](process[_0x04c1('0x9')][0x3]['split'](','),process[_0x04c1('0x9')][0x4][_0x04c1('0xd')](','));if(!process['argv'][0x5]||process[_0x04c1('0x9')][0x5]==='undefined'||process['argv'][0x5]===_0x04c1('0xa')){throw new Error(_0x04c1('0xe'));}var LISTID=process['argv'][0x5];var COMPANYID=process[_0x04c1('0x9')][0x6]&&process[_0x04c1('0x9')][0x6]!==_0x04c1('0xb')&&process[_0x04c1('0x9')][0x6]!==_0x04c1('0xa')?process['argv'][0x6]:null;var DUPLICATES=process[_0x04c1('0x9')][0x7]&&process[_0x04c1('0x9')][0x7]!=='undefined'&&process[_0x04c1('0x9')][0x7]!==_0x04c1('0xa')?process[_0x04c1('0x9')][0x7]:null;if(!process[_0x04c1('0x9')][0x8]||process[_0x04c1('0x9')][0x8]===_0x04c1('0xb')||process[_0x04c1('0x9')][0x8]==='null'){throw new Error(_0x04c1('0xf'));}var SOCKET_TIMESTAMP=process[_0x04c1('0x9')][0x8];}catch(_0x52a1d1){logger['error'](_0x52a1d1);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(_0x555b09,_0xaf0b28,_0x3e5397,_0x590d51){var _0x4086f1={'message':_0xaf0b28};_0x4086f1[_0x555b09]=!![];if(_0x3e5397){_0x4086f1['contact']=_0x3e5397;}if(_0x590d51){_0x4086f1[_0x04c1('0x10')]=_0x590d51;}return _0x4086f1;}function isEmail(_0x202098){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))*$/[_0x04c1('0x11')](_0x202098);}function checkRow(_0x1eacde,_0x32d5b5,_0x8b4608){return new BPromise(function(_0x4b2ca8,_0x25dfea){if(_[_0x04c1('0x12')](_0x1eacde)){return _0x25dfea(handleCheckRowError(_0x04c1('0x13'),'The\x20row\x20is\x20empty\x20or\x20the\x20number\x20of\x20parameters\x20does\x20not\x20match\x20the\x20columns!',null,_0x8b4608));}if(_0x1eacde[_0x04c1('0x14')]&&_0x1eacde[_0x04c1('0x14')][_0x04c1('0x15')]){var _0x3c2438=_['map'](_0x1eacde[_0x04c1('0x14')],_0x04c1('0x16'))[_0x04c1('0x17')](';');return _0x25dfea(handleCheckRowError(_0x04c1('0x13'),_0x3c2438,null,_0x8b4608));}var _0x2dcd4e={};for(var _0x4aa63a in FIELDS){if(FIELDS[_0x04c1('0x18')](_0x4aa63a)&&FIELDS[_0x4aa63a]){_0x2dcd4e[_0x4aa63a]=_0x1eacde[_0x04c1('0x19')][0x0][FIELDS[_0x4aa63a]]||_0x1eacde[_0x04c1('0x19')][0x0]['\ufeff'+FIELDS[_0x4aa63a]];}}if(!_0x2dcd4e[_0x04c1('0x1a')]){return _0x25dfea(handleCheckRowError(_0x04c1('0x13'),_0x04c1('0x1b'),null,_0x8b4608));}if(!_0x2dcd4e[_0x04c1('0x1c')]){return _0x25dfea(handleCheckRowError(_0x04c1('0x13'),_0x04c1('0x1d'),null,_0x8b4608));}if(_0x2dcd4e['birthDate']){var _0x53f3fd=moment(_0x2dcd4e[_0x04c1('0x1e')],_0x04c1('0x1f'));if(!_0x53f3fd[_0x04c1('0x20')]()){return _0x25dfea(handleCheckRowError(_0x04c1('0x13'),_0x04c1('0x21'),null,_0x8b4608));}}if(_0x2dcd4e['email']){if(!isEmail(_0x2dcd4e[_0x04c1('0x22')])){return _0x25dfea(handleCheckRowError(_0x04c1('0x13'),_0x04c1('0x23'),null,_0x8b4608));}}_0x2dcd4e[_0x04c1('0x24')]=LISTID;_0x2dcd4e[_0x04c1('0x25')]=COMPANYID||undefined;if(DUPLICATES&&DUPLICATES[_0x04c1('0x15')]&&_0x32d5b5){var _0x46f533={};for(var _0x1bb538=0x0,_0x27c9bd=DUPLICATES[_0x04c1('0x15')];_0x1bb538<_0x27c9bd;_0x1bb538+=0x1){_0x46f533[DUPLICATES[_0x1bb538]]=_0x2dcd4e[DUPLICATES[_0x1bb538]];}var _0xf85aef=_['find'](_0x32d5b5,_0x46f533);if(_0xf85aef){return _0x25dfea(handleCheckRowError(_0x04c1('0x26'),_0x04c1('0x27'),_0xf85aef,_0x8b4608));}}return db[_0x04c1('0x28')]['create'](_0x2dcd4e,{'raw':!![],'hooks':![],'fields':_[_0x04c1('0x29')](_0x2dcd4e)})[_0x04c1('0x2a')](function(_0x135972){if(DUPLICATES&&DUPLICATES['length']&&_0x32d5b5){_0x32d5b5[_0x04c1('0x2b')](_['pick'](_0x2dcd4e,DUPLICATES));}hopperContacts+=(hopperContacts?',':'')+_0x135972['id'];return _0x4b2ca8();})['catch'](function(_0x43f003){return _0x25dfea(handleCheckRowError('error',_0x04c1('0x2c')+(_0x43f003[_0x04c1('0x16')]||JSON[_0x04c1('0x2d')](_0x43f003)),null,_0x8b4608));});});}function checkHopper(){function _0x2c77f1(){return function(_0x48bc21){logger[_0x04c1('0x13')](_0x04c1('0x2e'),'checkHopper',util[_0x04c1('0x2f')](_0x48bc21,{'showHidden':![],'depth':null}));};}var _0xa5da11=function(_0xea7235,_0x57087d){var _0x1e865a=squel[_0x04c1('0x30')]()[_0x04c1('0x31')](_0x04c1('0x32'))[_0x04c1('0x33')]([_0x04c1('0x1c'),'scheduledAt',_0x04c1('0x34'),_0x04c1('0x24'),_0x57087d,_0x04c1('0x35'),'updatedAt'],squel[_0x04c1('0x36')]()[_0x04c1('0x37')]('phone','phone')[_0x04c1('0x37')](_0x04c1('0x38'),_0x04c1('0x39'))[_0x04c1('0x37')]('id',_0x04c1('0x34'))[_0x04c1('0x37')](LISTID['toString'](),_0x04c1('0x24'))[_0x04c1('0x37')](_0xea7235['id'][_0x04c1('0x3a')](),_0x57087d)[_0x04c1('0x37')](_0x04c1('0x38'),'createdAt')[_0x04c1('0x37')](_0x04c1('0x38'),_0x04c1('0x3b'))[_0x04c1('0x3c')](_0x04c1('0x3d'))[_0x04c1('0x3e')](_0x04c1('0x3f'))[_0x04c1('0x3e')](_0x04c1('0x40'),LISTID['toString']())['where'](_0x04c1('0x41'))[_0x04c1('0x3e')](_0x04c1('0x42'),squel[_0x04c1('0x36')]()[_0x04c1('0x37')](_0x04c1('0x1c'))[_0x04c1('0x3c')](_0x04c1('0x32'))[_0x04c1('0x3e')](_0x57087d+_0x04c1('0x43'),_0xea7235['id']['toString']())))[_0x04c1('0x3a')]();return _0x1e865a;};var _0x43b4eb=function(_0x5959b8,_0x4d260e){var _0x176997=squel[_0x04c1('0x30')]()['into'](_0x04c1('0x32'))[_0x04c1('0x33')]([_0x04c1('0x1c'),'scheduledAt',_0x04c1('0x34'),_0x04c1('0x24'),_0x4d260e,_0x04c1('0x35'),_0x04c1('0x3b')],squel[_0x04c1('0x36')]()[_0x04c1('0x37')]('phone','phone')[_0x04c1('0x37')](_0x04c1('0x38'),_0x04c1('0x39'))['field']('id','ContactId')['field'](LISTID[_0x04c1('0x3a')](),'ListId')[_0x04c1('0x37')](_0x5959b8['id']['toString'](),_0x4d260e)[_0x04c1('0x37')](_0x04c1('0x38'),_0x04c1('0x35'))[_0x04c1('0x37')](_0x04c1('0x38'),_0x04c1('0x3b'))[_0x04c1('0x3c')]('cm_contacts')[_0x04c1('0x3e')](_0x04c1('0x3f'))['where'](_0x04c1('0x40'),LISTID[_0x04c1('0x3a')]())['where']('id\x20IN\x20?',squel[_0x04c1('0x44')](hopperContacts))[_0x04c1('0x3e')](_0x04c1('0x41'))[_0x04c1('0x3e')](_0x04c1('0x42'),squel[_0x04c1('0x36')]()[_0x04c1('0x37')](_0x04c1('0x45'))[_0x04c1('0x3c')](_0x04c1('0x46'))[_0x04c1('0x3e')](_0x4d260e+_0x04c1('0x43'),_0x5959b8['id'][_0x04c1('0x3a')]()))['where'](_0x04c1('0x42'),squel[_0x04c1('0x36')]()['field']('phone')[_0x04c1('0x3c')](_0x04c1('0x32'))['where'](_0x4d260e+_0x04c1('0x43'),_0x5959b8['id']['toString']())))[_0x04c1('0x3a')]();return _0x176997;};function _0x5e7f7e(_0x44c6dd,_0xafa4d6){var _0x4931b3=squel['insert']()['into'](_0x04c1('0x32'))[_0x04c1('0x33')]([_0x04c1('0x1c'),'scheduledAt',_0x04c1('0x34'),_0x04c1('0x24'),_0xafa4d6,_0x04c1('0x35'),_0x04c1('0x3b')],squel[_0x04c1('0x36')]()[_0x04c1('0x37')](_0x04c1('0x1c'),'phone')[_0x04c1('0x37')](_0x04c1('0x38'),_0x04c1('0x39'))[_0x04c1('0x37')]('id',_0x04c1('0x34'))[_0x04c1('0x37')](LISTID[_0x04c1('0x3a')](),_0x04c1('0x24'))['field'](_0x44c6dd['id']['toString'](),_0xafa4d6)['field'](_0x04c1('0x38'),'createdAt')[_0x04c1('0x37')](_0x04c1('0x38'),_0x04c1('0x3b'))[_0x04c1('0x3c')](_0x04c1('0x3d'))[_0x04c1('0x3e')]('deletedAt\x20IS\x20NULL')['where'](_0x04c1('0x40'),LISTID[_0x04c1('0x3a')]())[_0x04c1('0x3e')]('id\x20IN\x20?',squel['str'](hopperContacts))[_0x04c1('0x3e')](_0x04c1('0x41')))['toString']();return _0x4931b3;}function _0x319c7d(_0x1c2f25,_0x4d5dbb){var _0x47ee59=squel[_0x04c1('0x30')]()['into'](_0x04c1('0x47'))[_0x04c1('0x33')]([_0x04c1('0x1c'),_0x04c1('0x34'),'ListId',_0x4d5dbb,'createdAt','updatedAt'],squel[_0x04c1('0x36')]()[_0x04c1('0x37')](_0x04c1('0x1c'),_0x04c1('0x1c'))[_0x04c1('0x37')]('id',_0x04c1('0x34'))[_0x04c1('0x37')](LISTID['toString'](),_0x04c1('0x24'))[_0x04c1('0x37')](_0x1c2f25['id'][_0x04c1('0x3a')](),_0x4d5dbb)[_0x04c1('0x37')]('NOW()',_0x04c1('0x35'))[_0x04c1('0x37')]('NOW()','updatedAt')[_0x04c1('0x3c')]('cm_contacts')[_0x04c1('0x3e')](_0x04c1('0x3f'))[_0x04c1('0x3e')](_0x04c1('0x40'),LISTID[_0x04c1('0x3a')]())[_0x04c1('0x3e')](_0x04c1('0x48'),squel[_0x04c1('0x44')](hopperContacts))['where']('phone\x20IS\x20NOT\x20NULL'))[_0x04c1('0x3a')]();return _0x47ee59;}return db[_0x04c1('0x49')][_0x04c1('0x4a')]({'where':{'type':_0x04c1('0x4b')},'attributes':['id',_0x04c1('0x4c')],'include':[{'model':db[_0x04c1('0x4d')],'as':_0x04c1('0x4e'),'where':{'id':LISTID}}]})[_0x04c1('0x2a')](function(_0x2ea14e){var _0xf1dcf6=[];if(_0x2ea14e){var _0x19d7a2;for(var _0x3775d6=0x0,_0x4b90cf;_0x3775d6<_0x2ea14e[_0x04c1('0x15')];_0x3775d6+=0x1){_0x4b90cf=_0x2ea14e[_0x3775d6]['get']({'plain':!![]});switch(_0x4b90cf[_0x04c1('0x4c')]){case _0x04c1('0x4f'):_0xf1dcf6[_0x04c1('0x2b')](db['sequelize'][_0x04c1('0x50')](_0x43b4eb(_0x4b90cf,_0x04c1('0x51')))[_0x04c1('0x2a')](function(){})[_0x04c1('0x52')](_0x2c77f1()));break;case'onlyIfOpen':_0xf1dcf6[_0x04c1('0x2b')](db['sequelize'][_0x04c1('0x50')](_0xa5da11(_0x4b90cf,_0x04c1('0x51')))['then'](function(){})[_0x04c1('0x52')](_0x2c77f1()));break;default:_0xf1dcf6[_0x04c1('0x2b')](db[_0x04c1('0x53')][_0x04c1('0x50')](_0x5e7f7e(_0x4b90cf,_0x04c1('0x51')))[_0x04c1('0x2a')](function(){})[_0x04c1('0x52')](_0x2c77f1()));}}}return _0xf1dcf6;})[_0x04c1('0x54')]()['then'](function(){return db[_0x04c1('0x49')][_0x04c1('0x4a')]({'where':{'type':'outbound'},'attributes':['id'],'include':[{'model':db[_0x04c1('0x4d')],'as':_0x04c1('0x55'),'where':{'id':LISTID}}]})[_0x04c1('0x2a')](function(_0x3327b4){var _0x19114e=[];if(_0x3327b4){var _0x1d0a40;for(var _0x2ee06f=0x0,_0x11082a;_0x2ee06f<_0x3327b4[_0x04c1('0x15')];_0x2ee06f+=0x1){_0x11082a=_0x3327b4[_0x2ee06f]['get']({'plain':!![]});_0x19114e[_0x04c1('0x2b')](db[_0x04c1('0x53')][_0x04c1('0x50')](_0x319c7d(_0x11082a,_0x04c1('0x51')))[_0x04c1('0x2a')](function(){})[_0x04c1('0x52')](_0x2c77f1()));}}return _0x19114e;})[_0x04c1('0x54')]();})[_0x04c1('0x2a')](function(){return db[_0x04c1('0x56')][_0x04c1('0x4a')]({'attributes':['id',_0x04c1('0x4c')],'include':[{'model':db['CmList'],'as':_0x04c1('0x4e'),'where':{'id':LISTID}}]})[_0x04c1('0x2a')](function(_0x1bf816){var _0x4184ad=[];if(_0x1bf816){for(var _0x5c1c28=0x0,_0x3fb641;_0x5c1c28<_0x1bf816['length'];_0x5c1c28+=0x1){_0x3fb641=_0x1bf816[_0x5c1c28]['get']({'plain':!![]});switch(_0x3fb641[_0x04c1('0x4c')]){case _0x04c1('0x4f'):_0x4184ad['push'](db[_0x04c1('0x53')]['query'](_0x43b4eb(_0x3fb641,'CampaignId'))['then'](function(){})[_0x04c1('0x52')](_0x2c77f1()));break;case'onlyIfOpen':_0x4184ad[_0x04c1('0x2b')](db[_0x04c1('0x53')][_0x04c1('0x50')](_0xa5da11(_0x3fb641,_0x04c1('0x57')))['then'](function(){})['catch'](_0x2c77f1()));break;default:_0x4184ad[_0x04c1('0x2b')](db['sequelize'][_0x04c1('0x50')](_0x5e7f7e(_0x3fb641,_0x04c1('0x57')))[_0x04c1('0x2a')](function(){})[_0x04c1('0x52')](_0x2c77f1()));}}}return _0x4184ad;})[_0x04c1('0x54')]();})['then'](function(){return db[_0x04c1('0x56')][_0x04c1('0x4a')]({'attributes':['id'],'include':[{'model':db[_0x04c1('0x4d')],'as':_0x04c1('0x55'),'where':{'id':LISTID}}]})[_0x04c1('0x2a')](function(_0x3614d5){var _0x58793e=[];if(_0x3614d5){for(var _0x8bcead=0x0,_0x3f906f;_0x8bcead<_0x3614d5['length'];_0x8bcead+=0x1){_0x3f906f=_0x3614d5[_0x8bcead][_0x04c1('0x58')]({'plain':!![]});_0x58793e[_0x04c1('0x2b')](db[_0x04c1('0x53')][_0x04c1('0x50')](_0x319c7d(_0x3f906f,'CampaignId'))[_0x04c1('0x2a')](function(){})[_0x04c1('0x52')](_0x2c77f1()));}}return _0x58793e;})[_0x04c1('0x54')]();})[_0x04c1('0x52')](function(_0x3cb7e5){logger[_0x04c1('0x13')](_0x04c1('0x59'),_0x04c1('0x5a'),_0x3cb7e5['message']);});}var processPromises=function(_0x3f78df){return BPromise[_0x04c1('0x54')](promises)[_0x04c1('0x2a')](function(_0x55bdf0){})[_0x04c1('0x52')](function(_0x695afa){logger['error'](_0x04c1('0x5b'),JSON[_0x04c1('0x2d')](_0x695afa));})[_0x04c1('0x5c')](function(){socket[_0x04c1('0x5d')](_0x04c1('0x5e')+SOCKET_TIMESTAMP,{'success':success,'errors':errors,'duplicates':duplicates,'rows':rows});promises=[];success=0x0;errors=0x0;duplicates=0x0;rows=[];if(_0x3f78df){return _0x3f78df[_0x04c1('0x5f')]();}});};var endCsv=function(){return BPromise[_0x04c1('0x60')]()['then'](function(){if(hopperContacts){return checkHopper();}})[_0x04c1('0x2a')](function(){socket[_0x04c1('0x5d')](_0x04c1('0x5e')+SOCKET_TIMESTAMP,{'finished':!![],'success':success,'errors':errors,'duplicates':duplicates,'rows':rows});try{fs['unlinkSync'](FILEPATH);}catch(_0xb9ac36){logger[_0x04c1('0x13')]('Unable\x20to\x20delete\x20temp\x20file:',JSON[_0x04c1('0x2d')](_0xb9ac36));}finally{process[_0x04c1('0x61')](0x0);}});};process['on'](_0x04c1('0x62'),function(){logger[_0x04c1('0x63')](_0x04c1('0x64'));endCsv();});function main(){return BPromise[_0x04c1('0x60')]()[_0x04c1('0x2a')](function(){if(DUPLICATES){DUPLICATES=DUPLICATES[_0x04c1('0xd')](',');return db['CmContact']['findAll']({'where':{'ListId':LISTID},'attributes':DUPLICATES,'raw':!![]});}})[_0x04c1('0x2a')](function(_0x5e207d){var _0x46d9ab=fs[_0x04c1('0x65')](FILEPATH,{'highWaterMark':0xf*0x400*0x400});Papa[_0x04c1('0x66')](_0x46d9ab,{'header':!![],'skipEmptyLines':!![],'step':function(_0x24d850,_0x1892e7){total+=0x1;var _0x2e559f=total;promises['push'](checkRow(_0x24d850,_0x5e207d,_0x2e559f)[_0x04c1('0x2a')](function(){success+=0x1;})[_0x04c1('0x52')](function(_0xe9006){if(_0xe9006[_0x04c1('0x13')]){errors+=0x1;delete _0xe9006[_0x04c1('0x13')];}else if(_0xe9006[_0x04c1('0x26')]){duplicates+=0x1;delete _0xe9006[_0x04c1('0x26')];}rows[_0x04c1('0x2b')](_0xe9006);}));if(total%0xc8===0x0){_0x1892e7['pause']();return processPromises(_0x1892e7);}},'complete':function(){return processPromises()[_0x04c1('0x2a')](function(){logger[_0x04c1('0x63')](_0x04c1('0x67'));endCsv();});},'error':function(_0x4b2d66,_0x1e9661){logger[_0x04c1('0x63')](_0x04c1('0x68'),JSON[_0x04c1('0x2d')](_0x4b2d66));endCsv();}});})[_0x04c1('0x52')](function(_0x14760b){logger[_0x04c1('0x13')](_0x04c1('0x69'),JSON[_0x04c1('0x2d')](_0x14760b));});}main();