4a2ff2b6bc5bcf7c499b144b3f16dd70578b869e
[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 _0x1018=['redis','localhost','socket.io-emitter','./plugin.socket','register','request','then','info','Plugin,\x20%s,\x20%s','request\x20sent','debug','Plugin,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','Plugin','create','body','options','raw','CreatePlugin','lodash','util','moment','bluebird','randomstring','ioredis','../../mysqldb','../../config/utils','../../config/logger','rpc','jayson/promise','client','http','defaults'];(function(_0x5bb4e8,_0x44b756){var _0x2a86f2=function(_0x279ab2){while(--_0x279ab2){_0x5bb4e8['push'](_0x5bb4e8['shift']());}};_0x2a86f2(++_0x44b756);}(_0x1018,0x148));var _0x8101=function(_0x2d7f6f,_0x4e7bd6){_0x2d7f6f=_0x2d7f6f-0x0;var _0x1079d5=_0x1018[_0x2d7f6f];return _0x1079d5;};'use strict';var _=require(_0x8101('0x0'));var util=require(_0x8101('0x1'));var moment=require(_0x8101('0x2'));var BPromise=require(_0x8101('0x3'));var rs=require(_0x8101('0x4'));var fs=require('fs');var Redis=require(_0x8101('0x5'));var db=require(_0x8101('0x6'))['db'];var utils=require(_0x8101('0x7'));var logger=require(_0x8101('0x8'))(_0x8101('0x9'));var config=require('../../config/environment');var jayson=require(_0x8101('0xa'));var client=jayson[_0x8101('0xb')][_0x8101('0xc')]({'port':0x232a});config['redis']=_[_0x8101('0xd')](config[_0x8101('0xe')],{'host':_0x8101('0xf'),'port':0x18eb});var socket=require(_0x8101('0x10'))(new Redis(config[_0x8101('0xe')]));require(_0x8101('0x11'))[_0x8101('0x12')](socket);function respondWithRpcPromise(_0x47c065,_0x38ed4d,_0x3640b4){return new BPromise(function(_0x503845,_0xaa7b0c){return client[_0x8101('0x13')](_0x47c065,_0x3640b4)[_0x8101('0x14')](function(_0x1df1ec){logger[_0x8101('0x15')](_0x8101('0x16'),_0x38ed4d,_0x8101('0x17'));logger[_0x8101('0x18')](_0x8101('0x19'),_0x38ed4d,_0x8101('0x17'),JSON[_0x8101('0x1a')](_0x1df1ec));if(_0x1df1ec[_0x8101('0x1b')]){if(_0x1df1ec['error'][_0x8101('0x1c')]===0x1f4){logger[_0x8101('0x1b')]('Plugin,\x20%s,\x20%s',_0x38ed4d,_0x1df1ec[_0x8101('0x1b')][_0x8101('0x1d')]);return _0xaa7b0c(_0x1df1ec['error'][_0x8101('0x1d')]);}logger[_0x8101('0x1b')](_0x8101('0x16'),_0x38ed4d,_0x1df1ec['error']['message']);return _0x503845(_0x1df1ec['error'][_0x8101('0x1d')]);}else{logger[_0x8101('0x15')]('Plugin,\x20%s,\x20%s',_0x38ed4d,_0x8101('0x17'));_0x503845(_0x1df1ec[_0x8101('0x1e')][_0x8101('0x1d')]);}})[_0x8101('0x1f')](function(_0x5bc437){logger['error']('Plugin,\x20%s,\x20%s',_0x38ed4d,_0x5bc437);_0xaa7b0c(_0x5bc437);});});}exports['CreatePlugin']=function(_0x2be96f){var _0x53879e=this;return new Promise(function(_0x5d8e41,_0x38d516){return db[_0x8101('0x20')][_0x8101('0x21')](_0x2be96f[_0x8101('0x22')],{'raw':_0x2be96f[_0x8101('0x23')]?_0x2be96f[_0x8101('0x23')][_0x8101('0x24')]===undefined?!![]:![]:!![]})[_0x8101('0x14')](function(_0x4f5a72){logger[_0x8101('0x15')](_0x8101('0x25'),_0x2be96f);logger[_0x8101('0x18')](_0x8101('0x25'),_0x2be96f,JSON[_0x8101('0x1a')](_0x4f5a72));_0x5d8e41(_0x4f5a72);})['catch'](function(_0x2331b7){logger['error']('CreatePlugin',_0x2331b7[_0x8101('0x1d')],_0x2be96f);_0x38d516(_0x53879e[_0x8101('0x1b')](0x1f4,_0x2331b7[_0x8101('0x1d')]));});});};