Built motion from commit d13fb11b.|2.6.34
[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 _0x63e5=['clientId','clientSecret','code','host','substring','lastIndexOf','https://accounts.zoho.com.au','https://accounts.zoho.in','https://accounts.zoho.com.cn','https://accounts.zoho.eu','POST','/oauth/v2/token','authorization_code','then','parse','refresh_token','info','ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d','name','error','format','ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d','inspect','slice','https://accounts.zoho.com','application/x-www-form-urlencoded','refreshToken','catch','../../config/logger','moment','request-promise','path','../../config/environment','./intZohoAccount.attributes','../../components/integrations/configuration','define','ZohoAccount','int_zoho_accounts','zone','changed','serverUrl'];(function(_0x46f5ca,_0x3eb787){var _0x3b7738=function(_0x25f469){while(--_0x25f469){_0x46f5ca['push'](_0x46f5ca['shift']());}};_0x3b7738(++_0x3eb787);}(_0x63e5,0x18d));var _0x563e=function(_0x342700,_0x569f75){_0x342700=_0x342700-0x0;var _0x53406f=_0x63e5[_0x342700];return _0x53406f;};'use strict';var _=require('lodash');var util=require('util');var logger=require(_0x563e('0x0'))('api');var moment=require(_0x563e('0x1'));var BPromise=require('bluebird');var rp=require(_0x563e('0x2'));var fs=require('fs');var path=require(_0x563e('0x3'));var rimraf=require('rimraf');var config=require(_0x563e('0x4'));var attributes=require(_0x563e('0x5'));var integrations=require(_0x563e('0x6'));module['exports']=function(_0x5d0367,_0x5c2448){return _0x5d0367[_0x563e('0x7')](_0x563e('0x8'),attributes,{'tableName':_0x563e('0x9'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x5468bf,_0x5b0463,_0xb1b597){if(_0x5468bf['changed'](_0x563e('0xa'))||_0x5468bf[_0x563e('0xb')](_0x563e('0xc'))||_0x5468bf[_0x563e('0xb')](_0x563e('0xd'))||_0x5468bf[_0x563e('0xb')](_0x563e('0xe'))||_0x5468bf[_0x563e('0xb')](_0x563e('0xf'))||_0x5468bf[_0x563e('0xb')](_0x563e('0x10'))){var _0x4c1939,_0x26fadc;_0x4c1939=_0x5468bf[_0x563e('0xc')];var _0x30f495=_0x4c1939['slice'](-0x1);if(_0x30f495==='/'||_0x30f495==='\x5c'||_0x30f495===':'){_0x4c1939=_0x4c1939[_0x563e('0x11')](0x0,_0x4c1939[_0x563e('0x12')](_0x30f495));}switch(_0x5468bf[_0x563e('0xa')]){case'US':_0x26fadc='https://accounts.zoho.com';break;case'AU':_0x26fadc=_0x563e('0x13');break;case'IN':_0x26fadc=_0x563e('0x14');break;case'CN':_0x26fadc=_0x563e('0x15');break;default:_0x26fadc=_0x563e('0x16');break;}var _0x4fd8c3={'method':_0x563e('0x17'),'uri':_0x26fadc+_0x563e('0x18'),'form':{'grant_type':_0x563e('0x19'),'client_id':_0x5468bf[_0x563e('0xd')],'client_secret':_0x5468bf[_0x563e('0xe')],'redirect_uri':_0x5468bf[_0x563e('0xc')],'code':_0x5468bf[_0x563e('0xf')]},'headers':{'Content-Type':'application/x-www-form-urlencoded'}};return rp(_0x4fd8c3)[_0x563e('0x1a')](function(_0x3bbc94){var _0x167bb7=JSON[_0x563e('0x1b')](_0x3bbc94);if(_0x167bb7[_0x563e('0x1c')]){_0x5468bf['refreshToken']=_0x167bb7[_0x563e('0x1c')];logger[_0x563e('0x1d')](util['format'](_0x563e('0x1e'),_0x5468bf[_0x563e('0x1f')],_0x5468bf['id']));}else{logger[_0x563e('0x20')](util[_0x563e('0x21')](_0x563e('0x22'),_0x5468bf[_0x563e('0x1f')],_0x5468bf['id']),util[_0x563e('0x23')](_0x167bb7,{'showHidden':![],'depth':null}));}return _0xb1b597(null,_0x5b0463);})['catch'](function(_0x12c99e){logger[_0x563e('0x20')](util[_0x563e('0x21')](_0x563e('0x22'),_0x5468bf[_0x563e('0x1f')],_0x5468bf['id']),util[_0x563e('0x23')](parsedResult,{'showHidden':![],'depth':null}));return _0xb1b597(_0x12c99e);});}else{return _0xb1b597(null,_0x5b0463);}},'beforeUpdate':function(_0x16381e,_0x473c7e,_0x5c3bfe){if(_0x16381e['changed']('zone')||_0x16381e['changed'](_0x563e('0xc'))||_0x16381e[_0x563e('0xb')](_0x563e('0xd'))||_0x16381e[_0x563e('0xb')]('clientSecret')||_0x16381e['changed'](_0x563e('0xf'))||_0x16381e[_0x563e('0xb')](_0x563e('0x10'))){var _0x2c6b21,_0x3c4c07;_0x2c6b21=_0x16381e['serverUrl'];var _0x52d167=_0x2c6b21[_0x563e('0x24')](-0x1);if(_0x52d167==='/'||_0x52d167==='\x5c'||_0x52d167===':'){_0x2c6b21=_0x2c6b21['substring'](0x0,_0x2c6b21[_0x563e('0x12')](_0x52d167));}switch(_0x16381e[_0x563e('0xa')]){case'US':_0x3c4c07=_0x563e('0x25');break;case'AU':_0x3c4c07=_0x563e('0x13');break;case'IN':_0x3c4c07='https://accounts.zoho.in';break;case'CN':_0x3c4c07=_0x563e('0x15');break;default:_0x3c4c07=_0x563e('0x16');break;}var _0x10a85d={'method':'POST','uri':_0x3c4c07+_0x563e('0x18'),'form':{'grant_type':'authorization_code','client_id':_0x16381e[_0x563e('0xd')],'client_secret':_0x16381e[_0x563e('0xe')],'redirect_uri':_0x16381e[_0x563e('0xc')],'code':_0x16381e[_0x563e('0xf')]},'headers':{'Content-Type':_0x563e('0x26')}};return rp(_0x10a85d)[_0x563e('0x1a')](function(_0x3d85f5){var _0x3dfc8e=JSON[_0x563e('0x1b')](_0x3d85f5);if(_0x3dfc8e[_0x563e('0x1c')]){_0x16381e[_0x563e('0x27')]=_0x3dfc8e[_0x563e('0x1c')];logger[_0x563e('0x1d')](util['format']('ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d',_0x16381e['name'],_0x16381e['id']));}else{logger[_0x563e('0x20')](util[_0x563e('0x21')](_0x563e('0x22'),_0x16381e['name'],_0x16381e['id']),util[_0x563e('0x23')](_0x3dfc8e,{'showHidden':![],'depth':null}));}return _0x5c3bfe(null,_0x473c7e);})[_0x563e('0x28')](function(_0x1431fe){logger[_0x563e('0x20')](util[_0x563e('0x21')]('ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d',_0x16381e['name'],_0x16381e['id']),util['inspect'](parsedResult,{'showHidden':![],'depth':null}));return _0x5c3bfe(_0x1431fe);});}else{return _0x5c3bfe(null,_0x473c7e);}}}});};