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

@justeat/f-stat-client

v0.1.0

Published

Javascript HTTP client for publishing stats to ElasticSearch

Downloads

4

Readme

f-stat-client

Javascript HTTP client for publishing stats to ElasticSearch


npm version CircleCI Coverage Status Known Vulnerabilities

This client abstracts away the complexity of publishing stats to ElasticSearch, such as API timings so you can then graph on these results. It also provides a standardised approach for to follow that can be used in a suite of features and components, allowing you to use and report in a generic way.

Benefits (Now)

  • Simple publish method that hides away the complexities of making posts requests to ElasticSearch
  • Sensible defaults, with the ability to override all
  • If you run ElasticSearch locally in a Docker Container and use the host localhost then you can see you results instantly (see https://www.elastic.co/guide/en/elasticsearch/reference/7.0/docker.html & https://elasticvue.com/)
  • Built-in mock ability by providing a mock on the constructor (see https://github.com/elastic/elasticsearch-js-mock and an example below)

Benefits (Soon)

  • encapsulated batch publishing
  • encapsulated sample publishing
  • encapsulated authentication

Usage

Installation

Install the module using npm or Yarn:

yarn add @justeat/f-stat-client

Initialisation/Construction e.g.

import StatClient from '@justeat/f-stat-client';

const options = {
    statClientUri: 'http://public-elastic-search-endpoint',
    tenant: 'uk',
    featureName: 'checkoutweb'
};

const client = new StatClient(options);

How to use


await client.publish({ verb: 'GET', segment: '/search', status: 200, timing: 611 });

Note; the dynamic model passed to the publish() method will get deconstructed and written out as individual fields on the ElasticSearch document along with the fixed fields of FeatureName, Tenant and a Timestamp.

An example of the final document written to ElasticSearch:

Constructor

Parameter | Description | Type | Example ------------- | ------------- | ------------- | ------------- options | The overrides for the default options | json [string] | {statClientUri: 'http://localhost:9200',tenant: 'ns',featureName: 'Generic Front End'}(See below the defaults for the options if not overridden via the constructor options) mock | This can be supplied for testing purposes and will be used to return your mock response instead | @elastic/elasticsearch-mock | (see mock example below)

Options

Parameter | Description | Type | Default ------------- | ------------- | ------------- | ------------- statClientUri | The host of the stat publishing endpoint | String | 'http://localhost:9200' tenant | This is a key identifier to group stats by country, e.g. uk | String | 'ns' featureName | This is a key identifier to group stats by feature, e.g. salesWebsite | String | 'Generic Front End' statClientUser | The username to gain access to the stat publishing endpoint (if not supplied then no authentication will be used) | String | null statClientPwd | The password to gain access to the stat publishing endpoint (ignored if user not supplied) | String | null statClientIndexName | This is index to write to | String | 'justeat'

Client Methods

These are all of the methods exposed by the f-stat-client

Method | Description | Parameters | Example ------------- | ------------- | ------------- | ------------- publish | Sends a dynamic model (stat details) to the Endpoint | json [string] | {verb: 'GET',segment: '/search',status: 200,timing: 654}

How to Test/Mock e.g.

import StatClient from '@justeat/f-stat-client';

const Mock = require('@elastic/elasticsearch-mock');

const mock = new Mock();

// Build a cut down mock reponse
const mockResponse = {
    _index: 'justeat',
    result: 'created',
    statusCode: 201
};

// Mock the action to return the mock response
mock.add({
    method: 'POST',
    path: '*'
}, () => (mockResponse));

const options = {
    statClientUri: 'http://localhost:9200',
    tenant: 'uk',
    featureName: 'checkoutweb_test',
    statClientIndexName: 'justeat'
};

// Supply the mock on the constructor
const client = new StatClient(options, mock);

// Act
const response = await client.publish({ verb: 'GET', segment: '/basket', status: 200, timimg: 654 });

// Assert
expect(response.body.result).toBe('created');