aab1a9b33aed3bf755cb5601306170712aa1743f
[motion2.git] / server / api / plugin / plugin.rpc.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 _0x010e=['../../config/utils','rpc','jayson/promise','http','defaults','redis','socket.io-emitter','register','request','then','info','Plugin,\x20%s,\x20%s','request\x20sent','Plugin,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','Plugin','create','body','raw','CreatePlugin','debug','catch','util','moment','bluebird','randomstring','ioredis','../../mysqldb'];(function(_0x8dd85f,_0x102a4c){var _0x5d55ee=function(_0x1463ab){while(--_0x1463ab){_0x8dd85f['push'](_0x8dd85f['shift']());}};_0x5d55ee(++_0x102a4c);}(_0x010e,0x1da));var _0xe010=function(_0x39cf45,_0x49f7d9){_0x39cf45=_0x39cf45-0x0;var _0x9d55a4=_0x010e[_0x39cf45];return _0x9d55a4;};'use strict';var _=require('lodash');var util=require(_0xe010('0x0'));var moment=require(_0xe010('0x1'));var BPromise=require(_0xe010('0x2'));var rs=require(_0xe010('0x3'));var fs=require('fs');var Redis=require(_0xe010('0x4'));var db=require(_0xe010('0x5'))['db'];var utils=require(_0xe010('0x6'));var logger=require('../../config/logger')(_0xe010('0x7'));var config=require('../../config/environment');var jayson=require(_0xe010('0x8'));var client=jayson['client'][_0xe010('0x9')]({'port':0x232a});config['redis']=_[_0xe010('0xa')](config[_0xe010('0xb')],{'host':'localhost','port':0x18eb});var socket=require(_0xe010('0xc'))(new Redis(config[_0xe010('0xb')]));require('./plugin.socket')[_0xe010('0xd')](socket);function respondWithRpcPromise(_0x55b90a,_0x2d2ffb,_0xcbf3b7){return new BPromise(function(_0xa0a4cd,_0x30058b){return client[_0xe010('0xe')](_0x55b90a,_0xcbf3b7)[_0xe010('0xf')](function(_0xa993b9){logger[_0xe010('0x10')](_0xe010('0x11'),_0x2d2ffb,_0xe010('0x12'));logger['debug'](_0xe010('0x13'),_0x2d2ffb,_0xe010('0x12'),JSON[_0xe010('0x14')](_0xa993b9));if(_0xa993b9[_0xe010('0x15')]){if(_0xa993b9['error'][_0xe010('0x16')]===0x1f4){logger[_0xe010('0x15')](_0xe010('0x11'),_0x2d2ffb,_0xa993b9[_0xe010('0x15')][_0xe010('0x17')]);return _0x30058b(_0xa993b9[_0xe010('0x15')][_0xe010('0x17')]);}logger[_0xe010('0x15')](_0xe010('0x11'),_0x2d2ffb,_0xa993b9['error'][_0xe010('0x17')]);return _0xa0a4cd(_0xa993b9[_0xe010('0x15')]['message']);}else{logger['info'](_0xe010('0x11'),_0x2d2ffb,_0xe010('0x12'));_0xa0a4cd(_0xa993b9[_0xe010('0x18')][_0xe010('0x17')]);}})['catch'](function(_0xe6d240){logger[_0xe010('0x15')]('Plugin,\x20%s,\x20%s',_0x2d2ffb,_0xe6d240);_0x30058b(_0xe6d240);});});}exports['CreatePlugin']=function(_0x21b9c8){var _0x4872d1=this;return new Promise(function(_0x188c61,_0x57c2ef){return db[_0xe010('0x19')][_0xe010('0x1a')](_0x21b9c8[_0xe010('0x1b')],{'raw':_0x21b9c8['options']?_0x21b9c8['options'][_0xe010('0x1c')]===undefined?!![]:![]:!![]})[_0xe010('0xf')](function(_0x4691b3){logger[_0xe010('0x10')](_0xe010('0x1d'),_0x21b9c8);logger[_0xe010('0x1e')](_0xe010('0x1d'),_0x21b9c8,JSON[_0xe010('0x14')](_0x4691b3));_0x188c61(_0x4691b3);})[_0xe010('0x1f')](function(_0xb4fd9f){logger[_0xe010('0x15')](_0xe010('0x1d'),_0xb4fd9f[_0xe010('0x17')],_0x21b9c8);_0x57c2ef(_0x4872d1[_0xe010('0x15')](0x1f4,_0xb4fd9f[_0xe010('0x17')]));});});};