Built motion from commit (unavailable).|2.5.4
[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 _0x7eff=['clientId','code','host','slice','substring','lastIndexOf','https://accounts.zoho.com.au','https://accounts.zoho.in','POST','/oauth/v2/token','authorization_code','clientSecret','then','parse','refresh_token','info','format','name','error','ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d','inspect','catch','https://accounts.zoho.com.cn','https://accounts.zoho.eu','application/x-www-form-urlencoded','refreshToken','ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d','util','../../config/logger','api','moment','bluebird','request-promise','rimraf','../../config/environment','./intZohoAccount.attributes','exports','ZohoAccount','changed','zone','serverUrl'];(function(_0x2f5ac5,_0x1ee939){var _0x37c9a8=function(_0x15031f){while(--_0x15031f){_0x2f5ac5['push'](_0x2f5ac5['shift']());}};_0x37c9a8(++_0x1ee939);}(_0x7eff,0x96));var _0xf7ef=function(_0x321bb2,_0x202794){_0x321bb2=_0x321bb2-0x0;var _0x9c12ed=_0x7eff[_0x321bb2];return _0x9c12ed;};'use strict';var _=require('lodash');var util=require(_0xf7ef('0x0'));var logger=require(_0xf7ef('0x1'))(_0xf7ef('0x2'));var moment=require(_0xf7ef('0x3'));var BPromise=require(_0xf7ef('0x4'));var rp=require(_0xf7ef('0x5'));var fs=require('fs');var path=require('path');var rimraf=require(_0xf7ef('0x6'));var config=require(_0xf7ef('0x7'));var attributes=require(_0xf7ef('0x8'));var integrations=require('../../components/integrations/configuration');module[_0xf7ef('0x9')]=function(_0x50a4d7,_0x5c472f){return _0x50a4d7['define'](_0xf7ef('0xa'),attributes,{'tableName':'int_zoho_accounts','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x323db4,_0x54a51a,_0x4b031f){if(_0x323db4[_0xf7ef('0xb')](_0xf7ef('0xc'))||_0x323db4[_0xf7ef('0xb')](_0xf7ef('0xd'))||_0x323db4[_0xf7ef('0xb')](_0xf7ef('0xe'))||_0x323db4['changed']('clientSecret')||_0x323db4[_0xf7ef('0xb')](_0xf7ef('0xf'))||_0x323db4[_0xf7ef('0xb')](_0xf7ef('0x10'))){var _0x5829cc,_0x5a1077;_0x5829cc=_0x323db4[_0xf7ef('0xd')];var _0x4a01e7=_0x5829cc[_0xf7ef('0x11')](-0x1);if(_0x4a01e7==='/'||_0x4a01e7==='\x5c'||_0x4a01e7===':'){_0x5829cc=_0x5829cc[_0xf7ef('0x12')](0x0,_0x5829cc[_0xf7ef('0x13')](_0x4a01e7));}switch(_0x323db4[_0xf7ef('0xc')]){case'US':_0x5a1077='https://accounts.zoho.com';break;case'AU':_0x5a1077=_0xf7ef('0x14');break;case'IN':_0x5a1077=_0xf7ef('0x15');break;case'CN':_0x5a1077='https://accounts.zoho.com.cn';break;default:_0x5a1077='https://accounts.zoho.eu';break;}var _0x827262={'method':_0xf7ef('0x16'),'uri':_0x5a1077+_0xf7ef('0x17'),'form':{'grant_type':_0xf7ef('0x18'),'client_id':_0x323db4[_0xf7ef('0xe')],'client_secret':_0x323db4[_0xf7ef('0x19')],'redirect_uri':_0x323db4[_0xf7ef('0xd')],'code':_0x323db4[_0xf7ef('0xf')]},'headers':{'Content-Type':'application/x-www-form-urlencoded'}};return rp(_0x827262)[_0xf7ef('0x1a')](function(_0x181f28){var _0x146aef=JSON[_0xf7ef('0x1b')](_0x181f28);if(_0x146aef[_0xf7ef('0x1c')]){_0x323db4['refreshToken']=_0x146aef['refresh_token'];logger[_0xf7ef('0x1d')](util[_0xf7ef('0x1e')]('ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d',_0x323db4[_0xf7ef('0x1f')],_0x323db4['id']));}else{logger[_0xf7ef('0x20')](util[_0xf7ef('0x1e')](_0xf7ef('0x21'),_0x323db4[_0xf7ef('0x1f')],_0x323db4['id']),util[_0xf7ef('0x22')](_0x146aef,{'showHidden':![],'depth':null}));}return _0x4b031f(null,_0x54a51a);})[_0xf7ef('0x23')](function(_0x33aece){logger[_0xf7ef('0x20')](util[_0xf7ef('0x1e')](_0xf7ef('0x21'),_0x323db4[_0xf7ef('0x1f')],_0x323db4['id']),util['inspect'](parsedResult,{'showHidden':![],'depth':null}));return _0x4b031f(_0x33aece);});}else{return _0x4b031f(null,_0x54a51a);}},'beforeUpdate':function(_0x40f0ac,_0x173e17,_0x61db4a){if(_0x40f0ac[_0xf7ef('0xb')](_0xf7ef('0xc'))||_0x40f0ac['changed'](_0xf7ef('0xd'))||_0x40f0ac['changed'](_0xf7ef('0xe'))||_0x40f0ac[_0xf7ef('0xb')]('clientSecret')||_0x40f0ac[_0xf7ef('0xb')]('code')||_0x40f0ac['changed'](_0xf7ef('0x10'))){var _0x2e71a0,_0x2f4f5c;_0x2e71a0=_0x40f0ac[_0xf7ef('0xd')];var _0x3a7c4a=_0x2e71a0[_0xf7ef('0x11')](-0x1);if(_0x3a7c4a==='/'||_0x3a7c4a==='\x5c'||_0x3a7c4a===':'){_0x2e71a0=_0x2e71a0[_0xf7ef('0x12')](0x0,_0x2e71a0[_0xf7ef('0x13')](_0x3a7c4a));}switch(_0x40f0ac[_0xf7ef('0xc')]){case'US':_0x2f4f5c='https://accounts.zoho.com';break;case'AU':_0x2f4f5c='https://accounts.zoho.com.au';break;case'IN':_0x2f4f5c='https://accounts.zoho.in';break;case'CN':_0x2f4f5c=_0xf7ef('0x24');break;default:_0x2f4f5c=_0xf7ef('0x25');break;}var _0x213abb={'method':'POST','uri':_0x2f4f5c+_0xf7ef('0x17'),'form':{'grant_type':'authorization_code','client_id':_0x40f0ac[_0xf7ef('0xe')],'client_secret':_0x40f0ac[_0xf7ef('0x19')],'redirect_uri':_0x40f0ac[_0xf7ef('0xd')],'code':_0x40f0ac[_0xf7ef('0xf')]},'headers':{'Content-Type':_0xf7ef('0x26')}};return rp(_0x213abb)[_0xf7ef('0x1a')](function(_0x3507da){var _0x29f7e4=JSON['parse'](_0x3507da);if(_0x29f7e4['refresh_token']){_0x40f0ac[_0xf7ef('0x27')]=_0x29f7e4[_0xf7ef('0x1c')];logger[_0xf7ef('0x1d')](util[_0xf7ef('0x1e')](_0xf7ef('0x28'),_0x40f0ac['name'],_0x40f0ac['id']));}else{logger[_0xf7ef('0x20')](util[_0xf7ef('0x1e')](_0xf7ef('0x21'),_0x40f0ac[_0xf7ef('0x1f')],_0x40f0ac['id']),util[_0xf7ef('0x22')](_0x29f7e4,{'showHidden':![],'depth':null}));}return _0x61db4a(null,_0x173e17);})[_0xf7ef('0x23')](function(_0x24673a){logger['error'](util[_0xf7ef('0x1e')](_0xf7ef('0x21'),_0x40f0ac[_0xf7ef('0x1f')],_0x40f0ac['id']),util[_0xf7ef('0x22')](parsedResult,{'showHidden':![],'depth':null}));return _0x61db4a(_0x24673a);});}else{return _0x61db4a(null,_0x173e17);}}}});};