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

@map-colonies/mc-utils

v3.2.0

Published

This is template for map colonies typescript packages

Downloads

1,652

Readme

mc-utils

this is general utilities for usage in Map Colonies project.

included components

usage

http client

this is abstract base class for sending http request with logging and request retries.

this class constructor requires the following parameters:

  • ILogger instance.
  • base url to use for all requests.
  • optional name for target service to be used in logs.
  • optional retry configuration.

the class have the following protected attributes -axiosOptions the options used by axios when sending requests

the class have the protected methods for sending http requests:

  • protected async get<T>(url: string, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig, auth?: AxiosBasicCredentials, headers?: unknown): Promise<T>
  • protected async post<T>(url: string, body?: unknown, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig, auth?: AxiosBasicCredentials, headers?: unknown): Promise<T>
  • protected async put<T>(url: string, body?: unknown, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig, auth?: AxiosBasicCredentials, headers?: unknown): Promise<T>
  • protected async delete<T>(url: string, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig, auth?: AxiosBasicCredentials, headers?: unknown): Promise<T>
  • protected async head<T>(url: string, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig, auth?: AxiosBasicCredentials, headers?: unknown): Promise<T>
  • protected async options<T>(url: string, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig, auth?: AxiosBasicCredentials, headers?: unknown): Promise<T>
  • protected async patch<T>(url: string, body?: unknown, queryParams?: Record<string, unknown>, retryConfig?: IAxiosRetryConfig, auth?: AxiosBasicCredentials, headers?: unknown): Promise<T>

function parameters list:

  • url: url path to send the request to (not including the base url).
  • body: optional object to be used as request body (in relevant request types).
  • queryParams: optional dictionary with query parameters and value.
  • retryConfig: optional override to the class retry configuration.
  • auth: optional basic authentication object (username, password).
  • headers: optional headers to proceed to the request.

usage example:

class myServiceClient extends HttpClient {
  public constructor(logger: ILogger){
    super(logger,'https://myService.com','myService',{
      attempts: 3,
      delay: 'exponential',
      shouldResetTimeout: true
    })
  }

  public async getName(): string {
    const name = await this.get<string>('api/name',{queryParam1: 'name'});
    return name;
  }
}

models

ILogger

logger interface with the flowing log methods

  • error(message:string)
  • warn(message:string)
  • info(message: string)
  • debug(message: string)

IHttpRetryConfig

http requests retry configuration interface with the following attributes:

  • attempts - the number of request to send until valid response (not 500+ status code). this value must be integer and greater then 0.
  • delay - the amount of time in ms to wait between attempts (for constant delay) or 'exponential' for exponential backoff.
  • shouldResetTimeout boolean value to indicate if the request timeout should be for each request (true) or global for all attempts (false)