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

darkspark-core-plug

v0.6.2

Published

This is the core HTTP request/response collection component for [Darkspark](https://darkspark.io). It provides a simple interface for ingesting HTTP request/response pairs, processing them locally and sending metadata to Darkspark. Metadata collected cons

Downloads

31

Readme

Darkspark Core Collector

This is the core HTTP request/response collection component for Darkspark. It provides a simple interface for ingesting HTTP request/response pairs, processing them locally and sending metadata to Darkspark. Metadata collected consists of:

  • The method and path of the request. Certain path elements such as numbers and UUIDs are replaced with placeholder tokens.
  • Query parameter keys.
  • Request and response header keys.
  • The request body schema.
  • The response body schema.

The core collector ensures that only this metadata is collected, and the actual content of the HTTP request never leaves the local environment.

The core collector can be used in two ways:

  1. As a Javascript/Typescript library
  2. As a standalone executable running on Node

In either form of usage you first need a Darkspark API key. See the Darkspark Documentation to learn how to create a key.

Library

To use as a library, import darksparkCoreReceiver and HttpEventLike from darkspark-core-plug/lib, create a receiver and send it events:

const { darksparkCoreReceiver, HttpEventLike } = require('darkspark-core-plug/lib');

const receiver = darksparkCoreReceiver("<your Darkspark API key>")

const event = {
    ...
};
receiver.receive(event);

Debugging

By default the core collector operates silently. To see diagnostics and internal logging, pass a Logger implementation to darksparkCoreReceiver and enable debug mode:

const receiver = darksparkCoreReceiver(
  "<your Darkspark API key>",
  new ConsoleLogger(),
  true
);

Alternate implementations of Logger may be used to integrate with your own logging environment.

Standalone

If you are not using Javascript/Typescript, or if you prefer to hand off the Darkspark data collection to a separate process, use the core collector as a standalone executable. It can be run directly with Node, passing the API key as an argument:

node darkspark-core-plug/index.js "<your Darkspark API key>"

The process reads JSON-serialised HttpEventLike objects from stdin and forwards them to Darkspark. Each event should be written as a JSON object on a single line, followed by a newline character.

Constructing HttpEvents

The core collector normalises incoming events to HttpEvent but for convenience it also accepts HttpEventLike which has less strict requirements. In Typescript this is defined as:

export interface HttpEventLike {
  metadata: {
    schema_type: "http-event";
    schema_version: number | string;
    created_by: string;
    created_at: string;
    id: string;
  };
  request: {
    method: string;
    scheme: string;
    body?: string;
    headers: KeyValuePairs;
    host: string;
    path: string;
    port?: number | string;
    query?: KeyValuePairs;
  };
  response: {
    status_code?: number | string;
    headers?: KeyValuePairs;
    body?: string;
  };
}

It should be populated as follows:

  • metadata.schema_type must be "http-event"
  • metadata.schema_version must be 2
  • metadata.created_by should name the source of the event
  • metadata.created_at should be an ISO 8601 timestamp
  • metadata.id should be a unique identifier for the event (we love UUIDs!)
  • request.method is the HTTP method of the request; case is not important
  • request.scheme must be either "http" or "https"
  • request.body if included is a base64-encoded string of the raw request body
  • request.headers is a list of KeyValuePair containing the request headers
  • request.host is the target host the request was sent to
  • request.path is the path component of the request URL
  • request.port if included is the port the request was sent to
  • request.query if included is a list of KeyValuePair containing the query parameters
  • response.status_code if included is the HTTP status code of the response
  • response.headers if included is a list of KeyValuePair containing the response headers
  • response.body if included is a base64-encoded string of the raw response body

KeyValuePair is defined as:

export interface KeyValuePair {
  key: string;
  value: string;
}

Lists of these are used for headers and query parameters rather than objects to allow for duplicate keys.

Request and response bodies should be base64-encodings of the raw bytes of the bodies. Darkspark will interpret Content-Encoding and Content-Type headers to decode the body as necessary.