Built motion from commit 449495f6.|2.6.27
[motion2.git] / server / api / intZohoAccount / intZohoAccount.model.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 _0xe3b7=['inspect','catch','ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d','host','https://accounts.zoho.com','https://accounts.zoho.com.au','lodash','util','../../config/logger','api','bluebird','request-promise','path','../../config/environment','../../components/integrations/configuration','exports','define','ZohoAccount','changed','zone','clientId','clientSecret','code','slice','lastIndexOf','https://accounts.zoho.in','https://accounts.zoho.com.cn','https://accounts.zoho.eu','POST','/oauth/v2/token','authorization_code','serverUrl','application/x-www-form-urlencoded','then','parse','refreshToken','refresh_token','info','format','ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d','name','error'];(function(_0x115683,_0x4a1c36){var _0x5715b0=function(_0x17a343){while(--_0x17a343){_0x115683['push'](_0x115683['shift']());}};_0x5715b0(++_0x4a1c36);}(_0xe3b7,0x12c));var _0x7e3b=function(_0x18cd5b,_0x10240b){_0x18cd5b=_0x18cd5b-0x0;var _0x5eaa52=_0xe3b7[_0x18cd5b];return _0x5eaa52;};'use strict';var _=require(_0x7e3b('0x0'));var util=require(_0x7e3b('0x1'));var logger=require(_0x7e3b('0x2'))(_0x7e3b('0x3'));var moment=require('moment');var BPromise=require(_0x7e3b('0x4'));var rp=require(_0x7e3b('0x5'));var fs=require('fs');var path=require(_0x7e3b('0x6'));var rimraf=require('rimraf');var config=require(_0x7e3b('0x7'));var attributes=require('./intZohoAccount.attributes');var integrations=require(_0x7e3b('0x8'));module[_0x7e3b('0x9')]=function(_0x4b7396,_0xfbede5){return _0x4b7396[_0x7e3b('0xa')](_0x7e3b('0xb'),attributes,{'tableName':'int_zoho_accounts','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x4eb0b3,_0x27790b,_0x3b94ba){if(_0x4eb0b3[_0x7e3b('0xc')](_0x7e3b('0xd'))||_0x4eb0b3[_0x7e3b('0xc')]('serverUrl')||_0x4eb0b3[_0x7e3b('0xc')](_0x7e3b('0xe'))||_0x4eb0b3[_0x7e3b('0xc')](_0x7e3b('0xf'))||_0x4eb0b3['changed'](_0x7e3b('0x10'))||_0x4eb0b3[_0x7e3b('0xc')]('host')){var _0x692c32,_0x4dfec6;_0x692c32=_0x4eb0b3['serverUrl'];var _0x4cb56f=_0x692c32[_0x7e3b('0x11')](-0x1);if(_0x4cb56f==='/'||_0x4cb56f==='\x5c'||_0x4cb56f===':'){_0x692c32=_0x692c32['substring'](0x0,_0x692c32[_0x7e3b('0x12')](_0x4cb56f));}switch(_0x4eb0b3[_0x7e3b('0xd')]){case'US':_0x4dfec6='https://accounts.zoho.com';break;case'AU':_0x4dfec6='https://accounts.zoho.com.au';break;case'IN':_0x4dfec6=_0x7e3b('0x13');break;case'CN':_0x4dfec6=_0x7e3b('0x14');break;default:_0x4dfec6=_0x7e3b('0x15');break;}var _0x1715d2={'method':_0x7e3b('0x16'),'uri':_0x4dfec6+_0x7e3b('0x17'),'form':{'grant_type':_0x7e3b('0x18'),'client_id':_0x4eb0b3['clientId'],'client_secret':_0x4eb0b3[_0x7e3b('0xf')],'redirect_uri':_0x4eb0b3[_0x7e3b('0x19')],'code':_0x4eb0b3[_0x7e3b('0x10')]},'headers':{'Content-Type':_0x7e3b('0x1a')}};return rp(_0x1715d2)[_0x7e3b('0x1b')](function(_0x425982){var _0x123550=JSON[_0x7e3b('0x1c')](_0x425982);if(_0x123550['refresh_token']){_0x4eb0b3[_0x7e3b('0x1d')]=_0x123550[_0x7e3b('0x1e')];logger[_0x7e3b('0x1f')](util[_0x7e3b('0x20')](_0x7e3b('0x21'),_0x4eb0b3[_0x7e3b('0x22')],_0x4eb0b3['id']));}else{logger[_0x7e3b('0x23')](util['format']('ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d',_0x4eb0b3[_0x7e3b('0x22')],_0x4eb0b3['id']),util[_0x7e3b('0x24')](_0x123550,{'showHidden':![],'depth':null}));}return _0x3b94ba(null,_0x27790b);})[_0x7e3b('0x25')](function(_0x5cc853){logger['error'](util[_0x7e3b('0x20')](_0x7e3b('0x26'),_0x4eb0b3['name'],_0x4eb0b3['id']),util[_0x7e3b('0x24')](parsedResult,{'showHidden':![],'depth':null}));return _0x3b94ba(_0x5cc853);});}else{return _0x3b94ba(null,_0x27790b);}},'beforeUpdate':function(_0x568e1d,_0x1d6db1,_0x107770){if(_0x568e1d[_0x7e3b('0xc')](_0x7e3b('0xd'))||_0x568e1d[_0x7e3b('0xc')](_0x7e3b('0x19'))||_0x568e1d[_0x7e3b('0xc')](_0x7e3b('0xe'))||_0x568e1d['changed'](_0x7e3b('0xf'))||_0x568e1d['changed']('code')||_0x568e1d[_0x7e3b('0xc')](_0x7e3b('0x27'))){var _0x309751,_0x519a40;_0x309751=_0x568e1d[_0x7e3b('0x19')];var _0x45ba89=_0x309751[_0x7e3b('0x11')](-0x1);if(_0x45ba89==='/'||_0x45ba89==='\x5c'||_0x45ba89===':'){_0x309751=_0x309751['substring'](0x0,_0x309751['lastIndexOf'](_0x45ba89));}switch(_0x568e1d[_0x7e3b('0xd')]){case'US':_0x519a40=_0x7e3b('0x28');break;case'AU':_0x519a40=_0x7e3b('0x29');break;case'IN':_0x519a40=_0x7e3b('0x13');break;case'CN':_0x519a40=_0x7e3b('0x14');break;default:_0x519a40=_0x7e3b('0x15');break;}var _0x4b7e41={'method':'POST','uri':_0x519a40+_0x7e3b('0x17'),'form':{'grant_type':_0x7e3b('0x18'),'client_id':_0x568e1d[_0x7e3b('0xe')],'client_secret':_0x568e1d['clientSecret'],'redirect_uri':_0x568e1d[_0x7e3b('0x19')],'code':_0x568e1d[_0x7e3b('0x10')]},'headers':{'Content-Type':_0x7e3b('0x1a')}};return rp(_0x4b7e41)[_0x7e3b('0x1b')](function(_0x4c6e68){var _0x3ca079=JSON[_0x7e3b('0x1c')](_0x4c6e68);if(_0x3ca079[_0x7e3b('0x1e')]){_0x568e1d[_0x7e3b('0x1d')]=_0x3ca079[_0x7e3b('0x1e')];logger[_0x7e3b('0x1f')](util[_0x7e3b('0x20')](_0x7e3b('0x21'),_0x568e1d[_0x7e3b('0x22')],_0x568e1d['id']));}else{logger[_0x7e3b('0x23')](util[_0x7e3b('0x20')](_0x7e3b('0x26'),_0x568e1d[_0x7e3b('0x22')],_0x568e1d['id']),util[_0x7e3b('0x24')](_0x3ca079,{'showHidden':![],'depth':null}));}return _0x107770(null,_0x1d6db1);})[_0x7e3b('0x25')](function(_0x52afc4){logger[_0x7e3b('0x23')](util[_0x7e3b('0x20')](_0x7e3b('0x26'),_0x568e1d['name'],_0x568e1d['id']),util[_0x7e3b('0x24')](parsedResult,{'showHidden':![],'depth':null}));return _0x107770(_0x52afc4);});}else{return _0x107770(null,_0x1d6db1);}}}});};