npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

atom-node

v1.6.0

Published

IronSource Atom NodeJS SDK

Downloads

3

Readme

ironSource.atom SDK for Node-JS

License Docs Coverage Status Build status npm version

atom-node is the official ironSource.atom SDK for Node.JS Javascript runtime

Installation

Installation using npm

$ npm install atom-node --save

Usage

High Level SDK - "Tracker"

The tracker is used for sending events to Atom based on several conditions

const AtomTracker = require('atom-node').Tracker;
co(function*() {
  const params = {
    endpoint: "https://track.atom-data.io/", // Optional, Don't change this (unless you have your own DNS CNAME)
    auth: "YOUR PRE-SHARED HAMC AUTH KEY", // Can be found in Atom Console
    flushInterval: 10, // Optional, Flushing interval in seconds
    bulkLen: 1000, // Optional, Max count for events to send
    bulkSize: 128, // Optional, Max size of data in Kb
  };

  let tracker = new AtomTracker(params);
  tracker.on('error', (err, data) => {
    // Handle Flush errors in here (write to file for example)
    console.log(`[TRACKER EXAMPLE] Got Error: ${err} for #${data.data.length} events`);
  });
  for (let i = 0; i < 10; i++) {
    let data = {
      id: i
    };
    try {
      yield tracker.track("SOME STREAM", data)
    } catch (err) {
      console.log(`[TRACKER EXAMPLE] track() method Error: ${err}`);
    }
  }
  // For sending events immediately use
  tracker.flush();
});

Tracker Flow Control

The methods: track() and flush() are decoupled and independent of each other.

track() method behaviour:
Tracks data to backlog, returns a Promise which will be resolved only when data is tracked to backlog.
The function rejects the Promise in 3 cases:

  1. Stream and/or Data are missing.
  2. Tracker has been stopped.
  3. In Non-blocking mode and trackingTimeout has been reached.

track() by default is blocking, but you can set it as non-blocking.
Note: blocking means that it will block new track() calls and not the whole event loop.
If block is true (the default) => block if necessary until a free slot is available.
If block is false and timeout is a positive number: blocks at most timeout seconds (10 seconds by default)
and emit and error event if no free slot was available within that time.

Tracker Error Handling

All track() errors need to be handled by a regular try-catch block.
All flush() errors are handled by error event.
See here for all usage examples
Error event is mandatory and you must listen to it.

tracker.on("error", (err, data) => console.log("[EXAMPLE2-GENERATOR] onError function:", err, data));

Tracker Events:

Except for 'error', the tracker emits this optional events:

  • retry - on first retry to server (500)
    The following are called only when there is a graceful shutdown:
  • stop - when stop() is called or when tracker gets a killing signal
  • empty - when the backlog is empty and there are no more in-flight msgs
tracker.on("stop", _ => console.log("[EXAMPLE2-GENERATOR] tracker stopped"));
tracker.on("retry", _ => console.log("[EXAMPLE2-GENERATOR] tracker emitted 'retry' event"));
tracker.on("empty", _ => console.log("[EXAMPLE2-GENERATOR] tracker emitted 'empty' event"));

Tracker Backlog

The tracker is using a simple in memory storage for its backlog
You can replace it with a custom backlog using the same interface

const AtomTracker = require('atom-node').Tracker;
const params = {
  backlog: YourCustomBacklogClass()
}
let tracker = new AtomTracker(params);

Tracker Logger

The tracker is using a simple logger based on console, you can replace it with your own (bunyan for example)

const AtomTracker = require('atom-node').Tracker;
const params = {
  logger: myLoggerModule
}
let tracker = new AtomTracker(params);

Low Level (Basic) SDK

The Low Level SDK has 2 methods:

  • putEvent - Sends a single event to Atom
  • putEvents - Sends a bulk (batch) of events to Atom (must be an array)
'use strict';
const AtomReporter = require('atom-node').ISAtom;
const options = {
  endpoint: "https://track.atom-data.io/",
  auth: "YOUR_API_KEY"
};

let atom = new AtomReporter(options);
let params = {
  stream: "STREAM_NAME", // Your target stream name
  data: JSON.stringify({name: "iron", last_name: "Source"}), // Object / Stringified Json
}
// With co (POST):
co(function*() {
  try {
    let res = yield atom.putEvent(params);
    console.log(`[Example PutEvent POST] success: ${res.message} ${res.status}`);
  } catch (err) {
    console.log(`[Example PutEvent POST] failure: ${err.message} ${err.status}`);
  }
});
  
// With Promises
params.method = 'POST';
atom.putEvent(params).then(function (res) {
  console.log(`[Example PutEvent POST] success: ${res.message} ${res.status}`);
}).catch(function (err) {
  console.log(`[Example PutEvent POST] failure: ${err.message} ${err.status}`);
});

// PutEvents (batch):
let batchPayload = {
  stream: "STREAM_NAME", // Your target stream name
  data: [{name: "iron", last_name: "Beast"},
    {name: "iron2", last_name: "Beast2"}], // Array with Json / Stringified Json
};
atom.putEvents(batchPayload).then(function (res) {
  console.log(`[Example PutEvents POST] success: ${res.message} ${res.status}`);
}, function (err) {
  console.log(`[Example PutEvents POST] failure: ${err.message} ${err.status}`);
});

Change Log

v1.6.0

  • Changed flow control to make it more clear and reliable (see Usage)
  • Removed FlushOnExit param - tracker will always try to flush on exit
  • Added a tracking timeout option - works only on non-blocking mode
  • Added a blocking / non-blocking toggle.
  • Tracker flush mechanism now emits events on: stop, first retry, empty & error
  • onError callback replaced with "error" event.

v1.5.2

  • Fixed broken headers
  • Added more parameters to the onError func
  • Added Limits to SDK Bulk Length and Bulk Size & Flush Interval

v1.5.1

  • Updated npm package conf
  • Updated readme
  • Changed project directory structure

v1.5.0

  • Refactored Request class
  • Refactored Atom class
  • Refactored Tracker
  • Fixed a bug in Tracker exit handler (there was no delay on graceful shutdown)
  • Added an option to add a callback on error (after max retries reached)
  • Changed example
  • Added more options to conf
  • Rewrote all tests and increased coverage
  • Updated README
  • Updated all docs and changed them from apiDoc to JSDoc
  • Fixed a bug with headers not being sent
  • Added AtomError custom Error

v1.2.0

  • Fixed tracker retry bug - caused by mutating an object that was passed by reference
  • increased test coverage
  • Updated README.MD

v1.1.2

  • Fixed tests and removed unused dependencies
  • Updated tests to run on LTS

v1.1.0

  • Added tracker
  • Added Backoff mechanism

v1.0.0

  • Basic features: putEvent & putEvents functionalities

Example

You can use our example for sending data to Atom.

node example/example.js -h

  Usage: example [options]

  Options:

    -h, --help       output usage information
    -V, --version    output the version number
    -p, --putevent   Run the putEvent examples
    -P, --putevents  Run the putEvents examples
    -H, --health     run the health check example
    -t, --tracker    run the tracker example
    -a, --all        Run all of the examples

License

MIT