New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bettercorp/service-base-plugin-events-rabbitmq

Package Overview
Dependencies
Maintainers
2
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bettercorp/service-base-plugin-events-rabbitmq - npm Package Compare versions

Comparing version 1.0.20210611131248 to 1.1.20210701165917

lib/test-client.d.ts

8

lib/plugins/events-rabbitmq/plugin.d.ts

@@ -1,3 +0,3 @@

import { IEvents, PluginFeature } from '@bettercorp/service-base/lib/ILib';
export declare class Events implements IEvents {
import { CEvents } from '@bettercorp/service-base/lib/ILib';
export declare class Events extends CEvents {
private rabbitQConnection;

@@ -10,4 +10,2 @@ private rabbitQConnectionEmitChannel;

private builtInEvents;
private features;
private logger;
private readonly emitExchange;

@@ -17,3 +15,3 @@ private readonly earExchange;

private readonly earExchangeQueue;
init(features: PluginFeature): Promise<void>;
init(): Promise<void>;
private _connectToAMQP;

@@ -20,0 +18,0 @@ private _emitEvent;

@@ -14,2 +14,3 @@ "use strict";

const amqplib = require("amqplib");
const ILib_1 = require("@bettercorp/service-base/lib/ILib");
const uuid_1 = require("uuid");

@@ -19,4 +20,5 @@ const Tools_1 = require("@bettercorp/tools/lib/Tools");

const OS = require("os");
class Events {
class Events extends ILib_1.CEvents {
constructor() {
super(...arguments);
this.rabbitQConnectionEmitChannelKey = "eq";

@@ -46,6 +48,4 @@ this.rabbitQConnectionEARChannelKey = "ar";

}
init(features) {
init() {
const self = this;
self.features = features;
self.logger = features.log;
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {

@@ -57,3 +57,3 @@ try {

catch (exce) {
features.log.error(exce);
self.log.fatal(exce);
reject(exce);

@@ -65,8 +65,8 @@ }

return __awaiter(this, void 0, void 0, function* () {
this.features.log.info(`Connect to ${this.features.getPluginConfig().endpoint}`);
if (Tools_1.Tools.isNullOrUndefined(this.features.getPluginConfig().credentials)) {
this.log.info(`Connect to ${this.getPluginConfig().endpoint}`);
if (Tools_1.Tools.isNullOrUndefined(this.getPluginConfig().credentials)) {
throw new Error('Plugin credentials not defined in sec.config.json');
}
this.rabbitQConnection = yield amqplib.connect(this.features.getPluginConfig().endpoint, {
credentials: amqplib.credentials.plain(this.features.getPluginConfig().credentials.username, this.features.getPluginConfig().credentials.password)
this.rabbitQConnection = yield amqplib.connect(this.getPluginConfig().endpoint, {
credentials: amqplib.credentials.plain(this.getPluginConfig().credentials.username, this.getPluginConfig().credentials.password)
});

@@ -76,10 +76,10 @@ const self = this;

if (err.message !== "Connection closing") {
self.features.log.error('AMQP ERROR', err.message);
self.log.error('AMQP ERROR', err.message);
}
});
this.rabbitQConnection.on("close", () => {
self.features.log.error('AMQP CONNECTION CLOSED');
throw 'AMQP Error: Connection closed';
self.log.error('AMQP CONNECTION CLOSED');
self.log.fatal('AMQP Error: Connection closed');
});
this.features.log.info(`Connected to ${this.features.getPluginConfig().endpoint}`);
this.log.info(`Connected to ${this.getPluginConfig().endpoint}`);
yield this._setupEmitHandler();

@@ -91,3 +91,3 @@ yield this._setupEARHandler();

const self = this;
self.features.log.debug(plugin, ` - EMIT: [${queueKey}-${pluginName || plugin}-${event}]`, data);
self.log.debug(plugin, ` - EMIT: [${queueKey}-${pluginName || plugin}-${event}]`, data);
let qArguments = undefined;

@@ -107,3 +107,3 @@ if (!Tools_1.Tools.isNullOrUndefined(additionalArgs)) {

channel.sendToQueue(`${queueKey}-${pluginName || plugin}-${event}`, Buffer.from(JSON.stringify(data)));
self.features.log.debug(plugin, ` - EMIT: [${queueKey}-${pluginName || plugin}-${event}] - EMITTED`, data);
self.log.debug(plugin, ` - EMIT: [${queueKey}-${pluginName || plugin}-${event}] - EMITTED`, data);
});

@@ -113,8 +113,8 @@ }

return __awaiter(this, void 0, void 0, function* () {
this.features.log.info(`Open emit channel (${this.emitExchange.name})`);
this.log.info(`Open emit channel (${this.emitExchange.name})`);
this.rabbitQConnectionEmitChannel = yield this.rabbitQConnection.createChannel();
this.rabbitQConnectionEmitChannel.assertExchange(this.emitExchange.name, this.emitExchange.type, this.emitExchangeQueue);
this.features.log.info(`Open emit channel (${this.emitExchange.name}) - PREFETCH x${this.features.getPluginConfig().prefetch}`);
this.rabbitQConnectionEmitChannel.prefetch(this.features.getPluginConfig().prefetch);
this.features.log.info(`Open emit channel (${this.emitExchange.name}) - COMPLETED`);
this.log.info(`Open emit channel (${this.emitExchange.name}) - PREFETCH x${this.getPluginConfig().prefetch}`);
this.rabbitQConnectionEmitChannel.prefetch(this.getPluginConfig().prefetch);
this.log.info(`Open emit channel (${this.emitExchange.name}) - COMPLETED`);
});

@@ -124,6 +124,6 @@ }

const self = this;
self.features.log.info(plugin, ` - LISTEN: [${self.rabbitQConnectionEmitChannelKey}-${pluginName || plugin}-${event}]`);
self.log.info(plugin, ` - LISTEN: [${self.rabbitQConnectionEmitChannelKey}-${pluginName || plugin}-${event}]`);
let ok = self.rabbitQConnectionEmitChannel.assertQueue(`${self.rabbitQConnectionEmitChannelKey}-${pluginName || plugin}-${event}`, self.emitExchangeQueue);
ok = ok.then(function () {
self.features.log.info(plugin, ` - LISTEN: [${`${self.rabbitQConnectionEmitChannelKey}-${pluginName || plugin}-${event}`}] - LISTENING`);
self.log.info(plugin, ` - LISTEN: [${`${self.rabbitQConnectionEmitChannelKey}-${pluginName || plugin}-${event}`}] - LISTENING`);
});

@@ -145,20 +145,20 @@ //ok = ok.then(function () { channel.prefetch(1); });

return __awaiter(this, void 0, void 0, function* () {
this.features.log.info(`Ready my events name`);
this.earExchange.myResponseName = `${this.features.cwd}`.replace(/[\W-]/g, '').toLowerCase() +
((this.features.getPluginConfig().noRandomDebugName === true ? '' : this.features.config.debug ? `-${Math.random()}` : '')) +
(this.features.getPluginConfig().uniqueId || '');
this.features.log.info(`Ready my events name - ${this.earExchange.myResponseName}`);
this.features.log.info(`Ready internal events`);
this.log.info(`Ready my events name`);
this.earExchange.myResponseName = `${this.cwd}`.replace(/[\W-]/g, '').toLowerCase() +
((this.getPluginConfig().noRandomDebugName === true ? '' : this.appConfig.runningInDebug || !this.appConfig.runningLive ? `-${Math.random()}` : '')) +
(this.getPluginConfig().uniqueId || '');
this.log.info(`Ready my events name - ${this.earExchange.myResponseName}`);
this.log.info(`Ready internal events`);
this.builtInEvents = new EVENT_EMITTER();
this.features.log.info(`Ready internal events - COMPLETED`);
this.features.log.info(`Open EAR channel (${this.earExchange.name})`);
this.log.info(`Ready internal events - COMPLETED`);
this.log.info(`Open EAR channel (${this.earExchange.name})`);
this.rabbitQConnectionEARChannel = yield this.rabbitQConnection.createChannel();
this.rabbitQConnectionEARChannel.assertExchange(this.earExchange.name, this.earExchange.type, this.earExchangeQueue);
this.features.log.info(`Open EAR channel (${this.earExchange.name}) - PREFETCH x${this.features.getPluginConfig().prefetchEAR}`);
this.rabbitQConnectionEARChannel.prefetch(this.features.getPluginConfig().prefetchEAR);
this.features.log.info(`Open EAR channel (${this.earExchange.name}) - ${this.earExchange.myResponseName} - LISTEN`);
this.log.info(`Open EAR channel (${this.earExchange.name}) - PREFETCH x${this.getPluginConfig().prefetchEAR}`);
this.rabbitQConnectionEARChannel.prefetch(this.getPluginConfig().prefetchEAR);
this.log.info(`Open EAR channel (${this.earExchange.name}) - ${this.earExchange.myResponseName} - LISTEN`);
let eventEARQueue = this.rabbitQConnectionEARChannel.assertQueue(`${this.rabbitQConnectionEARChannelKeyMine}-${OS.hostname()}-${this.earExchange.myResponseName}`, this.earExchangeQueue);
const self = this;
eventEARQueue = eventEARQueue.then(function () {
self.features.log.info(` - LISTEN: [${self.earExchange.myResponseName}] - LISTENING`);
self.log.info(` - LISTEN: [${self.earExchange.myResponseName}] - LISTENING`);
});

@@ -169,3 +169,3 @@ eventEARQueue = eventEARQueue.then(function () {

self.rabbitQConnectionEARChannel.ack(msg);
self.features.log.debug(`[RECEVIED ${self.earExchange.myResponseName}]:`, body);
self.log.debug(`[RECEVIED ${self.earExchange.myResponseName}]:`, body);
const bodyObj = JSON.parse(body);

@@ -175,3 +175,3 @@ self.builtInEvents.emit(bodyObj.id, bodyObj);

});
this.features.log.info(`Open EAR channel (${this.earExchange.name}) - COMPLETED`);
this.log.info(`Open EAR channel (${this.earExchange.name}) - COMPLETED`);
});

@@ -181,6 +181,6 @@ }

const self = this;
self.features.log.info(plugin, ` - LISTEN EAR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}]`);
self.log.info(plugin, ` - LISTEN EAR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}]`);
let ok = self.rabbitQConnectionEARChannel.assertQueue(`${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}`, self.earExchangeQueue);
ok = ok.then(function () {
self.features.log.info(plugin, ` - LISTEN EAR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}] - LISTENING`);
self.log.info(plugin, ` - LISTEN EAR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}] - LISTENING`);
});

@@ -194,3 +194,3 @@ //ok = ok.then(function () { channel.prefetch(1); });

self.rabbitQConnectionEARChannel.ack(msg);
self.logger.debug(plugin, ` - RETURN OKAY: [${self.rabbitQConnectionEARChannelKeyMine}-${pluginName || plugin}-${event}]`, bodyObj);
self.log.debug(plugin, ` - RETURN OKAY: [${self.rabbitQConnectionEARChannelKeyMine}-${pluginName || plugin}-${event}]`, bodyObj);
self._emitEvent(self.rabbitQConnectionEARChannelKeyMine, self.earExchangeQueue, plugin, bodyObj.plugin, bodyObj.topic, self.rabbitQConnectionEARChannel, {

@@ -203,3 +203,3 @@ data: x,

self.rabbitQConnectionEARChannel.ack(msg);
self.logger.debug(plugin, ` - RETURN ERROR: [${self.rabbitQConnectionEARChannelKeyMine}-${pluginName || plugin}-${event}]`, bodyObj);
self.log.debug(plugin, ` - RETURN ERROR: [${self.rabbitQConnectionEARChannelKeyMine}-${pluginName || plugin}-${event}]`, bodyObj);
self._emitEvent(self.rabbitQConnectionEARChannelKeyMine, self.earExchangeQueue, plugin, bodyObj.plugin, bodyObj.topic, self.rabbitQConnectionEARChannel, {

@@ -216,3 +216,3 @@ data: x,

const self = this;
this.logger.debug(plugin, ` - EMIT EAR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}]`, data);
this.log.debug(plugin, ` - EMIT EAR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}]`, data);
return new Promise((resolve, reject) => {

@@ -232,4 +232,4 @@ const resultKey = `${uuid_1.v4()}-${new Date().getTime()}${Math.random()}`;

if (timeoutTimer === null)
return this.logger.debug(plugin, ` - REC EAR TOO LATE: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}]`, data.resultSuccess ? 'SUCCESS' : 'ERRORED', data);
this.logger.debug(plugin, ` - REC EAR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}]`, data.resultSuccess ? 'SUCCESS' : 'ERRORED', data);
return this.log.debug(plugin, ` - REC EAR TOO LATE: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}]`, data.resultSuccess ? 'SUCCESS' : 'ERRORED', data);
this.log.debug(plugin, ` - REC EAR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}]`, data.resultSuccess ? 'SUCCESS' : 'ERRORED', data);
clearTimeout(timeoutTimer);

@@ -248,3 +248,3 @@ timeoutTimer = null;

self.builtInEvents.removeListener(resultKey, listener);
self.features.log.debug(plugin, ` - EMIT AR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}-${resultKey}]`, 'TIMED OUT');
self.log.debug(plugin, ` - EMIT AR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}-${resultKey}]`, 'TIMED OUT');
reject(`NO RESPONSE IN TIME: ${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}/${resultKey} x${(data || {}).timeoutSeconds || 10}s`);

@@ -259,3 +259,3 @@ }, timeoutSeconds * 1000);

}, qArguments);
self.features.log.debug(plugin, ` - EMIT EAR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}-${resultKey}] - EMITTED`, data);
self.log.debug(plugin, ` - EMIT EAR: [${self.rabbitQConnectionEARChannelKey}-${pluginName || plugin}-${event}-${resultKey}] - EMITTED`, data);
});

@@ -262,0 +262,0 @@ }

@@ -1,1 +0,1 @@

{"name":"@bettercorp/service-base-plugin-events-rabbitmq","license":"AGPL-3.0-only","repository":{"url":"https://gitlab.com/BetterCorp/public/service-base-plugin-events-rabbitmq"},"scripts":{"dev":"nodemon -L --watch src/**/*.ts --watch plugins/**/*.ts --exec ts-node src/index.ts","start":"node lib/index.js","build":"tsc","deploy":"npm publish","version":"node ./node_modules/@bettercorp/service-base/build/version.js $0"},"files":["lib/**/*","installer.js"],"main":"lib/index.js","version":"1.0.20210611131248","dependencies":{"@bettercorp/service-base":"^4.1.20210611125805","@bettercorp/tools":"^1.1.20210611125606","@types/amqplib":"^0.5.17","@types/node":"^14.17.5","@types/uuid":"^8.3.1","amqplib":"^0.8.0","uuid":"^8.3.2"},"devDependencies":{"ts-node":"^8.0.2","tslint":"^5.12.0","typescript":"^3.9.10"}}
{"name":"@bettercorp/service-base-plugin-events-rabbitmq","license":"AGPL-3.0-only","repository":{"url":"https://gitlab.com/BetterCorp/public/service-base-plugin-events-rabbitmq"},"scripts":{"dev":"nodemon -L --watch src/**/*.ts --watch plugins/**/*.ts --exec ts-node src/index.ts","start":"node lib/index.js","build":"tsc","deploy":"npm publish","version":"node ./node_modules/@bettercorp/service-base/build/version.js $0"},"files":["lib/**/*","installer.js"],"main":"lib/index.js","version":"1.1.20210701165917","dependencies":{"@bettercorp/service-base":"^5.1.20210701165109","@bettercorp/tools":"^1.1.20210611181403","@types/amqplib":"^0.5.17","@types/node":"^14.17.7","@types/uuid":"^8.3.1","amqplib":"^0.8.0","uuid":"^8.3.2"},"devDependencies":{"ts-node":"^8.0.2","tslint":"^5.12.0","typescript":"^3.9.10"}}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc