7d5780d599307eef03e45e6534bf878f1bbe2118
[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 _0xbf0c=['redis','socket.io-emitter','./plugin.socket','request','then','info','Plugin,\x20%s,\x20%s','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','stringify','error','message','catch','CreatePlugin','create','body','options','raw','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','../../config/environment','jayson/promise','client'];(function(_0x211687,_0x43a38b){var _0x1bb9e8=function(_0x2cd6b8){while(--_0x2cd6b8){_0x211687['push'](_0x211687['shift']());}};_0x1bb9e8(++_0x43a38b);}(_0xbf0c,0xae));var _0xcbf0=function(_0x38ff1e,_0x3b9385){_0x38ff1e=_0x38ff1e-0x0;var _0x3755d4=_0xbf0c[_0x38ff1e];return _0x3755d4;};'use strict';var _=require(_0xcbf0('0x0'));var util=require(_0xcbf0('0x1'));var moment=require(_0xcbf0('0x2'));var BPromise=require(_0xcbf0('0x3'));var rs=require(_0xcbf0('0x4'));var fs=require('fs');var Redis=require(_0xcbf0('0x5'));var db=require(_0xcbf0('0x6'))['db'];var utils=require(_0xcbf0('0x7'));var logger=require(_0xcbf0('0x8'))('rpc');var config=require(_0xcbf0('0x9'));var jayson=require(_0xcbf0('0xa'));var client=jayson[_0xcbf0('0xb')]['http']({'port':0x232a});config['redis']=_['defaults'](config[_0xcbf0('0xc')],{'host':'localhost','port':0x18eb});var socket=require(_0xcbf0('0xd'))(new Redis(config['redis']));require(_0xcbf0('0xe'))['register'](socket);function respondWithRpcPromise(_0x4fef11,_0x5314c3,_0x3b99e6){return new BPromise(function(_0x59f920,_0x45946e){return client[_0xcbf0('0xf')](_0x4fef11,_0x3b99e6)[_0xcbf0('0x10')](function(_0x1d2cdd){logger[_0xcbf0('0x11')](_0xcbf0('0x12'),_0x5314c3,_0xcbf0('0x13'));logger[_0xcbf0('0x14')](_0xcbf0('0x15'),_0x5314c3,_0xcbf0('0x13'),JSON[_0xcbf0('0x16')](_0x1d2cdd));if(_0x1d2cdd[_0xcbf0('0x17')]){if(_0x1d2cdd[_0xcbf0('0x17')]['code']===0x1f4){logger[_0xcbf0('0x17')](_0xcbf0('0x12'),_0x5314c3,_0x1d2cdd['error'][_0xcbf0('0x18')]);return _0x45946e(_0x1d2cdd[_0xcbf0('0x17')][_0xcbf0('0x18')]);}logger[_0xcbf0('0x17')](_0xcbf0('0x12'),_0x5314c3,_0x1d2cdd[_0xcbf0('0x17')][_0xcbf0('0x18')]);return _0x59f920(_0x1d2cdd[_0xcbf0('0x17')][_0xcbf0('0x18')]);}else{logger['info'](_0xcbf0('0x12'),_0x5314c3,'request\x20sent');_0x59f920(_0x1d2cdd['result'][_0xcbf0('0x18')]);}})[_0xcbf0('0x19')](function(_0x234cd6){logger[_0xcbf0('0x17')](_0xcbf0('0x12'),_0x5314c3,_0x234cd6);_0x45946e(_0x234cd6);});});}exports[_0xcbf0('0x1a')]=function(_0x53f4af){var _0x5b5990=this;return new Promise(function(_0x1dd7e0,_0xd96cef){return db['Plugin'][_0xcbf0('0x1b')](_0x53f4af[_0xcbf0('0x1c')],{'raw':_0x53f4af['options']?_0x53f4af[_0xcbf0('0x1d')][_0xcbf0('0x1e')]===undefined?!![]:![]:!![]})[_0xcbf0('0x10')](function(_0xaa1906){logger[_0xcbf0('0x11')]('CreatePlugin',_0x53f4af);logger[_0xcbf0('0x14')]('CreatePlugin',_0x53f4af,JSON['stringify'](_0xaa1906));_0x1dd7e0(_0xaa1906);})[_0xcbf0('0x19')](function(_0x121362){logger[_0xcbf0('0x17')](_0xcbf0('0x1a'),_0x121362[_0xcbf0('0x18')],_0x53f4af);_0xd96cef(_0x5b5990['error'](0x1f4,_0x121362[_0xcbf0('0x18')]));});});};