6505a63f30693040f5ca3ecc45eb327c35faf217
[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 _0x0187=['message','CreatePlugin','Plugin','create','body','options','raw','stringify','lodash','util','moment','../../mysqldb','../../config/utils','../../config/logger','http','redis','defaults','localhost','./plugin.socket','request','then','info','Plugin,\x20%s,\x20%s','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','error','code'];(function(_0x5b561d,_0x422b7c){var _0x431060=function(_0x401409){while(--_0x401409){_0x5b561d['push'](_0x5b561d['shift']());}};_0x431060(++_0x422b7c);}(_0x0187,0x158));var _0x7018=function(_0x2dc343,_0xf015a2){_0x2dc343=_0x2dc343-0x0;var _0x51eac5=_0x0187[_0x2dc343];return _0x51eac5;};'use strict';var _=require(_0x7018('0x0'));var util=require(_0x7018('0x1'));var moment=require(_0x7018('0x2'));var BPromise=require('bluebird');var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x7018('0x3'))['db'];var utils=require(_0x7018('0x4'));var logger=require(_0x7018('0x5'))('rpc');var config=require('../../config/environment');var jayson=require('jayson/promise');var client=jayson['client'][_0x7018('0x6')]({'port':0x232a});config[_0x7018('0x7')]=_[_0x7018('0x8')](config[_0x7018('0x7')],{'host':_0x7018('0x9'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x7018('0x7')]));require(_0x7018('0xa'))['register'](socket);function respondWithRpcPromise(_0x1f9533,_0x35ff33,_0x26b3b6){return new BPromise(function(_0x42f6e0,_0xf8b506){return client[_0x7018('0xb')](_0x1f9533,_0x26b3b6)[_0x7018('0xc')](function(_0x100041){logger[_0x7018('0xd')](_0x7018('0xe'),_0x35ff33,_0x7018('0xf'));logger[_0x7018('0x10')](_0x7018('0x11'),_0x35ff33,_0x7018('0xf'),JSON['stringify'](_0x100041));if(_0x100041[_0x7018('0x12')]){if(_0x100041['error'][_0x7018('0x13')]===0x1f4){logger[_0x7018('0x12')](_0x7018('0xe'),_0x35ff33,_0x100041[_0x7018('0x12')][_0x7018('0x14')]);return _0xf8b506(_0x100041[_0x7018('0x12')][_0x7018('0x14')]);}logger['error'](_0x7018('0xe'),_0x35ff33,_0x100041[_0x7018('0x12')][_0x7018('0x14')]);return _0x42f6e0(_0x100041[_0x7018('0x12')]['message']);}else{logger[_0x7018('0xd')](_0x7018('0xe'),_0x35ff33,_0x7018('0xf'));_0x42f6e0(_0x100041['result'][_0x7018('0x14')]);}})['catch'](function(_0x5843f1){logger[_0x7018('0x12')]('Plugin,\x20%s,\x20%s',_0x35ff33,_0x5843f1);_0xf8b506(_0x5843f1);});});}exports[_0x7018('0x15')]=function(_0x45b118){var _0x258b28=this;return new Promise(function(_0x1edc59,_0x3699bd){return db[_0x7018('0x16')][_0x7018('0x17')](_0x45b118[_0x7018('0x18')],{'raw':_0x45b118['options']?_0x45b118[_0x7018('0x19')][_0x7018('0x1a')]===undefined?!![]:![]:!![]})['then'](function(_0x16dd7c){logger[_0x7018('0xd')]('CreatePlugin',_0x45b118);logger[_0x7018('0x10')](_0x7018('0x15'),_0x45b118,JSON[_0x7018('0x1b')](_0x16dd7c));_0x1edc59(_0x16dd7c);})['catch'](function(_0x420037){logger[_0x7018('0x12')]('CreatePlugin',_0x420037['message'],_0x45b118);_0x3699bd(_0x258b28[_0x7018('0x12')](0x1f4,_0x420037[_0x7018('0x14')]));});});};