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

weweb-microservice-token

v0.1.19

Published

microservices token management for Weweb

Readme

Api token management for Weweb

https://www.npmjs.com/package/weweb-microservice-token

npm install weweb-microservice-token --save

Network error diagnostics

Set preserveNetworkError: true in request options to receive a NetworkError with code: 'NETWORK_ERROR' instead of the default 'NETWORK_ERROR' string:

await wwmt.get(url, query, headers, { preserveNetworkError: true })
await wwmt.post(url, body, query, headers, { preserveNetworkError: true })

The error's details include the original transport code (for example, ECONNRESET, ECONNREFUSED, or ECONNABORTED), and available system error, address, port, and timeout fields. They also include the destination hostname, HTTP method, configured timeout, elapsed milliseconds across retries, and attempt count. Missing transport fields are omitted.

The error is rebuilt from these fields. It excludes the original request and response objects, headers, body, URL credentials, path, query, and fragment. The message is generated from the transport code rather than copying the original message, which can contain the full URL. Existing retry behavior and HTTP errors are unchanged. A network failure has no HTTP response; these diagnostics identify the transport failure rather than an error returned by the destination service.

Bounded responses and redirects

Version 0.1.18 adds opt-in request options:

const response = await wwmt.post(url, body, query, headers, {
    maxResponseBytes: 1024 * 1024,
    rejectRedirects: true,
    timeout: 10000,
    maxAttemps: 1,
})

maxResponseBytes must be a positive safe integer. It buffers the response, counts bytes after HTTP decompression and before text decoding or JSON parsing, and applies to success and error responses. JSON and text responses use the existing Superagent parsers (missing Content-Type defaults to text); binary and unrecognized MIME responses return a Buffer. Multipart responses are also returned as a bounded Buffer.

Exceeding the limit cancels the response and rejects with an Error whose code is RESPONSE_TOO_LARGE. It is never retried and carries no partial response, request, authentication headers or body. Small HTTP error responses and their existing retry policy are preserved. Malformed bounded JSON rejects with code: RESPONSE_PARSE_ERROR and its HTTP status, without raw response text.

rejectRedirects: true disables following redirects and rejects with an Error whose code is REDIRECT_REJECTED, without forwarding authentication to the redirect target. It can be used independently of the response limit.

Both options are disabled by default; existing callers retain their behavior.

Callers of a route

Version 0.1.19 lets a route name the services that may call it:

app.route('/microservice/ask/chat/stop').post(wwmt.verifyWwServiceToken(['weweb-back']), ctrl.stopGeneration)

The token is checked first, as before. A valid token from an allowed service that is not in the list then gets 403 { message: 'WW_SERVICE_ACCESS_DENIED' }. The list must be a non-empty array of service names, or declaring the route throws. Used directly as a middleware (wwmt.verifyWwServiceToken), it still accepts every service of allowedServices.

In local (WW_ENV=local) the token is still not checked, but a request naming a service outside the list is refused, so a missing caller shows up before deploy.

init takes an optional onAccessDenied({ serviceName, method, path }) hook, called on each of those 403s (path without the query string), to log them:

wwmt.init({
    name: 'weweb-ai',
    seed: process.env.WW_SEED_AI,
    allowedServices: [{ name: 'weweb-back', seed: process.env.WW_SEED_BACK }],
    onAccessDenied: details => log.warn({ message: 'WW_SERVICE_ACCESS_DENIED', ...details }),
})