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

@lankajs/plugin-http

v5.0.0

Published

plugin: Retry, idempotency, CSRF, credentials, auth refresh and timeout as request middleware.

Readme

@lankajs/plugin-http

⬡ plugin · Request policy

Retry, idempotency, CSRF, credentials, auth refresh and timeout as request middleware.

A core capability core does not implement itself. Registered with use(), then called by core. peerDependencies: lanka is mandatory.

Runs in: the browser, node and React Native — everywhere.

How to use it: GUIDE.md — the user guide, with examples. How to change it: SKILL.md.

Extension point

Plugs into:

ALankaRequest → middleware chain (`useRequestMiddleware`), wired through `lanka.use()`

Mapping a server shape is a schema, not an adapter

A backend whose names are not the application's is read by a TRANSFORMING schema — v.pipe(..., v.transform(...)) — because the validator returns what the schema produced. One call reads the wire and builds the domain object, so there is no adapter layer and no adapt() beside validate().

Keep the mapping and the domain check as TWO schemas. The first changes when the server changes, the second when the application does, and each names its own context — so a failure says which of the two contracts broke, which is the difference between calling the backend team and reading your own reducer.

The reverse direction is the same thing: the payload a backend expects back is a mapping from the domain, not a serialiser. Both are in this package's playground.

Differences are CONFIGURATION, never a branch

Two apps can need genuinely different request policies — cookie session versus token session, CSRF or none, retry or none. A plugin expressing one of them as if (console) would only move the fork to another file; this package names no consumer.

Three rules, each of which cost a defect

Retry without idempotency is more dangerous than no retry. A failure can happen AFTER the server performed the request: the response was lost, the action happened. A retry without a key reads as a new intent and creates a second object — a payment, an invitation. So this configuration is rejected AT BUILD TIME, not on the first retry in production.

A key is issued once per intent, never per attempt. Idempotency registers OUTSIDE retry for exactly this reason: inside, it would mint a new key per attempt — the very defect the key exists to prevent.

Auth refresh takes a function, not an endpoint URL. A plugin that knew the endpoint would also know the response shape and the session storage, and would stop being a request policy. One attempt per 401: a second 401 after a successful refresh means refresh does not work and the loop must break — in production an infinite loop looks like a hung interface, not like an error.

A cookie session has to send the cookie

credentials lives in defaults, and lankaCookieSessionPolicy sets "include". The preset used to set the CSRF header and leave the credential alone — a proof of origin attached to a request that authenticated nobody, because fetch defaults to "same-origin" and the ordinary deployment puts the API on another host. There was nowhere else to say it: core knows nothing of cookies on purpose, so an application wrote the line into a transport of its own and, having written a transport, put the base URL, the retry and the refresh in there too.


Repository map: ../../README.md