Built motion from commit 775e2a94.|2.6.3
[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 _0xe721=['lastIndexOf','https://accounts.zoho.eu','POST','application/x-www-form-urlencoded','parse','ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d','util','../../config/logger','api','request-promise','path','rimraf','../../config/environment','./intZohoAccount.attributes','exports','ZohoAccount','changed','zone','serverUrl','clientId','clientSecret','code','https://accounts.zoho.com','https://accounts.zoho.in','https://accounts.zoho.com.cn','/oauth/v2/token','authorization_code','then','refresh_token','info','format','name','ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d','inspect','catch','error','host','slice','substring'];(function(_0x1a4a6a,_0x822688){var _0x1fd278=function(_0xe729f5){while(--_0xe729f5){_0x1a4a6a['push'](_0x1a4a6a['shift']());}};_0x1fd278(++_0x822688);}(_0xe721,0xa2));var _0x1e72=function(_0x3da91c,_0x5f436a){_0x3da91c=_0x3da91c-0x0;var _0x14d860=_0xe721[_0x3da91c];return _0x14d860;};'use strict';var _=require('lodash');var util=require(_0x1e72('0x0'));var logger=require(_0x1e72('0x1'))(_0x1e72('0x2'));var moment=require('moment');var BPromise=require('bluebird');var rp=require(_0x1e72('0x3'));var fs=require('fs');var path=require(_0x1e72('0x4'));var rimraf=require(_0x1e72('0x5'));var config=require(_0x1e72('0x6'));var attributes=require(_0x1e72('0x7'));var integrations=require('../../components/integrations/configuration');module[_0x1e72('0x8')]=function(_0x4397bc,_0x41eb25){return _0x4397bc['define'](_0x1e72('0x9'),attributes,{'tableName':'int_zoho_accounts','paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x2edee3,_0x311e20,_0x4e202e){if(_0x2edee3[_0x1e72('0xa')](_0x1e72('0xb'))||_0x2edee3[_0x1e72('0xa')](_0x1e72('0xc'))||_0x2edee3[_0x1e72('0xa')](_0x1e72('0xd'))||_0x2edee3[_0x1e72('0xa')](_0x1e72('0xe'))||_0x2edee3['changed'](_0x1e72('0xf'))||_0x2edee3['changed']('host')){var _0x6e9bcf,_0x2c5f86;_0x6e9bcf=_0x2edee3[_0x1e72('0xc')];var _0x1ce88b=_0x6e9bcf['slice'](-0x1);if(_0x1ce88b==='/'||_0x1ce88b==='\x5c'||_0x1ce88b===':'){_0x6e9bcf=_0x6e9bcf['substring'](0x0,_0x6e9bcf['lastIndexOf'](_0x1ce88b));}switch(_0x2edee3['zone']){case'US':_0x2c5f86=_0x1e72('0x10');break;case'AU':_0x2c5f86='https://accounts.zoho.com.au';break;case'IN':_0x2c5f86=_0x1e72('0x11');break;case'CN':_0x2c5f86=_0x1e72('0x12');break;default:_0x2c5f86='https://accounts.zoho.eu';break;}var _0x555f1b={'method':'POST','uri':_0x2c5f86+_0x1e72('0x13'),'form':{'grant_type':_0x1e72('0x14'),'client_id':_0x2edee3['clientId'],'client_secret':_0x2edee3[_0x1e72('0xe')],'redirect_uri':_0x2edee3[_0x1e72('0xc')],'code':_0x2edee3['code']},'headers':{'Content-Type':'application/x-www-form-urlencoded'}};return rp(_0x555f1b)[_0x1e72('0x15')](function(_0x54adfc){var _0x2cd05c=JSON['parse'](_0x54adfc);if(_0x2cd05c['refresh_token']){_0x2edee3['refreshToken']=_0x2cd05c[_0x1e72('0x16')];logger[_0x1e72('0x17')](util[_0x1e72('0x18')]('ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d',_0x2edee3[_0x1e72('0x19')],_0x2edee3['id']));}else{logger['error'](util[_0x1e72('0x18')](_0x1e72('0x1a'),_0x2edee3[_0x1e72('0x19')],_0x2edee3['id']),util[_0x1e72('0x1b')](_0x2cd05c,{'showHidden':![],'depth':null}));}return _0x4e202e(null,_0x311e20);})[_0x1e72('0x1c')](function(_0xede640){logger[_0x1e72('0x1d')](util['format'](_0x1e72('0x1a'),_0x2edee3[_0x1e72('0x19')],_0x2edee3['id']),util[_0x1e72('0x1b')](parsedResult,{'showHidden':![],'depth':null}));return _0x4e202e(_0xede640);});}else{return _0x4e202e(null,_0x311e20);}},'beforeUpdate':function(_0x295e13,_0x159896,_0x5da6d1){if(_0x295e13[_0x1e72('0xa')](_0x1e72('0xb'))||_0x295e13[_0x1e72('0xa')](_0x1e72('0xc'))||_0x295e13[_0x1e72('0xa')]('clientId')||_0x295e13[_0x1e72('0xa')](_0x1e72('0xe'))||_0x295e13[_0x1e72('0xa')](_0x1e72('0xf'))||_0x295e13['changed'](_0x1e72('0x1e'))){var _0x34ea37,_0x1466d2;_0x34ea37=_0x295e13[_0x1e72('0xc')];var _0x2ff71a=_0x34ea37[_0x1e72('0x1f')](-0x1);if(_0x2ff71a==='/'||_0x2ff71a==='\x5c'||_0x2ff71a===':'){_0x34ea37=_0x34ea37[_0x1e72('0x20')](0x0,_0x34ea37[_0x1e72('0x21')](_0x2ff71a));}switch(_0x295e13['zone']){case'US':_0x1466d2=_0x1e72('0x10');break;case'AU':_0x1466d2='https://accounts.zoho.com.au';break;case'IN':_0x1466d2='https://accounts.zoho.in';break;case'CN':_0x1466d2=_0x1e72('0x12');break;default:_0x1466d2=_0x1e72('0x22');break;}var _0x448d93={'method':_0x1e72('0x23'),'uri':_0x1466d2+'/oauth/v2/token','form':{'grant_type':'authorization_code','client_id':_0x295e13[_0x1e72('0xd')],'client_secret':_0x295e13[_0x1e72('0xe')],'redirect_uri':_0x295e13[_0x1e72('0xc')],'code':_0x295e13[_0x1e72('0xf')]},'headers':{'Content-Type':_0x1e72('0x24')}};return rp(_0x448d93)[_0x1e72('0x15')](function(_0x5314e5){var _0x9666f1=JSON[_0x1e72('0x25')](_0x5314e5);if(_0x9666f1[_0x1e72('0x16')]){_0x295e13['refreshToken']=_0x9666f1[_0x1e72('0x16')];logger[_0x1e72('0x17')](util['format'](_0x1e72('0x26'),_0x295e13[_0x1e72('0x19')],_0x295e13['id']));}else{logger[_0x1e72('0x1d')](util[_0x1e72('0x18')](_0x1e72('0x1a'),_0x295e13[_0x1e72('0x19')],_0x295e13['id']),util['inspect'](_0x9666f1,{'showHidden':![],'depth':null}));}return _0x5da6d1(null,_0x159896);})['catch'](function(_0x5215b6){logger[_0x1e72('0x1d')](util[_0x1e72('0x18')](_0x1e72('0x1a'),_0x295e13[_0x1e72('0x19')],_0x295e13['id']),util[_0x1e72('0x1b')](parsedResult,{'showHidden':![],'depth':null}));return _0x5da6d1(_0x5215b6);});}else{return _0x5da6d1(null,_0x159896);}}}});};