3172f2f71947a2bff57eb8c3cf8256d8cba205e8
[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 _0x8765=['moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client','http','redis','defaults','socket.io-emitter','./plugin.socket','register','Plugin,\x20%s,\x20%s','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','stringify','error','message','info','result','catch','CreatePlugin','create','body','options','raw','then','lodash'];(function(_0x52dd90,_0x132712){var _0x2e16bb=function(_0x176552){while(--_0x176552){_0x52dd90['push'](_0x52dd90['shift']());}};_0x2e16bb(++_0x132712);}(_0x8765,0x128));var _0x5876=function(_0x209941,_0x5c9988){_0x209941=_0x209941-0x0;var _0x1e8729=_0x8765[_0x209941];return _0x1e8729;};'use strict';var _=require(_0x5876('0x0'));var util=require('util');var moment=require(_0x5876('0x1'));var BPromise=require(_0x5876('0x2'));var rs=require(_0x5876('0x3'));var fs=require('fs');var Redis=require(_0x5876('0x4'));var db=require(_0x5876('0x5'))['db'];var utils=require(_0x5876('0x6'));var logger=require(_0x5876('0x7'))('rpc');var config=require(_0x5876('0x8'));var jayson=require(_0x5876('0x9'));var client=jayson[_0x5876('0xa')][_0x5876('0xb')]({'port':0x232a});config[_0x5876('0xc')]=_[_0x5876('0xd')](config[_0x5876('0xc')],{'host':'localhost','port':0x18eb});var socket=require(_0x5876('0xe'))(new Redis(config['redis']));require(_0x5876('0xf'))[_0x5876('0x10')](socket);function respondWithRpcPromise(_0x3a4458,_0x2c28d7,_0x169ee7){return new BPromise(function(_0x7e90b3,_0x1308f4){return client['request'](_0x3a4458,_0x169ee7)['then'](function(_0x290d61){logger['info'](_0x5876('0x11'),_0x2c28d7,_0x5876('0x12'));logger[_0x5876('0x13')](_0x5876('0x14'),_0x2c28d7,_0x5876('0x12'),JSON[_0x5876('0x15')](_0x290d61));if(_0x290d61[_0x5876('0x16')]){if(_0x290d61[_0x5876('0x16')]['code']===0x1f4){logger['error'](_0x5876('0x11'),_0x2c28d7,_0x290d61[_0x5876('0x16')][_0x5876('0x17')]);return _0x1308f4(_0x290d61['error'][_0x5876('0x17')]);}logger['error'](_0x5876('0x11'),_0x2c28d7,_0x290d61[_0x5876('0x16')][_0x5876('0x17')]);return _0x7e90b3(_0x290d61[_0x5876('0x16')][_0x5876('0x17')]);}else{logger[_0x5876('0x18')](_0x5876('0x11'),_0x2c28d7,_0x5876('0x12'));_0x7e90b3(_0x290d61[_0x5876('0x19')][_0x5876('0x17')]);}})[_0x5876('0x1a')](function(_0x3f779a){logger[_0x5876('0x16')](_0x5876('0x11'),_0x2c28d7,_0x3f779a);_0x1308f4(_0x3f779a);});});}exports[_0x5876('0x1b')]=function(_0x58b25e){var _0xe826fb=this;return new Promise(function(_0x44989a,_0xa581be){return db['Plugin'][_0x5876('0x1c')](_0x58b25e[_0x5876('0x1d')],{'raw':_0x58b25e[_0x5876('0x1e')]?_0x58b25e[_0x5876('0x1e')][_0x5876('0x1f')]===undefined?!![]:![]:!![]})[_0x5876('0x20')](function(_0x2d9e37){logger[_0x5876('0x18')](_0x5876('0x1b'),_0x58b25e);logger[_0x5876('0x13')](_0x5876('0x1b'),_0x58b25e,JSON[_0x5876('0x15')](_0x2d9e37));_0x44989a(_0x2d9e37);})['catch'](function(_0x532ea6){logger[_0x5876('0x16')](_0x5876('0x1b'),_0x532ea6[_0x5876('0x17')],_0x58b25e);_0xa581be(_0xe826fb['error'](0x1f4,_0x532ea6[_0x5876('0x17')]));});});};