88b3da63fe9fb72a5e9543179d073476a082d226
[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 _0xee4f=['bluebird','randomstring','ioredis','../../config/utils','rpc','client','defaults','redis','localhost','./plugin.socket','register','request','info','Plugin,\x20%s,\x20%s','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','error','message','result','catch','CreatePlugin','Plugin','create','body','options','then','stringify','lodash'];(function(_0x451a69,_0x17a8da){var _0x418d46=function(_0x573663){while(--_0x573663){_0x451a69['push'](_0x451a69['shift']());}};_0x418d46(++_0x17a8da);}(_0xee4f,0xad));var _0xfee4=function(_0x1a90a4,_0x407549){_0x1a90a4=_0x1a90a4-0x0;var _0x5803c2=_0xee4f[_0x1a90a4];return _0x5803c2;};'use strict';var _=require(_0xfee4('0x0'));var util=require('util');var moment=require('moment');var BPromise=require(_0xfee4('0x1'));var rs=require(_0xfee4('0x2'));var fs=require('fs');var Redis=require(_0xfee4('0x3'));var db=require('../../mysqldb')['db'];var utils=require(_0xfee4('0x4'));var logger=require('../../config/logger')(_0xfee4('0x5'));var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson[_0xfee4('0x6')]['http']({'port':0x232a});config['redis']=_[_0xfee4('0x7')](config[_0xfee4('0x8')],{'host':_0xfee4('0x9'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0xfee4('0xa'))[_0xfee4('0xb')](socket);function respondWithRpcPromise(_0xa77876,_0x4dc812,_0x53f260){return new BPromise(function(_0x2ca5f9,_0x1d6855){return client[_0xfee4('0xc')](_0xa77876,_0x53f260)['then'](function(_0x2ef3c3){logger[_0xfee4('0xd')](_0xfee4('0xe'),_0x4dc812,_0xfee4('0xf'));logger[_0xfee4('0x10')](_0xfee4('0x11'),_0x4dc812,_0xfee4('0xf'),JSON['stringify'](_0x2ef3c3));if(_0x2ef3c3[_0xfee4('0x12')]){if(_0x2ef3c3[_0xfee4('0x12')]['code']===0x1f4){logger[_0xfee4('0x12')](_0xfee4('0xe'),_0x4dc812,_0x2ef3c3[_0xfee4('0x12')][_0xfee4('0x13')]);return _0x1d6855(_0x2ef3c3[_0xfee4('0x12')][_0xfee4('0x13')]);}logger[_0xfee4('0x12')]('Plugin,\x20%s,\x20%s',_0x4dc812,_0x2ef3c3[_0xfee4('0x12')][_0xfee4('0x13')]);return _0x2ca5f9(_0x2ef3c3[_0xfee4('0x12')]['message']);}else{logger[_0xfee4('0xd')]('Plugin,\x20%s,\x20%s',_0x4dc812,'request\x20sent');_0x2ca5f9(_0x2ef3c3[_0xfee4('0x14')][_0xfee4('0x13')]);}})[_0xfee4('0x15')](function(_0x44a1ec){logger[_0xfee4('0x12')](_0xfee4('0xe'),_0x4dc812,_0x44a1ec);_0x1d6855(_0x44a1ec);});});}exports[_0xfee4('0x16')]=function(_0x22766){var _0x153649=this;return new Promise(function(_0x5826da,_0x194cd8){return db[_0xfee4('0x17')][_0xfee4('0x18')](_0x22766[_0xfee4('0x19')],{'raw':_0x22766[_0xfee4('0x1a')]?_0x22766[_0xfee4('0x1a')]['raw']===undefined?!![]:![]:!![]})[_0xfee4('0x1b')](function(_0xd97878){logger[_0xfee4('0xd')](_0xfee4('0x16'),_0x22766);logger[_0xfee4('0x10')](_0xfee4('0x16'),_0x22766,JSON[_0xfee4('0x1c')](_0xd97878));_0x5826da(_0xd97878);})[_0xfee4('0x15')](function(_0x3ac09a){logger[_0xfee4('0x12')]('CreatePlugin',_0x3ac09a['message'],_0x22766);_0x194cd8(_0x153649['error'](0x1f4,_0x3ac09a['message']));});});};