ba40799374389fc26ff4cea1d7b08d5125dc340b
[motion-next.git] / server / api / intZohoAccount / intZohoAccount.model.js
1 const a347_0x3b5d=['info','error','zone','code','substring','clientSecret','https://accounts.zoho.com.cn','refresh_token','refreshToken','host','slice','application/x-www-form-urlencoded','https://accounts.zoho.com.au','/oauth/v2/token','catch','format','../../config/logger','clientId','https://accounts.zoho.com','ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d','define','exports','parse','authorization_code','then','inspect','https://accounts.zoho.in','util','name','./intZohoAccount.attributes','ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d','ZohoAccount','serverUrl','https://accounts.zoho.eu','changed'];(function(_0xbcee1a,_0x3b5d15){const _0x4db11f=function(_0x2e2f79){while(--_0x2e2f79){_0xbcee1a['push'](_0xbcee1a['shift']());}};_0x4db11f(++_0x3b5d15);}(a347_0x3b5d,0x1a0));const a347_0x4db1=function(_0xbcee1a,_0x3b5d15){_0xbcee1a=_0xbcee1a-0x0;let _0x4db11f=a347_0x3b5d[_0xbcee1a];return _0x4db11f;};const _0x4b3281=a347_0x4db1;'use strict';const util=require(_0x4b3281('0x1f')),logger=require(_0x4b3281('0x14'))('api'),rp=require('request-promise-native'),attributes=require(_0x4b3281('0x21'));module[_0x4b3281('0x19')]=function(_0x2e2f79){const _0x582775=_0x4b3281,_0x5c6080=_0x2e2f79[_0x582775('0x18')](_0x582775('0x0'),attributes,{'tableName':'int_zoho_accounts','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x4a0652){const _0x4f4f24=_0x582775;if(_0x4a0652[_0x4f4f24('0x3')](_0x4f4f24('0x6'))||_0x4a0652['changed'](_0x4f4f24('0x1'))||_0x4a0652[_0x4f4f24('0x3')](_0x4f4f24('0x15'))||_0x4a0652[_0x4f4f24('0x3')]('clientSecret')||_0x4a0652[_0x4f4f24('0x3')]('code')||_0x4a0652['changed'](_0x4f4f24('0xd'))){let _0x3a6dbc,_0x21e652;_0x3a6dbc=_0x4a0652[_0x4f4f24('0x1')];const _0x3ba340=_0x3a6dbc[_0x4f4f24('0xe')](-0x1);(_0x3ba340==='/'||_0x3ba340==='\x5c'||_0x3ba340===':')&&(_0x3a6dbc=_0x3a6dbc[_0x4f4f24('0x8')](0x0,_0x3a6dbc['lastIndexOf'](_0x3ba340)));switch(_0x4a0652[_0x4f4f24('0x6')]){case'US':_0x21e652=_0x4f4f24('0x16');break;case'AU':_0x21e652=_0x4f4f24('0x10');break;case'IN':_0x21e652='https://accounts.zoho.in';break;case'CN':_0x21e652=_0x4f4f24('0xa');break;default:_0x21e652=_0x4f4f24('0x2');break;}const _0x4f924d={'method':'POST','uri':_0x21e652+'/oauth/v2/token','form':{'grant_type':_0x4f4f24('0x1b'),'client_id':_0x4a0652[_0x4f4f24('0x15')],'client_secret':_0x4a0652[_0x4f4f24('0x9')],'redirect_uri':_0x4a0652[_0x4f4f24('0x1')],'code':_0x4a0652[_0x4f4f24('0x7')]},'headers':{'Content-Type':'application/x-www-form-urlencoded'}};let _0x5222d1=null;return rp(_0x4f924d)['then'](function(_0x11b389){const _0x57c185=_0x4f4f24;return _0x5222d1=JSON[_0x57c185('0x1a')](_0x11b389),_0x5222d1[_0x57c185('0xb')]?(_0x4a0652[_0x57c185('0xc')]=_0x5222d1['refresh_token'],logger[_0x57c185('0x4')](util[_0x57c185('0x13')](_0x57c185('0x17'),_0x4a0652[_0x57c185('0x20')],_0x4a0652['id']))):logger['error'](util[_0x57c185('0x13')](_0x57c185('0x22'),_0x4a0652['name'],_0x4a0652['id']),util['inspect'](_0x5222d1,{'showHidden':![],'depth':null})),null;})[_0x4f4f24('0x12')](function(_0x1307bb){const _0x12c854=_0x4f4f24;return logger[_0x12c854('0x5')](util[_0x12c854('0x13')]('ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d',_0x4a0652['name'],_0x4a0652['id']),util[_0x12c854('0x1d')](_0x5222d1,{'showHidden':![],'depth':null})),_0x1307bb;});}else return null;},'beforeUpdate':function(_0x20adc5){const _0xd7c84e=_0x582775;if(_0x20adc5[_0xd7c84e('0x3')](_0xd7c84e('0x6'))||_0x20adc5['changed'](_0xd7c84e('0x1'))||_0x20adc5['changed'](_0xd7c84e('0x15'))||_0x20adc5[_0xd7c84e('0x3')](_0xd7c84e('0x9'))||_0x20adc5[_0xd7c84e('0x3')](_0xd7c84e('0x7'))||_0x20adc5[_0xd7c84e('0x3')](_0xd7c84e('0xd'))){let _0x2245e3,_0x17d718;_0x2245e3=_0x20adc5['serverUrl'];const _0x28103b=_0x2245e3[_0xd7c84e('0xe')](-0x1);(_0x28103b==='/'||_0x28103b==='\x5c'||_0x28103b===':')&&(_0x2245e3=_0x2245e3['substring'](0x0,_0x2245e3['lastIndexOf'](_0x28103b)));switch(_0x20adc5[_0xd7c84e('0x6')]){case'US':_0x17d718=_0xd7c84e('0x16');break;case'AU':_0x17d718=_0xd7c84e('0x10');break;case'IN':_0x17d718=_0xd7c84e('0x1e');break;case'CN':_0x17d718=_0xd7c84e('0xa');break;default:_0x17d718=_0xd7c84e('0x2');break;}const _0x4bf09={'method':'POST','uri':_0x17d718+_0xd7c84e('0x11'),'form':{'grant_type':'authorization_code','client_id':_0x20adc5[_0xd7c84e('0x15')],'client_secret':_0x20adc5[_0xd7c84e('0x9')],'redirect_uri':_0x20adc5[_0xd7c84e('0x1')],'code':_0x20adc5[_0xd7c84e('0x7')]},'headers':{'Content-Type':_0xd7c84e('0xf')}};let _0x22d551=null;return rp(_0x4bf09)[_0xd7c84e('0x1c')](function(_0x1839d1){const _0x4306a9=_0xd7c84e;return _0x22d551=JSON[_0x4306a9('0x1a')](_0x1839d1),_0x22d551[_0x4306a9('0xb')]?(_0x20adc5[_0x4306a9('0xc')]=_0x22d551[_0x4306a9('0xb')],logger['info'](util['format']('ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d',_0x20adc5[_0x4306a9('0x20')],_0x20adc5['id']))):logger[_0x4306a9('0x5')](util[_0x4306a9('0x13')](_0x4306a9('0x22'),_0x20adc5[_0x4306a9('0x20')],_0x20adc5['id']),util['inspect'](_0x22d551,{'showHidden':![],'depth':null})),null;})[_0xd7c84e('0x12')](function(_0x429cdf){const _0x553c66=_0xd7c84e;return logger['error'](util[_0x553c66('0x13')](_0x553c66('0x22'),_0x20adc5['name'],_0x20adc5['id']),util[_0x553c66('0x1d')](_0x22d551,{'showHidden':![],'depth':null})),_0x429cdf;});}else return null;}}});return _0x5c6080;};