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

@corpsmap/create-jwt-api-bundle

v0.5.0

Published

Auto-wire your api calls to use a JWT (https://jwt.io) for authentication / authorization. Requires a selector to get the token, typically would be used in concert with the `@corpsmap/create-auth-bundle` but that's not required as long as you provide a se

Downloads

7

Readme

CREATE JWT API BUNDLE

Auto-wire your api calls to use a JWT (https://jwt.io) for authentication / authorization. Requires a selector to get the token, typically would be used in concert with the @corpsmap/create-auth-bundle but that's not required as long as you provide a selctor that returns a string token.

Usage

// returns a bundle, see redux-bundler documentation for more info on that
import createJwtApiBundle from "@corpsmap/create-jwt-api-bundle";

// default values for options shown
const apiBundle = createJwtApiBundle({
  name: "api", // optional string
  root: "", // required string, path to your api, won't really work with the default
  tokenSelector: "selectAuthToken", // optional string
  unless: null, // optional object, use to skip adding token to requests conditionally see below
});

Use the apiBundle in your composeBundles workflow to integrate it with your app store.

This will expose new api functions to all of your other action creators:

// in your custom bundle
doFetch: () => ({ dispatch, store, apiGet }) => {};

This bundle will expose the following:

  • apiFetch returns the fetch promise that you can treat as if you used the native fetch api.
  • apiGet fires a GET request, takes a path and a callback similar to the older-school ajax libraries. This was to make it plug and play with legacy code.
  • apiPut fires a PUT request, takes a path, a JSON payload and a callback function
  • apiPost firse a POST request, takes a path, a JSON payload and a callback function
  • apiDelete fires a DELETE request, takes a path and a callback function

Unless

If you want to bypass adding the token, say you want to make some of the requests anonymously in order to present users with some data without requiring them to log in you can set the unless option. This is modelled after the express-unless module, but uses a subset of their options:

unless should be set to an object that may contain one or more of the following keys that will be used to evaluate if the token should be added.

  • method it could be an string or an array of strings. If you want to allow all calls using this method to be anonymous, set it here.
  • path it could be an string, a regexp or an array of any of those. It also could be an array of object which is url and methods key-pairs. If the request path or path and method match, the call will be anonymous.
  • custom it must be a function that accepts an object containing the method and url and returns true / false. If the function returns true for the given request, the request will be sent anonymously.