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

@openknot-ts/trpc-context

v0.0.6-preview

Published

tRPC request context from OpenKnot actor resolution and trace propagation.

Readme

@openknot-ts/trpc-context

The native tRPC request context: it keeps credentials private, resolves the actor in native middleware before protected procedures enter Flow, and selects trace propagation fields. The root entry works with plain tRPC, without Wire.

API

| Entry | Export | Description | | --- | --- | --- | | @openknot-ts/trpc-context | createTrpcContext({ tracing? }) | Context factory returning TrpcAuthenticationContext. | | | actorAuthentication(resolve) | Native middleware that supplies a verified ctx.actor. | | | authenticationErrorFormatter | Adds public authentication failures to error.data.authenticationError. | | | invokeFlow(ctx, invoke, request?), flowInput(reference, value) | Call a Flow input from a procedure. | | | TrpcContext, TrpcAuthenticationContext, TrpcContextFactory, TrpcContextInput | Types. | | @openknot-ts/trpc-context/wire | trpcContextFactory | The context factory as a unit, using optional(trace). | | | trpcContext | Module for custom adapters that resolve the factory. | | | trpcAuthentication | actorAuthentication over the application's executionActorResolver. |

The Knot server handler and @openknot-ts/trpc-fastify require the factory themselves.

Calling Flow

Routes declared with trpcRouter() receive exposures as native resolvers. Other routers use invokeFlow, which forwards only the context's signal, actor and propagation:

createRole: trpc.procedure.input(createRoleSchema).mutation(({ input, ctx }) => invokeFlow(ctx, createRoleExposure, { input })),
getState: trpc.procedure.query(({ ctx }) => invokeFlow(ctx, getStateExposure)),

A cancelled input becomes CLIENT_CLOSED_REQUEST and an unavailable one (during shutdown) SERVICE_UNAVAILABLE, with the Flow error as cause. Other errors reach tRPC unchanged.

Protected procedures

Supply an actor resolver with actorResolver({ requirements, resolve }) from @openknot-ts/flow/wire or provideAuth0, then use trpcAuthentication:

const router = trpcRouter({
  requirements: { authentication: trpcAuthentication, getProfileExposure },
  routes: ({ trpc, authentication, getProfileExposure }) => {
    const protectedProcedure = trpc.procedure.use(authentication);
    return { me: protectedProcedure.query(getProfileExposure) };
  },
});
  • Missing or invalid credentials answer UNAUTHORIZED before Flow admission, with ActorAuthenticationError as cause. Infrastructure failures stay server errors.
  • Verification is shared within one HTTP request or WebSocket connection. A verification that could not finish, such as an unreachable key set, is retried by the next procedure.
  • Public procedures keep actor: undefined and verify nothing.
  • HTTP and SSE use the bearer header. Only tRPC's WebSocket adapter reads connectionParams.token; an explicit header wins. URL credentials never authenticate an HTTP or SSE request.
  • The middleware protects procedures and subscription admission, not the WebSocket handshake or the expiry of admitted streams.
  • @openknot-ts/auth0-authentication builds the same middleware from Auth0 options.

Augment ExecutionTypes from @openknot-ts/flow with readonly actor: AppActor to type ctx.actor everywhere. propagation carries only the configured propagator's fields (traceparent/tracestate by default).

Custom adapters

TrpcContextInput takes native request headers, info.signal, optional info.connectionParams and info.url (null from the WebSocket adapter), which the standalone Node, Fastify and WebSocket adapters supply.

import { fastifyTRPCPlugin } from "@trpc/server/adapters/fastify";

await server.register(fastifyTRPCPlugin, {
  prefix: "/trpc",
  trpcOptions: { router: app.resolve(router), createContext: app.resolve(trpcContextFactory) },
});

Tests

pnpm --filter @openknot-ts/trpc-context test covers context isolation, the WebSocket gate, verification retries, imports without a host and Fastify integration.