@barchart/events-client-js
Advanced tools
Comparing version 1.6.0 to 2.0.0
@@ -7,3 +7,3 @@ const Enum = require('@barchart/common-js/lang/Enum'); | ||
const version = require('../../../lib/meta').version; | ||
const version = require('../../../lib/index').version; | ||
@@ -10,0 +10,0 @@ module.exports = (() => { |
@@ -15,2 +15,3 @@ const gulp = require('gulp'); | ||
jshint = require('gulp-jshint'), | ||
merge = require('merge-stream'), | ||
prompt = require('gulp-prompt'), | ||
@@ -65,9 +66,15 @@ rename = require('gulp-rename'), | ||
return gulp.src(['./lib/meta.js']) | ||
const index = gulp.src(['./lib/index.js']) | ||
.pipe(replace(/(version:\s*')([0-9]+\.[0-9]+\.[0-9]+)(')/g, '$1' + version + '$3')) | ||
.pipe(gulp.dest('./lib/')); | ||
const coverpage = gulp.src(['./docs/_coverpage.md']) | ||
.pipe(replace(/[0-9]+\.[0-9]+\.[0-9]+/g, version)) | ||
.pipe(gulp.dest('./docs/')); | ||
return merge(index, coverpage); | ||
}); | ||
gulp.task('commit-changes', () => { | ||
return gulp.src([ './', './test/', './package.json', './lib/meta.js', './example/browser/example.event.js', './example/browser/example.report.js', './test/SpecRunner.js' ]) | ||
return gulp.src([ './', './test/', './package.json', './lib/index.js', './example/browser/example.event.js', './example/browser/example.report.js', './test/SpecRunner.js' ]) | ||
.pipe(git.add()) | ||
@@ -74,0 +81,0 @@ .pipe(git.commit('Release. Bump version number')); |
@@ -8,2 +8,3 @@ module.exports = (() => { | ||
* @public | ||
* @ignore | ||
*/ | ||
@@ -10,0 +11,0 @@ class Configuration { |
@@ -10,4 +10,4 @@ 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. | ||
* A utility which buffers {@link Schema.Event} objects and periodically | ||
* transmits them to backend in batches. | ||
* | ||
@@ -33,4 +33,4 @@ * @public | ||
/** | ||
* Starts the scheduler for transmitting events, causing | ||
* events to be periodically flushed from the buffer. | ||
* Begins queue processing. Items in the buffer will begin to be transmitted | ||
* to the remote service. | ||
* | ||
@@ -47,9 +47,9 @@ * @public | ||
watch.call(this); | ||
processBuffer.call(this); | ||
} | ||
/** | ||
* Stops the scheduler, causing events to accumulate in | ||
* the buffer. | ||
* | ||
* Stops the queue processing. Items in the buffer accumulate without being | ||
* transmitted to the remote service. | ||
* | ||
* @public | ||
@@ -67,4 +67,3 @@ */ | ||
/** | ||
* Clears the internal buffer of any events waiting to be | ||
* sent to the server. | ||
* Clears the internal buffer. | ||
* | ||
@@ -81,3 +80,3 @@ * @public | ||
* @public | ||
* @param {Event} event | ||
* @param {Schema.Event} event | ||
*/ | ||
@@ -93,3 +92,3 @@ push(event) { | ||
function watch() { | ||
function processBuffer() { | ||
if (!this._running) { | ||
@@ -100,7 +99,7 @@ return; | ||
if (this._buffer.length === 0) { | ||
return this._scheduler.schedule(watch.bind(this), 5000, 'Watch'); | ||
return this._scheduler.schedule(processBuffer.bind(this), 5000, 'processBuffer'); | ||
} | ||
const batch = this._buffer; | ||
this._buffer = [ ]; | ||
@@ -115,9 +114,9 @@ | ||
return response; | ||
}).catch((err) => { | ||
console.error('Failed to transmit events to server', err); | ||
}).catch((e) => { | ||
console.error('Failed to transmit events to Barchart Usage Tracking Service', e); | ||
return err; | ||
return null; | ||
}).then(() => { | ||
if (this._running) { | ||
this._scheduler.schedule(watch.bind(this), 5000, 'Watch'); | ||
this._scheduler.schedule(processBuffer.bind(this), 5000, 'processBuffer'); | ||
} | ||
@@ -124,0 +123,0 @@ }); |
@@ -12,3 +12,3 @@ const assert = require('@barchart/common-js/lang/assert'), | ||
/** | ||
* A factory for event objects. | ||
* A utility for simplifying the construction of event. | ||
* | ||
@@ -29,22 +29,8 @@ * @public | ||
/** | ||
* Configures a new event factory, which will build events for a specific | ||
* customer and product. | ||
* Creates a new {@link Schema.Event} object, using the factory's customer and product. | ||
* | ||
* @public | ||
* @param {CustomerType} customer | ||
* @param {ProductType} product | ||
* @returns {EventFactory} | ||
*/ | ||
static for(customer, product) { | ||
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} | ||
* @returns {Schema.Event} | ||
*/ | ||
@@ -64,2 +50,14 @@ build(type, context) { | ||
/** | ||
* 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) { | ||
return new EventFactory(customer, product); | ||
} | ||
toString() { | ||
@@ -70,15 +68,3 @@ 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; | ||
})(); |
@@ -104,3 +104,3 @@ const assert = require('@barchart/common-js/lang/assert'), | ||
* @param {String} stage | ||
* @returns {Promise<ReportGateway|null>} | ||
* @returns {Promise<EventGateway|null>} | ||
*/ | ||
@@ -107,0 +107,0 @@ static for(stage) { |
{ | ||
"name": "@barchart/events-client-js", | ||
"version": "1.6.0", | ||
"description": "JavaScript library for interfacing with Barchart's Events API", | ||
"version": "2.0.0", | ||
"description": "JavaScript SDK for Barchart's Event Tracking Service", | ||
"author": { | ||
@@ -19,22 +19,23 @@ "name": "Bryan Ingle", | ||
"dependencies": { | ||
"@barchart/common-js": "^3.8.0", | ||
"@barchart/events-api-common": "^1.7.0" | ||
"@barchart/common-js": "^3.15.0", | ||
"@barchart/events-api-common": "^1.8.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.10.1", | ||
"aws-sdk": "^2.686.0", | ||
"@babel/core": "^7.11.6", | ||
"aws-sdk": "^2.747.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"babelify": "^10.0.0", | ||
"browserify": "^16.5.0", | ||
"browserify": "^16.5.2", | ||
"git-get-status": "^1.0.5", | ||
"glob": "^6.0.1", | ||
"gulp": "^4.0.2", | ||
"gulp-awspublish": "^4.0.0", | ||
"gulp-awspublish": "^4.1.2", | ||
"gulp-git": "^2.5.1", | ||
"gulp-jasmine": "^2.2.1", | ||
"gulp-jshint": "~2.1.0", | ||
"gulp-prompt": "^1.2.0", | ||
"gulp-rename": "^1.4.0", | ||
"gulp-replace": "^0.5.4", | ||
"gulp-prompt": "^1.2.0", | ||
"jshint": "^2.10.3", | ||
"jshint": "^2.12.0", | ||
"merge-stream": "^2.0.0", | ||
"vinyl-buffer": "^1.0.1", | ||
@@ -41,0 +42,0 @@ "vinyl-source-stream": "^2.0.0" |
@@ -5,67 +5,14 @@ # @barchart/events-client-js | ||
A **public** JavaScript SDK for interfacing with Barchart's Event Tracking System | ||
This **JavaScript SDK** connects your software to Barchart's Event Tracking System — a simple tool for collecting usage statistics. | ||
## Overview | ||
### Documentation | ||
The Barchart Event Tracking System collects usage statistics from various software systems and exposes the following functionality: | ||
Complete documentation for this SDK can be accessed [here](https://barchart.github.io/events-client-js/). | ||
- Accepts and **saves events** (e.g. Job Started, Pizza Ordered, Lightning Struck, etc). | ||
- Accepts requests to **generate log files** containing events (given a customer, product type, and optional start and end dates). | ||
### Package Managers | ||
This SDK simplifies interaction with the Barchart Event Tracking System, by exposing JavaScript classes with simple functions: | ||
This library has been published as a _public_ module to NPM as [@barchart/events-client-js](https://www.npmjs.com/package/@barchart/events-client-js). | ||
- EventGateway.sendEvents (sends a new event(s) to the backend), | ||
- ReportGateway.startReport (triggers generation of a new report), | ||
- ReportGateway.getReportAvailability (checks progress of report generation), and | ||
- ReportGateway.getReport (gets the download link for a completed report) | ||
### License | ||
Also, two utilities exist: | ||
- EventBatcher (Wraps an EventGateway, temporarily caching new events before sending them to the backend), and | ||
- EventFactory (Simplifies creation of event objects) | ||
## Documentation | ||
The code is documented with [JSDoc](http://usejsdoc.org/). This will be used as the basis for formal documentation (coming soon). | ||
## Examples | ||
### SDK Usage | ||
A step-by-step guide for using the SDK can be found here: [README_SDK.md](https://github.com/barchart/events-client-js/blob/master/README_SDK.md). | ||
### Direct API Access | ||
You can interact with the Barchart Event Tracking System without using this SDK. The documentation for the API can be found here: [README_API.md](https://github.com/barchart/events-client-js/blob/master/README_API.md). | ||
### Browser Test Client | ||
Two example pages exist. One allows you to send manually generated events the backend. The other allows you to trigger report generation, check report status, and download reports. Please note, these clients are attached to the _staging_ environment (not the production environment). | ||
Load the examples from your local file system, here: | ||
- ./example/browser/example.event.html | ||
- ./example/browser/example.report.html | ||
Or, visit the hosted page at: | ||
- [https://examples.aws.barchart.com/events-client-js/example.event.html](https://examples.aws.barchart.com/events-client-js/example.event.html) | ||
- [https://examples.aws.barchart.com/events-client-js/example.report.html](https://examples.aws.barchart.com/events-client-js/example.report.html) | ||
## Development | ||
#### Package Managers | ||
This library has been published as a *public* module to NPM as [@barchart/events-client-js](https://www.npmjs.com/package/@barchart/events-client-js). | ||
```shell | ||
npm install @barchart/events-client-js -S | ||
``` | ||
#### Build | ||
Modern JavaScript language features are used. Some browsers may still require polyfills. | ||
#### License | ||
This software is provided under the MIT license. |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1382743
46
30432
19
17