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

@penzle/core-sdk

v3.0.2

Published

This package includes the core modules and utilities for the penzle-delivery.js and penzle-management.js SDKs.

Downloads

5

Readme

npm version Build Known Vulnerabilities GitHub license Gzip browser bundle Discord

Penzle Core package

This package includes the core modules and utilities for the penzle-delivery.js and penzle-management.js SDKs.

Installation

To install the JavaScript Delivery SDK, you can either use npm or take advantage of global CDNs like jsdelivr.

npm

To install the SDK via npm, run this command:

npm i @penzle/core-sdk --save

UMD Bundles

For UMD bundles, include the library using a script tag on your HTML page. The library will be accessible through the penzleDelivery global variable.

UMD bundles can be found in the dist/bundles folder.

  • dist/bundles/penzle-core.js
  • dist/bundles/penzle-core.min.js

CDN Options

Choose between two available CDN options for the Penzle JavaScript Delivery SDK: the standard UMD bundle and the minified UMD bundle.

Standard UMD Bundle (penzle-core.js)

Gzip UMD bundle

Use the following link to include the standard UMD bundle:

https://cdn.jsdelivr.net/npm/@penzle/core-sdk@latest/dist/bundles/penzle-core.js
Minified UMD Bundle (penzle-core.min.js)

Gzip UMD Minified bundle

Use the following link to include the minified UMD bundle:

https://cdn.jsdelivr.net/npm/@penzle/core-sdk@latest/dist/bundles/penzle-core.min.js

HttpService: Handling HTTP Requests and Responses with Retry Policy

The HttpService class is an implementation of the ApiService interface that provides functionality for making HTTP requests and processing responses. It uses the Axios library to make the requests and can be configured with custom settings.

Methods

The HttpService class has methods for making HTTP requests, including get, post, delete, patch, and put. Each method accepts a corresponding HttpMethod object (e.g., HttpGet, HttpPost) and an optional HttpSettings object, which contains settings like headers, responseType, cancellationToken, and retryStrategy.

For each request, the getRetryPolicy method is used to determine the retry strategy based on the provided settings or the default retry strategy.

The ResponseFactory.create method is used to create a Response object from the Axios response and the retry strategy configuration.

createCancellationToken

This method creates a new HttpCancellationToken that can be used to cancel an ongoing HTTP request. It uses the Axios CancelToken and Canceler to manage cancellation.

getRetryPolicy

This method returns the retry policy based on the provided RetryStrategySettings or the default retry strategy. The default strategy has a maximum of 5 retries and uses an exponential delay between retries.

Usage

To use the HttpService, create an instance and pass the desired settings (if any) to the constructor. Then, call the appropriate method (e.g., get, post, delete, patch, put) with the required HttpMethod object and optional HttpSettings object.

Debugging

Each response from this SDK is bundled with supplementary debug data. This data can be extremely useful for troubleshooting if you encounter any issues, or if you need to examine network-related properties such as response headers.

Consider the following code snippet as an example:


// 'deliveryResponse.response' holds the raw response data, headers, status, etc.
const rawResponseData = httpService.get<TResult>(method: HttpGet, settings?: HttpSettings<CancelToken>);

// To access response headers specifically, use 'rawResponse.headers'.
const responseHeaders = rawResponseData.rawResponse.headers;

Implementing Test HTTP Service

In certain cases, you might want to inject a testing service as an implementation of the ApiService interface. This is particularly useful when you're writing tests and want to mock HTTP responses. Our library provides a configurable TestHttpService for such purposes.

import { TestHttpService } from '@penzle/core-sdk';

const client = new /*(Delivery/Management)*/Client() {
    // ...
    httpService: new TestHttpService({
        fakeResponseJson: json,
        throwError: false
    });

Reach out to us

Need Help Using This Library?

If you need any assistance regarding the use of this library, we have several resources available to support you:

  • Questions: Reach out to our support
  • Instant Messaging: For more immediate, casual conversation, our Discord Channel is a great place to connect with both the team and other users.

Encountered an Issue or Have a Suggestion

If you've come across a bug or have an idea for a new feature, we would love to hear from you! You can also open an issue on the GitHub repository or submit a pull request with improvements to the code: File an issue

Need to Share Sensitive Information or Have Additional Inquiries?

If you need to share private data or have any other questions that weren't addressed, please don't hesitate to reach out.

Contribution

We welcome contributions to this library. If you are interested in contributing, please read the CONTRIBUTING file for more information on how to get started. Your help is appreciated, and every contribution counts in making our project better.

Code of Conduct

Our aim is to foster a community that is respectful, inclusive, welcoming, and free from any form of harassment. We want all participants to feel safe, regardless of their gender identity, sexual orientation, disability, physical appearance, socioeconomic status, body size, ethnicity, nationality, experience level, age, religious beliefs, or any other aspect of identity.

Read our full Code of Conduct.

License

This SDK is released under the MIT License.