Built motion from commit 87cd5f02.|2.5.48
[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 _0xa32d=['then','parse','refresh_token','refreshToken','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.eu','catch','lodash','util','../../config/logger','api','bluebird','request-promise','path','rimraf','../../config/environment','./intZohoAccount.attributes','../../components/integrations/configuration','define','ZohoAccount','int_zoho_accounts','changed','serverUrl','clientId','clientSecret','code','host','substring','lastIndexOf','zone','https://accounts.zoho.com','https://accounts.zoho.com.au','https://accounts.zoho.in','https://accounts.zoho.com.cn','POST','/oauth/v2/token','authorization_code','application/x-www-form-urlencoded'];(function(_0x1c4903,_0x2c8ecd){var _0x1f0af5=function(_0x90ceaa){while(--_0x90ceaa){_0x1c4903['push'](_0x1c4903['shift']());}};_0x1f0af5(++_0x2c8ecd);}(_0xa32d,0x68));var _0xda32=function(_0x4defd6,_0x37bbd3){_0x4defd6=_0x4defd6-0x0;var _0x4c9276=_0xa32d[_0x4defd6];return _0x4c9276;};'use strict';var _=require(_0xda32('0x0'));var util=require(_0xda32('0x1'));var logger=require(_0xda32('0x2'))(_0xda32('0x3'));var moment=require('moment');var BPromise=require(_0xda32('0x4'));var rp=require(_0xda32('0x5'));var fs=require('fs');var path=require(_0xda32('0x6'));var rimraf=require(_0xda32('0x7'));var config=require(_0xda32('0x8'));var attributes=require(_0xda32('0x9'));var integrations=require(_0xda32('0xa'));module['exports']=function(_0x13f4b8,_0x4e9f14){return _0x13f4b8[_0xda32('0xb')](_0xda32('0xc'),attributes,{'tableName':_0xda32('0xd'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x11b5a3,_0x316afc,_0x440d4d){if(_0x11b5a3[_0xda32('0xe')]('zone')||_0x11b5a3[_0xda32('0xe')](_0xda32('0xf'))||_0x11b5a3[_0xda32('0xe')](_0xda32('0x10'))||_0x11b5a3[_0xda32('0xe')](_0xda32('0x11'))||_0x11b5a3[_0xda32('0xe')](_0xda32('0x12'))||_0x11b5a3[_0xda32('0xe')](_0xda32('0x13'))){var _0x2882e4,_0x351722;_0x2882e4=_0x11b5a3[_0xda32('0xf')];var _0x5dffa8=_0x2882e4['slice'](-0x1);if(_0x5dffa8==='/'||_0x5dffa8==='\x5c'||_0x5dffa8===':'){_0x2882e4=_0x2882e4[_0xda32('0x14')](0x0,_0x2882e4[_0xda32('0x15')](_0x5dffa8));}switch(_0x11b5a3[_0xda32('0x16')]){case'US':_0x351722=_0xda32('0x17');break;case'AU':_0x351722=_0xda32('0x18');break;case'IN':_0x351722=_0xda32('0x19');break;case'CN':_0x351722=_0xda32('0x1a');break;default:_0x351722='https://accounts.zoho.eu';break;}var _0x583d0a={'method':_0xda32('0x1b'),'uri':_0x351722+_0xda32('0x1c'),'form':{'grant_type':_0xda32('0x1d'),'client_id':_0x11b5a3[_0xda32('0x10')],'client_secret':_0x11b5a3[_0xda32('0x11')],'redirect_uri':_0x11b5a3[_0xda32('0xf')],'code':_0x11b5a3[_0xda32('0x12')]},'headers':{'Content-Type':_0xda32('0x1e')}};return rp(_0x583d0a)[_0xda32('0x1f')](function(_0xa92fbc){var _0x30c83d=JSON[_0xda32('0x20')](_0xa92fbc);if(_0x30c83d[_0xda32('0x21')]){_0x11b5a3[_0xda32('0x22')]=_0x30c83d[_0xda32('0x21')];logger[_0xda32('0x23')](util['format'](_0xda32('0x24'),_0x11b5a3[_0xda32('0x25')],_0x11b5a3['id']));}else{logger[_0xda32('0x26')](util[_0xda32('0x27')](_0xda32('0x28'),_0x11b5a3[_0xda32('0x25')],_0x11b5a3['id']),util[_0xda32('0x29')](_0x30c83d,{'showHidden':![],'depth':null}));}return _0x440d4d(null,_0x316afc);})['catch'](function(_0x41bde9){logger['error'](util[_0xda32('0x27')]('ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d',_0x11b5a3[_0xda32('0x25')],_0x11b5a3['id']),util[_0xda32('0x29')](parsedResult,{'showHidden':![],'depth':null}));return _0x440d4d(_0x41bde9);});}else{return _0x440d4d(null,_0x316afc);}},'beforeUpdate':function(_0x3121b5,_0x2fd25c,_0x242838){if(_0x3121b5[_0xda32('0xe')](_0xda32('0x16'))||_0x3121b5[_0xda32('0xe')](_0xda32('0xf'))||_0x3121b5[_0xda32('0xe')](_0xda32('0x10'))||_0x3121b5[_0xda32('0xe')]('clientSecret')||_0x3121b5[_0xda32('0xe')]('code')||_0x3121b5[_0xda32('0xe')](_0xda32('0x13'))){var _0x552b46,_0x2bec61;_0x552b46=_0x3121b5[_0xda32('0xf')];var _0x37e976=_0x552b46[_0xda32('0x2a')](-0x1);if(_0x37e976==='/'||_0x37e976==='\x5c'||_0x37e976===':'){_0x552b46=_0x552b46[_0xda32('0x14')](0x0,_0x552b46[_0xda32('0x15')](_0x37e976));}switch(_0x3121b5[_0xda32('0x16')]){case'US':_0x2bec61='https://accounts.zoho.com';break;case'AU':_0x2bec61=_0xda32('0x18');break;case'IN':_0x2bec61=_0xda32('0x19');break;case'CN':_0x2bec61=_0xda32('0x1a');break;default:_0x2bec61=_0xda32('0x2b');break;}var _0x21a438={'method':_0xda32('0x1b'),'uri':_0x2bec61+_0xda32('0x1c'),'form':{'grant_type':_0xda32('0x1d'),'client_id':_0x3121b5['clientId'],'client_secret':_0x3121b5[_0xda32('0x11')],'redirect_uri':_0x3121b5[_0xda32('0xf')],'code':_0x3121b5[_0xda32('0x12')]},'headers':{'Content-Type':_0xda32('0x1e')}};return rp(_0x21a438)[_0xda32('0x1f')](function(_0x548ead){var _0x5a9536=JSON['parse'](_0x548ead);if(_0x5a9536[_0xda32('0x21')]){_0x3121b5['refreshToken']=_0x5a9536['refresh_token'];logger['info'](util['format'](_0xda32('0x24'),_0x3121b5['name'],_0x3121b5['id']));}else{logger[_0xda32('0x26')](util[_0xda32('0x27')](_0xda32('0x28'),_0x3121b5['name'],_0x3121b5['id']),util['inspect'](_0x5a9536,{'showHidden':![],'depth':null}));}return _0x242838(null,_0x2fd25c);})[_0xda32('0x2c')](function(_0x15e1e6){logger['error'](util[_0xda32('0x27')](_0xda32('0x28'),_0x3121b5['name'],_0x3121b5['id']),util[_0xda32('0x29')](parsedResult,{'showHidden':![],'depth':null}));return _0x242838(_0x15e1e6);});}else{return _0x242838(null,_0x2fd25c);}}}});};