Built motion from commit 994c64e1.|2.6.1
[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 _0x77c8=['error','ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d','inspect','catch','https://accounts.zoho.com.au','parse','info','util','../../config/logger','request-promise','path','../../config/environment','./intZohoAccount.attributes','../../components/integrations/configuration','exports','define','ZohoAccount','int_zoho_accounts','changed','zone','serverUrl','clientId','clientSecret','code','host','slice','substring','lastIndexOf','https://accounts.zoho.com','https://accounts.zoho.in','https://accounts.zoho.com.cn','https://accounts.zoho.eu','POST','/oauth/v2/token','application/x-www-form-urlencoded','then','refresh_token','refreshToken','format','ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d','name'];(function(_0x42e40b,_0x5747f9){var _0x54a5b2=function(_0x46646d){while(--_0x46646d){_0x42e40b['push'](_0x42e40b['shift']());}};_0x54a5b2(++_0x5747f9);}(_0x77c8,0x14f));var _0x877c=function(_0x474d97,_0x5909ce){_0x474d97=_0x474d97-0x0;var _0x1edf25=_0x77c8[_0x474d97];return _0x1edf25;};'use strict';var _=require('lodash');var util=require(_0x877c('0x0'));var logger=require(_0x877c('0x1'))('api');var moment=require('moment');var BPromise=require('bluebird');var rp=require(_0x877c('0x2'));var fs=require('fs');var path=require(_0x877c('0x3'));var rimraf=require('rimraf');var config=require(_0x877c('0x4'));var attributes=require(_0x877c('0x5'));var integrations=require(_0x877c('0x6'));module[_0x877c('0x7')]=function(_0x2acdf3,_0x240f0a){return _0x2acdf3[_0x877c('0x8')](_0x877c('0x9'),attributes,{'tableName':_0x877c('0xa'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x356a24,_0x24ade6,_0x5e942b){if(_0x356a24[_0x877c('0xb')](_0x877c('0xc'))||_0x356a24[_0x877c('0xb')](_0x877c('0xd'))||_0x356a24[_0x877c('0xb')](_0x877c('0xe'))||_0x356a24[_0x877c('0xb')](_0x877c('0xf'))||_0x356a24['changed'](_0x877c('0x10'))||_0x356a24[_0x877c('0xb')](_0x877c('0x11'))){var _0x66f200,_0x14e113;_0x66f200=_0x356a24[_0x877c('0xd')];var _0x377cda=_0x66f200[_0x877c('0x12')](-0x1);if(_0x377cda==='/'||_0x377cda==='\x5c'||_0x377cda===':'){_0x66f200=_0x66f200[_0x877c('0x13')](0x0,_0x66f200[_0x877c('0x14')](_0x377cda));}switch(_0x356a24[_0x877c('0xc')]){case'US':_0x14e113=_0x877c('0x15');break;case'AU':_0x14e113='https://accounts.zoho.com.au';break;case'IN':_0x14e113=_0x877c('0x16');break;case'CN':_0x14e113=_0x877c('0x17');break;default:_0x14e113=_0x877c('0x18');break;}var _0x3aff54={'method':_0x877c('0x19'),'uri':_0x14e113+_0x877c('0x1a'),'form':{'grant_type':'authorization_code','client_id':_0x356a24[_0x877c('0xe')],'client_secret':_0x356a24[_0x877c('0xf')],'redirect_uri':_0x356a24[_0x877c('0xd')],'code':_0x356a24['code']},'headers':{'Content-Type':_0x877c('0x1b')}};return rp(_0x3aff54)[_0x877c('0x1c')](function(_0x51250c){var _0x5877be=JSON['parse'](_0x51250c);if(_0x5877be[_0x877c('0x1d')]){_0x356a24[_0x877c('0x1e')]=_0x5877be[_0x877c('0x1d')];logger['info'](util[_0x877c('0x1f')](_0x877c('0x20'),_0x356a24[_0x877c('0x21')],_0x356a24['id']));}else{logger[_0x877c('0x22')](util[_0x877c('0x1f')](_0x877c('0x23'),_0x356a24['name'],_0x356a24['id']),util[_0x877c('0x24')](_0x5877be,{'showHidden':![],'depth':null}));}return _0x5e942b(null,_0x24ade6);})[_0x877c('0x25')](function(_0x5d8bbe){logger[_0x877c('0x22')](util[_0x877c('0x1f')]('ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d',_0x356a24[_0x877c('0x21')],_0x356a24['id']),util[_0x877c('0x24')](parsedResult,{'showHidden':![],'depth':null}));return _0x5e942b(_0x5d8bbe);});}else{return _0x5e942b(null,_0x24ade6);}},'beforeUpdate':function(_0x36c9e5,_0x428b7e,_0x18e1d2){if(_0x36c9e5[_0x877c('0xb')]('zone')||_0x36c9e5['changed']('serverUrl')||_0x36c9e5[_0x877c('0xb')]('clientId')||_0x36c9e5[_0x877c('0xb')](_0x877c('0xf'))||_0x36c9e5[_0x877c('0xb')]('code')||_0x36c9e5['changed'](_0x877c('0x11'))){var _0x218c72,_0x9578f6;_0x218c72=_0x36c9e5[_0x877c('0xd')];var _0xe86f89=_0x218c72[_0x877c('0x12')](-0x1);if(_0xe86f89==='/'||_0xe86f89==='\x5c'||_0xe86f89===':'){_0x218c72=_0x218c72['substring'](0x0,_0x218c72[_0x877c('0x14')](_0xe86f89));}switch(_0x36c9e5[_0x877c('0xc')]){case'US':_0x9578f6='https://accounts.zoho.com';break;case'AU':_0x9578f6=_0x877c('0x26');break;case'IN':_0x9578f6=_0x877c('0x16');break;case'CN':_0x9578f6=_0x877c('0x17');break;default:_0x9578f6=_0x877c('0x18');break;}var _0x97515f={'method':_0x877c('0x19'),'uri':_0x9578f6+_0x877c('0x1a'),'form':{'grant_type':'authorization_code','client_id':_0x36c9e5[_0x877c('0xe')],'client_secret':_0x36c9e5[_0x877c('0xf')],'redirect_uri':_0x36c9e5[_0x877c('0xd')],'code':_0x36c9e5[_0x877c('0x10')]},'headers':{'Content-Type':_0x877c('0x1b')}};return rp(_0x97515f)[_0x877c('0x1c')](function(_0x40725){var _0x418e10=JSON[_0x877c('0x27')](_0x40725);if(_0x418e10['refresh_token']){_0x36c9e5[_0x877c('0x1e')]=_0x418e10[_0x877c('0x1d')];logger[_0x877c('0x28')](util['format']('ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d',_0x36c9e5[_0x877c('0x21')],_0x36c9e5['id']));}else{logger[_0x877c('0x22')](util[_0x877c('0x1f')](_0x877c('0x23'),_0x36c9e5['name'],_0x36c9e5['id']),util['inspect'](_0x418e10,{'showHidden':![],'depth':null}));}return _0x18e1d2(null,_0x428b7e);})[_0x877c('0x25')](function(_0x5062b0){logger[_0x877c('0x22')](util[_0x877c('0x1f')]('ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d',_0x36c9e5[_0x877c('0x21')],_0x36c9e5['id']),util[_0x877c('0x24')](parsedResult,{'showHidden':![],'depth':null}));return _0x18e1d2(_0x5062b0);});}else{return _0x18e1d2(null,_0x428b7e);}}}});};