Socket
Socket
Sign inDemoInstall

@barchart/events-client-js

Package Overview
Dependencies
19
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.9 to 1.0.10

14

lib/common/Configuration.js

@@ -10,4 +10,6 @@ module.exports = (() => {

class Configuration {
constructor() {}
constructor() {
}
/**

@@ -20,3 +22,3 @@ * The host of the development system.

*/
static get development() {
static get developmentHost() {
return 'events-stage.aws.barchart.com';

@@ -32,3 +34,3 @@ }

*/
static get staging() {
static get stagingHost() {
return 'events-stage.aws.barchart.com';

@@ -44,5 +46,9 @@ }

*/
static get production() {
static get productionHost() {
return 'events.aws.barchart.com';
}
toString() {
return '[Configuration]';
}
}

@@ -49,0 +55,0 @@

@@ -9,2 +9,10 @@ const assert = require('@barchart/common-js/lang/assert'),

/**
* A wrapper utility for an {@link @EventGateway} which caches and
* periodically sends new {@link Event} objects to the server.
*
* @public
* @param {EventGateway}
* @param {Function=} callback
*/
class EventBatcher {

@@ -18,50 +26,80 @@ constructor(eventGateway, callback) {

this._currentBatch = [ ];
this._nextBatch = [ ];
this._scheduler = new Scheduler();
this._sending = false;
this._watching = false;
this._scheduler = new Scheduler();
this._buffer = [ ];
this._running = false;
}
/**
* Starts the scheduler for transmitting events, causing
* events to be periodically flushed from the buffer.
*
* @public
*/
start() {
this._watching = true;
if (this._running) {
return;
}
this._scheduler = new Scheduler();
this._running = true;
watch.call(this);
}
/**
* Stops the scheduler, causing events to accumulate in
* the buffer.
*
* @public
*/
stop() {
this._watching = false;
this._running = false;
if (this._scheduler !== null) {
this._scheduler.dispose();
this._scheduler = null;
}
}
/**
* Clears the internal buffer of any events waiting to be
* sent to the server.
*
* @public
*/
clear() {
this._currentBatch = [ ];
this._nextBatch = [ ];
this._buffer = [ ];
}
/**
* Adds a new event to the buffer.
*
* @public
* @param {Event} event
*/
push(event) {
if (this._sending) {
this._nextBatch.push(event);
} else {
this._currentBatch.push(event);
}
this._buffer.push(event);
}
toString() {
return '[EventBatcher]';
}
}
function watch() {
if (!this._watching) {
if (!this._running) {
return;
}
if (this._currentBatch.length === 0) {
if (this._buffer.length === 0) {
return this._scheduler.schedule(watch.bind(this), 5000, 'Watch');
}
this._sending = true;
const batch = this._buffer;
this._buffer = [ ];
return this._eventGateway.createEvents(this._currentBatch)
return this._eventGateway.createEvents(batch)
.then((response) => {
console.log(`[ ${this._currentBatch.length} ] events successfully sent`);
if (this._callback) {

@@ -73,11 +111,9 @@ this._callback(response);

}).catch((err) => {
console.error(err);
console.error('Failed to transmit events to server', err);
return err;
}).then(() => {
this._currentBatch = this._nextBatch;
this._nextBatch = [ ];
this._sending = false;
return this._scheduler.schedule(watch.bind(this), 5000, 'Watch');
if (this._running) {
this._scheduler.schedule(watch.bind(this), 5000, 'Watch');
}
});

@@ -84,0 +120,0 @@ }

@@ -11,2 +11,9 @@ const assert = require('@barchart/common-js/lang/assert'),

/**
* A factory for event objects.
*
* @public
* @param {CustomerType} customer
* @param {ProductType} product
*/
class EventFactory {

@@ -21,2 +28,11 @@ constructor(customer, product) {

/**
* Configures a new event factory, which will build events for a specific
* customer and product.
*
* @public
* @param {CustomerType} customer
* @param {ProductType} product
* @returns {EventFactory}
*/
static for(customer, product) {

@@ -26,5 +42,14 @@ return new EventFactory(customer, product);

/**
* Creates a new event object, using the factory's customer and
* product.
*
* @public
* @param {EventType} type
* @param {Array} context
* @returns {Event}
*/
build(type, context) {
assert.argumentIsRequired(type, 'type', EventType, 'EventType');
assert.argumentIsArray(context,'context');
assert.argumentIsArray(context, 'context');

@@ -36,8 +61,24 @@ return {

timestamp: Timestamp.now().timestamp,
context: context,
context: context
};
}
toString() {
return '[EventFactory]';
}
}
/**
* An event.
*
* @typedef Event
* @type {Object}
* @property {CustomerType} customer
* @property {ProductType} product
* @property {EventType} type
* @property {Number} timestamp
* @property {Array} context
*/
return EventFactory;
})();

@@ -25,7 +25,6 @@ const assert = require('@barchart/common-js/lang/assert'),

* @public
* @extends {Disposable}
* @param {String} protocol - The protocol to use (either HTTP or HTTPS).
* @param {String} host - The host name of the Events web service.
* @param {Number} port - The TCP port number of the Events web service.
* @extends {Disposable}
*
*/

@@ -88,4 +87,4 @@ class EventGateway extends Disposable {

* @public
* @param {Array} events
* @returns {Promise<Object>}
* @param {Array<Event>} events
* @returns {Promise<Array<Events>>}
*/

@@ -112,5 +111,5 @@ createEvents(events) {

return Promise.resolve()
.then(() => {
return start(new EventGateway('https', Configuration.development, 443));
});
.then(() => {
return start(new EventGateway('https', Configuration.developmentHost, 443));
});
}

@@ -128,3 +127,3 @@

.then(() => {
return start(new EventGateway('https', Configuration.staging, 443));
return start(new EventGateway('https', Configuration.stagingHost, 443));
});

@@ -142,6 +141,10 @@ }

return Promise.resolve()
.then(() => {
return start(new EventGateway('https', Configuration.production, 443));
});
.then(() => {
return start(new EventGateway('https', Configuration.productionHost, 443));
});
}
toString() {
return '[EventGateway]';
}
}

@@ -161,3 +164,3 @@

}).catch((e) => {
console.error('Error serializing data to create event', e);
console.error('Error serializing data for event creation (using EventSchema.TYPE schema)', e);

@@ -164,0 +167,0 @@ return Promise.reject();

@@ -8,3 +8,2 @@ const assert = require('@barchart/common-js/lang/assert'),

Gateway = require('@barchart/common-js/api/http/Gateway'),
FailureReason = require('@barchart/common-js/api/failures/FailureReason'),
ProtocolType = require('@barchart/common-js/api/http/definitions/ProtocolType'),

@@ -26,7 +25,6 @@ RequestInterceptor = require('@barchart/common-js/api/http/interceptors/RequestInterceptor'),

* @public
* @extends {Disposable}
* @param {String} protocol - The protocol to use (either HTTP or HTTPS).
* @param {String} host - The host name of the Events web service.
* @param {Number} port - The TCP port number of the Events web service.
* @extends {Disposable}
*
*/

@@ -167,5 +165,23 @@ class ReportGateway extends Disposable {

.then(() => {
return start(new ReportGateway('https', Configuration.staging, 443));
return start(new ReportGateway('https', Configuration.stagingHost, 443));
});
}
/**
* Creates and starts a new {@link ReportGateway} for use in the production environment.
*
* @public
* @static
* @returns {Promise<ReportGateway>}
*/
static forProduction() {
return Promise.resolve()
.then(() => {
return start(new ReportGateway('https', Configuration.productionHost, 443));
});
}
toString() {
return '[ReportGateway]';
}
}

@@ -177,3 +193,3 @@

} catch (e) {
console.log('Error deserializing event-job', e);
console.log('Error deserializing report (using EventJobSchema.PROCESS schema)', e);
}

@@ -186,3 +202,3 @@ });

} catch (e) {
console.log('Error deserializing event-job', e);
console.log('Error deserializing report availability (using EventJobSchema.PROCESS schema)', e);
}

@@ -189,0 +205,0 @@ });

{
"name": "@barchart/events-client-js",
"version": "1.0.9",
"version": "1.0.10",
"description": "JavaScript library for interfacing with Barchart's Events API",

@@ -5,0 +5,0 @@ "author": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc