Built motion from commit (unavailable).|2.4.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 _0x4152=['POST','/oauth/v2/token','application/x-www-form-urlencoded','lodash','util','../../config/logger','api','moment','bluebird','request-promise','../../config/environment','./intZohoAccount.attributes','../../components/integrations/configuration','define','int_zoho_accounts','changed','zone','serverUrl','clientId','clientSecret','code','host','slice','https://accounts.zoho.com','https://accounts.zoho.in','https://accounts.zoho.com.cn','authorization_code','then','parse','refresh_token','refreshToken','info','format','ZohoAccount,\x20Refresh\x20token\x20successfully\x20generated\x20for\x20account\x20\x22%s\x22\x20#%d','error','ZohoAccount,\x20Unable\x20to\x20generate\x20the\x20refresh\x20token\x20for\x20account\x20\x22%s\x22\x20#%d','inspect','catch','name','substring','lastIndexOf','https://accounts.zoho.eu'];(function(_0x538522,_0x5b83c3){var _0x1842ae=function(_0x2f7109){while(--_0x2f7109){_0x538522['push'](_0x538522['shift']());}};_0x1842ae(++_0x5b83c3);}(_0x4152,0xff));var _0x2415=function(_0xb7b878,_0x5c3b92){_0xb7b878=_0xb7b878-0x0;var _0x3c84b9=_0x4152[_0xb7b878];return _0x3c84b9;};'use strict';var _=require(_0x2415('0x0'));var util=require(_0x2415('0x1'));var logger=require(_0x2415('0x2'))(_0x2415('0x3'));var moment=require(_0x2415('0x4'));var BPromise=require(_0x2415('0x5'));var rp=require(_0x2415('0x6'));var fs=require('fs');var path=require('path');var rimraf=require('rimraf');var config=require(_0x2415('0x7'));var attributes=require(_0x2415('0x8'));var integrations=require(_0x2415('0x9'));module['exports']=function(_0x1412f0,_0x2ad822){return _0x1412f0[_0x2415('0xa')]('ZohoAccount',attributes,{'tableName':_0x2415('0xb'),'paranoid':![],'indexes':[],'timestamps':!![],'hooks':{'beforeCreate':function(_0x46f4f2,_0x2e1189,_0x345aea){if(_0x46f4f2[_0x2415('0xc')](_0x2415('0xd'))||_0x46f4f2[_0x2415('0xc')](_0x2415('0xe'))||_0x46f4f2['changed'](_0x2415('0xf'))||_0x46f4f2[_0x2415('0xc')](_0x2415('0x10'))||_0x46f4f2[_0x2415('0xc')](_0x2415('0x11'))||_0x46f4f2[_0x2415('0xc')](_0x2415('0x12'))){var _0x10865d,_0x1e99de;_0x10865d=_0x46f4f2[_0x2415('0xe')];var _0x50a95d=_0x10865d[_0x2415('0x13')](-0x1);if(_0x50a95d==='/'||_0x50a95d==='\x5c'||_0x50a95d===':'){_0x10865d=_0x10865d['substring'](0x0,_0x10865d['lastIndexOf'](_0x50a95d));}switch(_0x46f4f2[_0x2415('0xd')]){case'US':_0x1e99de=_0x2415('0x14');break;case'AU':_0x1e99de='https://accounts.zoho.com.au';break;case'IN':_0x1e99de=_0x2415('0x15');break;case'CN':_0x1e99de=_0x2415('0x16');break;default:_0x1e99de='https://accounts.zoho.eu';break;}var _0xd5c73={'method':'POST','uri':_0x1e99de+'/oauth/v2/token','form':{'grant_type':_0x2415('0x17'),'client_id':_0x46f4f2[_0x2415('0xf')],'client_secret':_0x46f4f2[_0x2415('0x10')],'redirect_uri':_0x46f4f2[_0x2415('0xe')],'code':_0x46f4f2[_0x2415('0x11')]},'headers':{'Content-Type':'application/x-www-form-urlencoded'}};return rp(_0xd5c73)[_0x2415('0x18')](function(_0x48c0d1){var _0x556b12=JSON[_0x2415('0x19')](_0x48c0d1);if(_0x556b12[_0x2415('0x1a')]){_0x46f4f2[_0x2415('0x1b')]=_0x556b12['refresh_token'];logger[_0x2415('0x1c')](util[_0x2415('0x1d')](_0x2415('0x1e'),_0x46f4f2['name'],_0x46f4f2['id']));}else{logger[_0x2415('0x1f')](util[_0x2415('0x1d')](_0x2415('0x20'),_0x46f4f2['name'],_0x46f4f2['id']),util[_0x2415('0x21')](_0x556b12,{'showHidden':![],'depth':null}));}return _0x345aea(null,_0x2e1189);})[_0x2415('0x22')](function(_0xe5921){logger[_0x2415('0x1f')](util[_0x2415('0x1d')](_0x2415('0x20'),_0x46f4f2[_0x2415('0x23')],_0x46f4f2['id']),util[_0x2415('0x21')](parsedResult,{'showHidden':![],'depth':null}));return _0x345aea(_0xe5921);});}else{return _0x345aea(null,_0x2e1189);}},'beforeUpdate':function(_0x32d78f,_0xe27ac5,_0x502d39){if(_0x32d78f['changed'](_0x2415('0xd'))||_0x32d78f[_0x2415('0xc')]('serverUrl')||_0x32d78f[_0x2415('0xc')](_0x2415('0xf'))||_0x32d78f[_0x2415('0xc')]('clientSecret')||_0x32d78f['changed'](_0x2415('0x11'))||_0x32d78f[_0x2415('0xc')](_0x2415('0x12'))){var _0x586796,_0x5f2f4e;_0x586796=_0x32d78f[_0x2415('0xe')];var _0x46114c=_0x586796[_0x2415('0x13')](-0x1);if(_0x46114c==='/'||_0x46114c==='\x5c'||_0x46114c===':'){_0x586796=_0x586796[_0x2415('0x24')](0x0,_0x586796[_0x2415('0x25')](_0x46114c));}switch(_0x32d78f[_0x2415('0xd')]){case'US':_0x5f2f4e='https://accounts.zoho.com';break;case'AU':_0x5f2f4e='https://accounts.zoho.com.au';break;case'IN':_0x5f2f4e=_0x2415('0x15');break;case'CN':_0x5f2f4e=_0x2415('0x16');break;default:_0x5f2f4e=_0x2415('0x26');break;}var _0x31a78a={'method':_0x2415('0x27'),'uri':_0x5f2f4e+_0x2415('0x28'),'form':{'grant_type':_0x2415('0x17'),'client_id':_0x32d78f[_0x2415('0xf')],'client_secret':_0x32d78f['clientSecret'],'redirect_uri':_0x32d78f[_0x2415('0xe')],'code':_0x32d78f[_0x2415('0x11')]},'headers':{'Content-Type':_0x2415('0x29')}};return rp(_0x31a78a)[_0x2415('0x18')](function(_0x6a3be){var _0x10b0cf=JSON[_0x2415('0x19')](_0x6a3be);if(_0x10b0cf[_0x2415('0x1a')]){_0x32d78f[_0x2415('0x1b')]=_0x10b0cf[_0x2415('0x1a')];logger[_0x2415('0x1c')](util[_0x2415('0x1d')](_0x2415('0x1e'),_0x32d78f[_0x2415('0x23')],_0x32d78f['id']));}else{logger[_0x2415('0x1f')](util[_0x2415('0x1d')](_0x2415('0x20'),_0x32d78f[_0x2415('0x23')],_0x32d78f['id']),util[_0x2415('0x21')](_0x10b0cf,{'showHidden':![],'depth':null}));}return _0x502d39(null,_0xe27ac5);})[_0x2415('0x22')](function(_0x45a079){logger['error'](util[_0x2415('0x1d')](_0x2415('0x20'),_0x32d78f[_0x2415('0x23')],_0x32d78f['id']),util['inspect'](parsedResult,{'showHidden':![],'depth':null}));return _0x502d39(_0x45a079);});}else{return _0x502d39(null,_0xe27ac5);}}}});};