Built motion from commit f861bcb808219e66da88ba48b61bddb35224a65e. Version 3.0.0...
[motion-next.git] / server / components / import / cm / csv / csv-parser.js
index 823d390..f93fa5a 100644 (file)
@@ -1 +1 @@
-const a992_0x1f62=['33LEjKAm','652993GYBrMW','moment','priority','validator','SystemRow','475562UOVEPu','25589yMYZQY','dateOfBirth','undefined','YYYY-MM-DD','partial-result','errors','number','emit','stats','resetStats','join','setCSVFilePath','UserId','rows','36021jOhqqZ','createReadStream','isArray','data','139rKVNQH','length','39MdejDc','keys','replace','firstName','string','1yBMowi','push','11YVSDjj','parseStep','2006dQnsgy','validateRow','425pAEjKT','250256BLlrAK','SystemError','includes','agents','Abort\x20parser','fs-extra','validateAndFormatValue','rowError','scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)','stopped','agent\x20does\x20not\x20exist','recallme','parsed-data','parse','emitLog','email\x20wrong\x20format','exports','binding','csvFilePath','phone','increaseRowCounter','@utils/console-logger','isValid','abort','importEventThreshold','papaparse'];const a992_0x4c3f=function(_0x277597,_0x468a6e){_0x277597=_0x277597-0x74;let _0x1f621d=a992_0x1f62[_0x277597];return _0x1f621d;};const a992_0x1ebd5c=a992_0x4c3f;(function(_0x50ba1a,_0x388564){const _0x1a7106=a992_0x4c3f;while(!![]){try{const _0x5c1ccc=parseInt(_0x1a7106(0x99))*-parseInt(_0x1a7106(0x7e))+-parseInt(_0x1a7106(0x78))+-parseInt(_0x1a7106(0x90))*parseInt(_0x1a7106(0x77))+-parseInt(_0x1a7106(0x7d))*parseInt(_0x1a7106(0x97))+parseInt(_0x1a7106(0x9d))*parseInt(_0x1a7106(0x9b))+-parseInt(_0x1a7106(0x9e))+parseInt(_0x1a7106(0x8c))*parseInt(_0x1a7106(0x92));if(_0x5c1ccc===_0x388564)break;else _0x50ba1a['push'](_0x50ba1a['shift']());}catch(_0x5dbbc7){_0x50ba1a['push'](_0x50ba1a['shift']());}}}(a992_0x1f62,0x90a6c));const fs=require(a992_0x1ebd5c(0xa3)),moment=require(a992_0x1ebd5c(0x79)),Papa=require(a992_0x1ebd5c(0x76)),{consoleLogger}=require(a992_0x1ebd5c(0xb3)),EventEmitter=require('events'),{isEmail}=require(a992_0x1ebd5c(0x7b)),INITIAL_STATS={'finish':![],'rows':0x0,'affectedRows':0x0,'errors':[]};class CSVParser extends EventEmitter{constructor(_0x1613de,_0x55430d,_0x4e6598,_0x2b6cc8,_0x15f1c,_0x15d7a9=0xc8){const _0x1de0e0=a992_0x1ebd5c;super(),this[_0x1de0e0(0xb0)]='',this[_0x1de0e0(0xaf)]=_0x55430d,this[_0x1de0e0(0xa9)]=_0x4e6598,this[_0x1de0e0(0xa1)]=_0x2b6cc8,this[_0x1de0e0(0xac)]=!_0x15f1c,this[_0x1de0e0(0x75)]=_0x15d7a9,this[_0x1de0e0(0x86)]=null,this['stopped']=![],this['setCSVFilePath'](_0x1613de);}[a992_0x1ebd5c(0x87)](){const _0x371dfd=a992_0x1ebd5c;this[_0x371dfd(0x86)]={...INITIAL_STATS};}[a992_0x1ebd5c(0x89)](_0xc0b6cb){const _0x4e17a6=a992_0x1ebd5c;this['resetStats'](),this[_0x4e17a6(0xb0)]=_0xc0b6cb;}['stop'](){this['stopped']=!![];}[a992_0x1ebd5c(0xa5)](_0x3fb081,{code:_0x489f70,message:_0x3abd1a}){const _0x4c2606=a992_0x1ebd5c,_0x3792de={'name':_0x489f70,'message':_0x3abd1a,'row':_0x3fb081};this[_0x4c2606(0x86)][_0x4c2606(0x83)]['push'](_0x3792de);}[a992_0x1ebd5c(0xb2)](){const _0x3a0ec6=a992_0x1ebd5c;this[_0x3a0ec6(0x86)]['rows']+=0x1;}[a992_0x1ebd5c(0xa4)](_0x10f9c4,_0x8359a5){const _0x470b3a=a992_0x1ebd5c;let _0x5dba8f=null,_0x32be04=null;switch(_0x8359a5){case'scheduledat':{const _0x38f6e9=moment(_0x10f9c4,'YYYY-MM-DD\x20HH:mm:ss',!![]);_0x38f6e9['isValid']()?_0x5dba8f='\x22'+_0x10f9c4+'\x22':_0x32be04=_0x470b3a(0xa6);}break;case _0x470b3a(0x7a):{const _0x36a486=parseInt(_0x10f9c4),_0x6dff42=isNaN(_0x36a486)||_0x36a486<0x0||_0x36a486>0x4?this[_0x470b3a(0xa9)]?0x3:0x2:_0x36a486;_0x5dba8f='\x22'+_0x6dff42+'\x22';}break;case _0x470b3a(0x8a):{const _0x26d113=parseInt(_0x10f9c4);typeof _0x26d113===_0x470b3a(0x84)&&this['agents'][_0x470b3a(0xa0)](_0x26d113)?_0x5dba8f='\x22'+_0x10f9c4+'\x22':_0x32be04=_0x470b3a(0xa8);}break;case'email':isEmail(_0x10f9c4)?_0x5dba8f='\x22'+_0x10f9c4+'\x22':_0x32be04=_0x470b3a(0xad);break;case _0x470b3a(0x7f):{const _0x3f8382=moment(_0x10f9c4,_0x470b3a(0x81),!![]);_0x3f8382[_0x470b3a(0xb4)]()?_0x5dba8f='\x22'+_0x10f9c4+'\x22':_0x32be04='dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)';}break;default:_0x5dba8f='\x22'+_0x10f9c4+'\x22';break;}return{'formattedValue':_0x5dba8f,'error':_0x32be04};}[a992_0x1ebd5c(0x9c)](_0x3d3ef8){const _0x4be1de=a992_0x1ebd5c,_0x23c1e2=[],_0x520490=[],_0x4e3541=Object[_0x4be1de(0x93)](this['binding']);for(const _0x286490 of _0x4e3541){const _0x29c98c=this['binding'][_0x286490],_0x54c653=typeof _0x29c98c!==_0x4be1de(0x80);if(_0x54c653){let _0x34b8b6=_0x3d3ef8[_0x29c98c];if(typeof _0x34b8b6===_0x4be1de(0x96)&&_0x34b8b6['length']>0x0){_0x34b8b6=_0x34b8b6['trim']()[_0x4be1de(0x94)](/"/g,'\x27');const {error:_0x4871d9,formattedValue:_0x35c182}=this['validateAndFormatValue'](_0x34b8b6,_0x286490);_0x4871d9?_0x520490[_0x4be1de(0x98)](_0x4871d9):_0x23c1e2[_0x4be1de(0x98)](_0x35c182);}else switch(_0x286490){case _0x4be1de(0x95):case _0x4be1de(0xb1):_0x520490[_0x4be1de(0x98)](_0x286490+'\x20not\x20specified');break;default:_0x23c1e2['push']('\x22\x22');}}}return{'parsedRows':_0x23c1e2,'validationErrors':_0x520490};}[a992_0x1ebd5c(0x9a)](_0x3bb032,_0x32b929){const _0x114ba1=a992_0x1ebd5c;for(let _0x83280e=0x0;_0x83280e<_0x3bb032[_0x114ba1(0x91)];_0x83280e++){this['increaseRowCounter']();const _0x5aad06=_0x3bb032[_0x83280e],_0x57cbef=_0x32b929[_0x83280e];try{if(_0x57cbef)this[_0x114ba1(0xa5)](_0x5aad06,_0x57cbef);else{const {parsedRows:_0x45cec5,validationErrors:_0x2c1b27}=this[_0x114ba1(0x9c)](_0x5aad06);_0x2c1b27[_0x114ba1(0x91)]>0x0?this[_0x114ba1(0xa5)](_0x5aad06,{'code':_0x114ba1(0x7c),'message':_0x2c1b27[_0x114ba1(0x88)]()}):this[_0x114ba1(0x85)](_0x114ba1(0xaa),_0x45cec5[_0x114ba1(0x88)]()+'\x0a');}}catch(_0x2469fd){this[_0x114ba1(0xa5)](_0x5aad06,{'code':_0x114ba1(0x9f),'message':_0x2469fd['message']}),this['emitLog']&&consoleLogger['error']('step\x20error',_0x2469fd['message']);}this[_0x114ba1(0x86)][_0x114ba1(0x8b)]%this['importEventThreshold']===0x0&&this[_0x114ba1(0x85)](_0x114ba1(0x82),this[_0x114ba1(0x86)]);}}[a992_0x1ebd5c(0xab)](){const _0x6af86=a992_0x1ebd5c;return this[_0x6af86(0xa7)]=![],new Promise((_0x115efc,_0x32eafe)=>{const _0x47dc89=_0x6af86,_0x59be14=fs[_0x47dc89(0x8d)](this[_0x47dc89(0xb0)]);Papa[_0x47dc89(0xab)](_0x59be14,{'header':!![],'skipEmptyLines':!![],'step':(_0x40c35c,_0x380e98)=>{const _0x54d033=_0x47dc89;this[_0x54d033(0xa7)]===!![]&&(this[_0x54d033(0xac)]&&consoleLogger['debug'](_0x54d033(0xa2)),_0x380e98[_0x54d033(0x74)]());const _0x100c68=Array[_0x54d033(0x8e)](_0x40c35c[_0x54d033(0x8f)])?_0x40c35c[_0x54d033(0x8f)]:[_0x40c35c[_0x54d033(0x8f)]];this[_0x54d033(0x9a)](_0x100c68,_0x40c35c[_0x54d033(0x83)]);},'complete':_0x1f118e=>{const _0x49aaf2=_0x47dc89;this[_0x49aaf2(0xac)]&&consoleLogger['info']('CSV\x20Parsing\x20complete'),_0x115efc({'results':_0x1f118e,'stats':this[_0x49aaf2(0x86)]});},'error':(_0x233a55,_0x43c24c,_0x41314f,_0x2f2649)=>{_0x32eafe(_0x2f2649);}});});}}module[a992_0x1ebd5c(0xae)]=CSVParser;
\ No newline at end of file
+const a999_0x7144=['stopped','phone','data','YYYY-MM-DD','recallme','setCSVFilePath','parseStep','validateRow','2804zeLdPr','importEventThreshold','agents','dateOfBirth\x20wrong\x20format\x20(YYYY-MM-DD)','replace','23rieICy','info','rowError','trim','4133558FLmoov','fs-extra','emit','664569mIafGw','514tvntyZ','papaparse','exports','binding','Abort\x20parser','stats','agent\x20does\x20not\x20exist','scheduledat','message','isValid','increaseRowCounter','@utils/console-logger','UserId','step\x20error','1365368WDALvm','resetStats','join','rows','\x20not\x20specified','SystemRow','4139yDaWSz','YYYY-MM-DD\x20HH:mm:ss','csvFilePath','stop','validateAndFormatValue','firstName','length','error','isArray','CSV\x20Parsing\x20complete','parsed-data','353JzIwin','string','includes','emitLog','undefined','760972BdWnqY','partial-result','push','17933TZeMuR','parse','SystemError','validator'];const a999_0x5504=function(_0x2296be,_0xefe010){_0x2296be=_0x2296be-0x67;let _0x71446b=a999_0x7144[_0x2296be];return _0x71446b;};const a999_0x419cfa=a999_0x5504;(function(_0x1d03ba,_0x549f69){const _0x523962=a999_0x5504;while(!![]){try{const _0x63e04=-parseInt(_0x523962(0x83))+parseInt(_0x523962(0x94))*-parseInt(_0x523962(0x89))+-parseInt(_0x523962(0x9c))*parseInt(_0x523962(0x6d))+-parseInt(_0x523962(0x99))+parseInt(_0x523962(0x68))*parseInt(_0x523962(0x75))+-parseInt(_0x523962(0x74))+parseInt(_0x523962(0x71));if(_0x63e04===_0x549f69)break;else _0x1d03ba['push'](_0x1d03ba['shift']());}catch(_0x3a33a7){_0x1d03ba['push'](_0x1d03ba['shift']());}}}(a999_0x7144,0xde42b));const fs=require(a999_0x419cfa(0x72)),moment=require('moment'),Papa=require(a999_0x419cfa(0x76)),{consoleLogger}=require(a999_0x419cfa(0x80)),EventEmitter=require('events'),{isEmail}=require(a999_0x419cfa(0x9f)),INITIAL_STATS={'finish':![],'rows':0x0,'affectedRows':0x0,'errors':[]};class CSVParser extends EventEmitter{constructor(_0x444567,_0x30e264,_0x4da0f2,_0x220b20,_0x48c790,_0x214473=0xc8){const _0x12182c=a999_0x419cfa;super(),this[_0x12182c(0x8b)]='',this[_0x12182c(0x78)]=_0x30e264,this['recallme']=_0x4da0f2,this[_0x12182c(0x6a)]=_0x220b20,this[_0x12182c(0x97)]=!_0x48c790,this[_0x12182c(0x69)]=_0x214473,this[_0x12182c(0x7a)]=null,this['stopped']=![],this[_0x12182c(0xa5)](_0x444567);}[a999_0x419cfa(0x84)](){const _0x13a871=a999_0x419cfa;this[_0x13a871(0x7a)]={...INITIAL_STATS};}[a999_0x419cfa(0xa5)](_0x203d96){const _0x5c32bf=a999_0x419cfa;this[_0x5c32bf(0x84)](),this[_0x5c32bf(0x8b)]=_0x203d96;}[a999_0x419cfa(0x8c)](){this['stopped']=!![];}[a999_0x419cfa(0x6f)](_0x334d7d,{code:_0x4b4e0a,message:_0x241686}){const _0x2c01e6={'name':_0x4b4e0a,'message':_0x241686,'row':_0x334d7d};this['stats']['errors']['push'](_0x2c01e6);}[a999_0x419cfa(0x7f)](){const _0x41a040=a999_0x419cfa;this[_0x41a040(0x7a)]['rows']+=0x1;}[a999_0x419cfa(0x8d)](_0x314631,_0x2116bf){const _0x2901a0=a999_0x419cfa;let _0x514da2=null,_0x2227c6=null;switch(_0x2116bf){case _0x2901a0(0x7c):{const _0x2ea31f=moment(_0x314631,_0x2901a0(0x8a),!![]);_0x2ea31f[_0x2901a0(0x7e)]()?_0x514da2='\x22'+_0x314631+'\x22':_0x2227c6='scheduledat\x20wrong\x20format\x20(YYYY-MM-DD\x20HH:mm:ss)';}break;case'priority':{const _0x276f09=parseInt(_0x314631),_0x54e442=isNaN(_0x276f09)||_0x276f09<0x0||_0x276f09>0x4?this[_0x2901a0(0xa4)]?0x3:0x2:_0x276f09;_0x514da2='\x22'+_0x54e442+'\x22';}break;case _0x2901a0(0x81):{const _0x477575=parseInt(_0x314631);typeof _0x477575==='number'&&this[_0x2901a0(0x6a)][_0x2901a0(0x96)](_0x477575)?_0x514da2='\x22'+_0x314631+'\x22':_0x2227c6=_0x2901a0(0x7b);}break;case'email':isEmail(_0x314631)?_0x514da2='\x22'+_0x314631+'\x22':_0x2227c6='email\x20wrong\x20format';break;case'dateOfBirth':{const _0xe68dd1=moment(_0x314631,_0x2901a0(0xa3),!![]);_0xe68dd1[_0x2901a0(0x7e)]()?_0x514da2='\x22'+_0x314631+'\x22':_0x2227c6=_0x2901a0(0x6b);}break;default:_0x514da2='\x22'+_0x314631+'\x22';break;}return{'formattedValue':_0x514da2,'error':_0x2227c6};}['validateRow'](_0x1bd87e){const _0x4e65bd=a999_0x419cfa,_0x326dae=[],_0x158a11=[],_0x11b48f=Object['keys'](this[_0x4e65bd(0x78)]);for(const _0x1d5c4a of _0x11b48f){const _0x10a910=this['binding'][_0x1d5c4a],_0x23feed=typeof _0x10a910!==_0x4e65bd(0x98);if(_0x23feed){let _0x389843=_0x1bd87e[_0x10a910];if(typeof _0x389843===_0x4e65bd(0x95)&&_0x389843[_0x4e65bd(0x8f)]>0x0){_0x389843=_0x389843[_0x4e65bd(0x70)]()[_0x4e65bd(0x6c)](/"/g,'\x27');const {error:_0x10025b,formattedValue:_0x47c388}=this[_0x4e65bd(0x8d)](_0x389843,_0x1d5c4a);_0x10025b?_0x158a11[_0x4e65bd(0x9b)](_0x10025b):_0x326dae[_0x4e65bd(0x9b)](_0x47c388);}else switch(_0x1d5c4a){case _0x4e65bd(0x8e):case _0x4e65bd(0xa1):_0x158a11[_0x4e65bd(0x9b)](_0x1d5c4a+_0x4e65bd(0x87));break;default:_0x326dae[_0x4e65bd(0x9b)]('\x22\x22');}}}return{'parsedRows':_0x326dae,'validationErrors':_0x158a11};}[a999_0x419cfa(0xa6)](_0x5d6b8b,_0x294a82){const _0x20c567=a999_0x419cfa;for(let _0x5b335=0x0;_0x5b335<_0x5d6b8b[_0x20c567(0x8f)];_0x5b335++){this[_0x20c567(0x7f)]();const _0x3b1bc0=_0x5d6b8b[_0x5b335],_0x4f6519=_0x294a82[_0x5b335];try{if(_0x4f6519)this[_0x20c567(0x6f)](_0x3b1bc0,_0x4f6519);else{const {parsedRows:_0x585f31,validationErrors:_0x3bc353}=this[_0x20c567(0x67)](_0x3b1bc0);_0x3bc353[_0x20c567(0x8f)]>0x0?this[_0x20c567(0x6f)](_0x3b1bc0,{'code':_0x20c567(0x88),'message':_0x3bc353['join']()}):this[_0x20c567(0x73)](_0x20c567(0x93),_0x585f31[_0x20c567(0x85)]()+'\x0a');}}catch(_0x28c0c8){this[_0x20c567(0x6f)](_0x3b1bc0,{'code':_0x20c567(0x9e),'message':_0x28c0c8[_0x20c567(0x7d)]}),this[_0x20c567(0x97)]&&consoleLogger[_0x20c567(0x90)](_0x20c567(0x82),_0x28c0c8[_0x20c567(0x7d)]);}this[_0x20c567(0x7a)][_0x20c567(0x86)]%this[_0x20c567(0x69)]===0x0&&this[_0x20c567(0x73)](_0x20c567(0x9a),this['stats']);}}[a999_0x419cfa(0x9d)](){const _0x12eef1=a999_0x419cfa;return this[_0x12eef1(0xa0)]=![],new Promise((_0x5cf5fc,_0x37cd8e)=>{const _0x1eed05=_0x12eef1,_0xce88f2=fs['createReadStream'](this['csvFilePath']);Papa[_0x1eed05(0x9d)](_0xce88f2,{'header':!![],'skipEmptyLines':!![],'step':(_0x4b5f26,_0x5ae879)=>{const _0x19222f=_0x1eed05;this['stopped']===!![]&&(this[_0x19222f(0x97)]&&consoleLogger['debug'](_0x19222f(0x79)),_0x5ae879['abort']());const _0x579d95=Array[_0x19222f(0x91)](_0x4b5f26[_0x19222f(0xa2)])?_0x4b5f26[_0x19222f(0xa2)]:[_0x4b5f26[_0x19222f(0xa2)]];this[_0x19222f(0xa6)](_0x579d95,_0x4b5f26['errors']);},'complete':_0x36e55c=>{const _0x438fa2=_0x1eed05;this['emitLog']&&consoleLogger[_0x438fa2(0x6e)](_0x438fa2(0x92)),_0x5cf5fc({'results':_0x36e55c,'stats':this['stats']});},'error':(_0x446bb7,_0x26d9eb,_0x49e4d7,_0x5d3108)=>{_0x37cd8e(_0x5d3108);}});});}}module[a999_0x419cfa(0x77)]=CSVParser;
\ No newline at end of file