Built motion from commit (unavailable).|2.5.9
[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 _0x0bde=['int_zoho_accounts','changed','zone','serverUrl','clientSecret','code','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','info','format','name','error','ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d','inspect','host','authorization_code','clientId','parse','ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d','catch','lodash','api','request-promise','rimraf','../../config/environment','./intZohoAccount.attributes','../../components/integrations/configuration','exports','define','ZohoAccount'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0x0bde,0x1b9));var _0xe0bd=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0x0bde[_0x2641f9];return _0x585741;};'use strict';var _=require(_0xe0bd('0x0'));var util=require('util');var logger=require('../../config/logger')(_0xe0bd('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rp=require(_0xe0bd('0x2'));var fs=require('fs');var path=require('path');var rimraf=require(_0xe0bd('0x3'));var config=require(_0xe0bd('0x4'));var attributes=require(_0xe0bd('0x5'));var integrations=require(_0xe0bd('0x6'));module[_0xe0bd('0x7')]=function(_0x51d6e5,_0x11ad31){return _0x51d6e5[_0xe0bd('0x8')](_0xe0bd('0x9'),attributes,{'tableName':_0xe0bd('0xa'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x2fc817,_0x26bd36,_0x315c03){if(_0x2fc817[_0xe0bd('0xb')](_0xe0bd('0xc'))||_0x2fc817[_0xe0bd('0xb')](_0xe0bd('0xd'))||_0x2fc817[_0xe0bd('0xb')]('clientId')||_0x2fc817['changed'](_0xe0bd('0xe'))||_0x2fc817[_0xe0bd('0xb')](_0xe0bd('0xf'))||_0x2fc817[_0xe0bd('0xb')]('host')){var _0x2adf8a,_0x476845;_0x2adf8a=_0x2fc817[_0xe0bd('0xd')];var _0x4761d5=_0x2adf8a[_0xe0bd('0x10')](-0x1);if(_0x4761d5==='/'||_0x4761d5==='\x5c'||_0x4761d5===':'){_0x2adf8a=_0x2adf8a[_0xe0bd('0x11')](0x0,_0x2adf8a[_0xe0bd('0x12')](_0x4761d5));}switch(_0x2fc817['zone']){case'US':_0x476845=_0xe0bd('0x13');break;case'AU':_0x476845='https://accounts.zoho.com.au';break;case'IN':_0x476845=_0xe0bd('0x14');break;case'CN':_0x476845=_0xe0bd('0x15');break;default:_0x476845=_0xe0bd('0x16');break;}var _0x12a07e={'method':_0xe0bd('0x17'),'uri':_0x476845+_0xe0bd('0x18'),'form':{'grant_type':'authorization_code','client_id':_0x2fc817['clientId'],'client_secret':_0x2fc817['clientSecret'],'redirect_uri':_0x2fc817[_0xe0bd('0xd')],'code':_0x2fc817[_0xe0bd('0xf')]},'headers':{'Content-Type':_0xe0bd('0x19')}};return rp(_0x12a07e)[_0xe0bd('0x1a')](function(_0x33ed79){var _0x479b20=JSON['parse'](_0x33ed79);if(_0x479b20[_0xe0bd('0x1b')]){_0x2fc817[_0xe0bd('0x1c')]=_0x479b20[_0xe0bd('0x1b')];logger[_0xe0bd('0x1d')](util[_0xe0bd('0x1e')]('ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d',_0x2fc817[_0xe0bd('0x1f')],_0x2fc817['id']));}else{logger[_0xe0bd('0x20')](util[_0xe0bd('0x1e')](_0xe0bd('0x21'),_0x2fc817[_0xe0bd('0x1f')],_0x2fc817['id']),util['inspect'](_0x479b20,{'showHidden':![],'depth':null}));}return _0x315c03(null,_0x26bd36);})['catch'](function(_0x1c041a){logger[_0xe0bd('0x20')](util['format'](_0xe0bd('0x21'),_0x2fc817['name'],_0x2fc817['id']),util[_0xe0bd('0x22')](parsedResult,{'showHidden':![],'depth':null}));return _0x315c03(_0x1c041a);});}else{return _0x315c03(null,_0x26bd36);}},'beforeUpdate':function(_0x3adf51,_0x57a6c0,_0x585e84){if(_0x3adf51[_0xe0bd('0xb')]('zone')||_0x3adf51[_0xe0bd('0xb')](_0xe0bd('0xd'))||_0x3adf51[_0xe0bd('0xb')]('clientId')||_0x3adf51['changed'](_0xe0bd('0xe'))||_0x3adf51['changed'](_0xe0bd('0xf'))||_0x3adf51[_0xe0bd('0xb')](_0xe0bd('0x23'))){var _0x525515,_0x447cb0;_0x525515=_0x3adf51['serverUrl'];var _0x52da6c=_0x525515[_0xe0bd('0x10')](-0x1);if(_0x52da6c==='/'||_0x52da6c==='\x5c'||_0x52da6c===':'){_0x525515=_0x525515['substring'](0x0,_0x525515['lastIndexOf'](_0x52da6c));}switch(_0x3adf51[_0xe0bd('0xc')]){case'US':_0x447cb0=_0xe0bd('0x13');break;case'AU':_0x447cb0='https://accounts.zoho.com.au';break;case'IN':_0x447cb0=_0xe0bd('0x14');break;case'CN':_0x447cb0=_0xe0bd('0x15');break;default:_0x447cb0=_0xe0bd('0x16');break;}var _0x22d05a={'method':_0xe0bd('0x17'),'uri':_0x447cb0+_0xe0bd('0x18'),'form':{'grant_type':_0xe0bd('0x24'),'client_id':_0x3adf51[_0xe0bd('0x25')],'client_secret':_0x3adf51['clientSecret'],'redirect_uri':_0x3adf51[_0xe0bd('0xd')],'code':_0x3adf51[_0xe0bd('0xf')]},'headers':{'Content-Type':'application/x-www-form-urlencoded'}};return rp(_0x22d05a)[_0xe0bd('0x1a')](function(_0x1c9605){var _0x44453e=JSON[_0xe0bd('0x26')](_0x1c9605);if(_0x44453e[_0xe0bd('0x1b')]){_0x3adf51[_0xe0bd('0x1c')]=_0x44453e[_0xe0bd('0x1b')];logger[_0xe0bd('0x1d')](util[_0xe0bd('0x1e')](_0xe0bd('0x27'),_0x3adf51['name'],_0x3adf51['id']));}else{logger[_0xe0bd('0x20')](util['format'](_0xe0bd('0x21'),_0x3adf51[_0xe0bd('0x1f')],_0x3adf51['id']),util[_0xe0bd('0x22')](_0x44453e,{'showHidden':![],'depth':null}));}return _0x585e84(null,_0x57a6c0);})[_0xe0bd('0x28')](function(_0xe42389){logger[_0xe0bd('0x20')](util[_0xe0bd('0x1e')](_0xe0bd('0x21'),_0x3adf51[_0xe0bd('0x1f')],_0x3adf51['id']),util['inspect'](parsedResult,{'showHidden':![],'depth':null}));return _0x585e84(_0xe42389);});}else{return _0x585e84(null,_0x57a6c0);}}}});};