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 🙏

© 2026 – Pkg Stats / Ryan Hefner

netra-api-logger

v1.2.0

Published

## Overview The Netra API Library is a JavaScript library designed to simplify interactions with the NETRA backend. It provides a straightforward way to handle API calls, manage response statuses, and switch between different server endpoints seamlessly.

Readme

Netra API Library

Overview

The Netra API Library is a JavaScript library designed to simplify interactions with the NETRA backend. It provides a straightforward way to handle API calls, manage response statuses, and switch between different server endpoints seamlessly.

Features

  • API Client: A robust client for making GET, POST, PUT, and DELETE requests.
  • Status Handling: Automatic handling of common HTTP response statuses (200, 404, 500, etc.).
  • Token Management: Functions for generating SAS tokens for secure API access.
  • Server Switching: A round-robin mechanism for switching between multiple NETRA API endpoints.

Installation

To install the Netra API Library, use npm:

npm install netra-api-lib

Usage

Initialization

First, import the library and initialize the API client:

import { ApiClient } from 'netra-api-lib';

const apiClient = new ApiClient();

Making Requests

You can make requests using the methods provided by the ApiClient class:

// Example of a GET request
apiClient.get('/endpoint')
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.error(error);
  });

Handling Tokens

To generate a token for your requests, use the token management functions:

import { generateToken } from 'netra-api-lib/token';

const token = generateToken();

Switching Servers

If you need to switch between different NETRA API servers, use the ServerSwitcher class:

import { ServerSwitcher } from 'netra-api-lib/serverSwitcher';

const serverSwitcher = new ServerSwitcher();
const nextServer = serverSwitcher.getNextServer();

API Reference

  • ApiClient: Class for making API requests.

    • get(endpoint): Makes a GET request to the specified endpoint.
    • post(endpoint, data): Makes a POST request to the specified endpoint with the provided data.
    • put(endpoint, data): Makes a PUT request to the specified endpoint with the provided data.
    • delete(endpoint): Makes a DELETE request to the specified endpoint.
  • Token Functions:

    • generateToken(): Generates a SAS token for authentication.
  • ServerSwitcher: Class for managing server endpoints.

    • getNextServer(): Returns the next server endpoint in the round-robin sequence.

Contributing

Contributions are welcome! Please submit a pull request or open an issue for any enhancements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

This module provides functions to store, batch, and push log events to Netra using IndexedDB (via Dexie.js). It supports bulk sending, retry logic, and safe clearing of logs per day.

Functions initDb(customName?: string): Dexie Initializes the IndexedDB database with a custom name (default: "NetraLogsDB").

Parameters:

customName (optional): The name of the database to use. Usage:

initDb("NetraLogsDB-ttweb");

storeLogAndMaybePush(logEvent: object): Promise Stores a log event in IndexedDB. When the total size of pending logs reaches 600KB it pushes all pending logs to Netra in bulk. Uses a batch ID to avoid data loss in multi-tab scenarios.

Parameters:

logEvent: The log data object to store. Behavior:

Adds the log with status "pending". If size limit reached, marks all pending logs as "pushing" with a unique batch ID. Sends only logs with that batch ID. Clears only successfully pushed logs. If push fails, reverts status to "pending" for retry. Usage:

await storeLogAndMaybePush(logData);

clearDbOnNewDayLogin(): Promise Clears the database on a new day (based on date comparison). Deletes the DB and re-initializes it, then stores the new date in the meta table.

Behavior:

Checks the last login date in the meta table. If today is different, deletes the DB and re-initializes. Updates the meta table with the new date. Usage:

await clearDbOnNewDayLogin();

How It Works Batching: Logs are stored in IndexedDB until the size limit is reached, then sent in bulk. Multi-tab Safety: Uses status and batchId fields to avoid clearing logs added during a bulk push. Daily Reset: Clears the DB and resets log IDs on a new day. Recommended Usage Pattern Initialize DB at startup:

initDb("NetraLogsDB-ttweb");

Clear DB on new day (e.g., at login):

await clearDbOnNewDayLogin();

Log events:

await storeLogAndMaybePush(logData);

Notes The log table uses auto-incrementing IDs. Only logs for a successful bulk push are deleted. The meta table stores the last login date for daily resets.