Built motion from commit 20b39a97.|2.6.29
[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 _0xeca5=['https://accounts.zoho.eu','authorization_code','clientSecret','application/x-www-form-urlencoded','then','refresh_token','refreshToken','info','format','name','error','ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d','inspect','catch','code','https://accounts.zoho.com.au','parse','ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d','lodash','util','../../config/logger','api','moment','bluebird','request-promise','path','rimraf','../../config/environment','./intZohoAccount.attributes','../../components/integrations/configuration','define','changed','zone','serverUrl','clientId','host','slice','substring','lastIndexOf','https://accounts.zoho.com','https://accounts.zoho.in','https://accounts.zoho.com.cn'];(function(_0x4801bd,_0x368071){var _0x3cf6fc=function(_0x4d376c){while(--_0x4d376c){_0x4801bd['push'](_0x4801bd['shift']());}};_0x3cf6fc(++_0x368071);}(_0xeca5,0xe4));var _0x5eca=function(_0x5da3c6,_0x536542){_0x5da3c6=_0x5da3c6-0x0;var _0xc7a243=_0xeca5[_0x5da3c6];return _0xc7a243;};'use strict';var _=require(_0x5eca('0x0'));var util=require(_0x5eca('0x1'));var logger=require(_0x5eca('0x2'))(_0x5eca('0x3'));var moment=require(_0x5eca('0x4'));var BPromise=require(_0x5eca('0x5'));var rp=require(_0x5eca('0x6'));var fs=require('fs');var path=require(_0x5eca('0x7'));var rimraf=require(_0x5eca('0x8'));var config=require(_0x5eca('0x9'));var attributes=require(_0x5eca('0xa'));var integrations=require(_0x5eca('0xb'));module['exports']=function(_0x471d83,_0x25933d){return _0x471d83[_0x5eca('0xc')]('ZohoAccount',attributes,{'tableName':'int_zoho_accounts','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x838731,_0xe88781,_0x107459){if(_0x838731[_0x5eca('0xd')](_0x5eca('0xe'))||_0x838731[_0x5eca('0xd')](_0x5eca('0xf'))||_0x838731[_0x5eca('0xd')](_0x5eca('0x10'))||_0x838731['changed']('clientSecret')||_0x838731[_0x5eca('0xd')]('code')||_0x838731[_0x5eca('0xd')](_0x5eca('0x11'))){var _0x492aa4,_0xee31ac;_0x492aa4=_0x838731[_0x5eca('0xf')];var _0x112ada=_0x492aa4[_0x5eca('0x12')](-0x1);if(_0x112ada==='/'||_0x112ada==='\x5c'||_0x112ada===':'){_0x492aa4=_0x492aa4[_0x5eca('0x13')](0x0,_0x492aa4[_0x5eca('0x14')](_0x112ada));}switch(_0x838731[_0x5eca('0xe')]){case'US':_0xee31ac=_0x5eca('0x15');break;case'AU':_0xee31ac='https://accounts.zoho.com.au';break;case'IN':_0xee31ac=_0x5eca('0x16');break;case'CN':_0xee31ac=_0x5eca('0x17');break;default:_0xee31ac=_0x5eca('0x18');break;}var _0x243dd6={'method':'POST','uri':_0xee31ac+'/oauth/v2/token','form':{'grant_type':_0x5eca('0x19'),'client_id':_0x838731['clientId'],'client_secret':_0x838731[_0x5eca('0x1a')],'redirect_uri':_0x838731[_0x5eca('0xf')],'code':_0x838731['code']},'headers':{'Content-Type':_0x5eca('0x1b')}};return rp(_0x243dd6)[_0x5eca('0x1c')](function(_0x5854c3){var _0x32bad4=JSON['parse'](_0x5854c3);if(_0x32bad4[_0x5eca('0x1d')]){_0x838731[_0x5eca('0x1e')]=_0x32bad4[_0x5eca('0x1d')];logger[_0x5eca('0x1f')](util[_0x5eca('0x20')]('ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d',_0x838731[_0x5eca('0x21')],_0x838731['id']));}else{logger[_0x5eca('0x22')](util[_0x5eca('0x20')](_0x5eca('0x23'),_0x838731['name'],_0x838731['id']),util[_0x5eca('0x24')](_0x32bad4,{'showHidden':![],'depth':null}));}return _0x107459(null,_0xe88781);})[_0x5eca('0x25')](function(_0x2f8bc8){logger[_0x5eca('0x22')](util[_0x5eca('0x20')](_0x5eca('0x23'),_0x838731[_0x5eca('0x21')],_0x838731['id']),util[_0x5eca('0x24')](parsedResult,{'showHidden':![],'depth':null}));return _0x107459(_0x2f8bc8);});}else{return _0x107459(null,_0xe88781);}},'beforeUpdate':function(_0x31098b,_0x585648,_0x23e463){if(_0x31098b[_0x5eca('0xd')](_0x5eca('0xe'))||_0x31098b['changed'](_0x5eca('0xf'))||_0x31098b[_0x5eca('0xd')](_0x5eca('0x10'))||_0x31098b[_0x5eca('0xd')](_0x5eca('0x1a'))||_0x31098b['changed'](_0x5eca('0x26'))||_0x31098b[_0x5eca('0xd')]('host')){var _0x1b7667,_0xfe6df5;_0x1b7667=_0x31098b[_0x5eca('0xf')];var _0x1a7ef8=_0x1b7667[_0x5eca('0x12')](-0x1);if(_0x1a7ef8==='/'||_0x1a7ef8==='\x5c'||_0x1a7ef8===':'){_0x1b7667=_0x1b7667[_0x5eca('0x13')](0x0,_0x1b7667[_0x5eca('0x14')](_0x1a7ef8));}switch(_0x31098b[_0x5eca('0xe')]){case'US':_0xfe6df5=_0x5eca('0x15');break;case'AU':_0xfe6df5=_0x5eca('0x27');break;case'IN':_0xfe6df5='https://accounts.zoho.in';break;case'CN':_0xfe6df5='https://accounts.zoho.com.cn';break;default:_0xfe6df5='https://accounts.zoho.eu';break;}var _0x58133b={'method':'POST','uri':_0xfe6df5+'/oauth/v2/token','form':{'grant_type':_0x5eca('0x19'),'client_id':_0x31098b['clientId'],'client_secret':_0x31098b[_0x5eca('0x1a')],'redirect_uri':_0x31098b[_0x5eca('0xf')],'code':_0x31098b[_0x5eca('0x26')]},'headers':{'Content-Type':'application/x-www-form-urlencoded'}};return rp(_0x58133b)[_0x5eca('0x1c')](function(_0x46c648){var _0x3ab3a1=JSON[_0x5eca('0x28')](_0x46c648);if(_0x3ab3a1[_0x5eca('0x1d')]){_0x31098b['refreshToken']=_0x3ab3a1[_0x5eca('0x1d')];logger[_0x5eca('0x1f')](util[_0x5eca('0x20')](_0x5eca('0x29'),_0x31098b[_0x5eca('0x21')],_0x31098b['id']));}else{logger['error'](util['format'](_0x5eca('0x23'),_0x31098b[_0x5eca('0x21')],_0x31098b['id']),util['inspect'](_0x3ab3a1,{'showHidden':![],'depth':null}));}return _0x23e463(null,_0x585648);})[_0x5eca('0x25')](function(_0x2a3c80){logger['error'](util[_0x5eca('0x20')]('ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d',_0x31098b[_0x5eca('0x21')],_0x31098b['id']),util[_0x5eca('0x24')](parsedResult,{'showHidden':![],'depth':null}));return _0x23e463(_0x2a3c80);});}else{return _0x23e463(null,_0x585648);}}}});};