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

@nodii/db-rls

v0.14.0

Published

Three-pool RLS dispatch + GUC-set + entry-point helpers + RLS policy DDL generator for the Nodii microservice stack. Polyglot per D159 (TS + Python + Go). Spec: planning hub docKey=db-rls.

Downloads

6,936

Readme

@nodii/db-rls

Three-pool RLS dispatch + GUC binding + policy DDL generation for the Nodii microservice stack.

Spec: https://planning.dev.nucleus-cloud.in/api/v1/feature-docs?serviceId=nodii-libs&docKey=db-rls

Unforgeable tenant binding

On the authenticated path the tenant is not a parameter. It is read from a request-scoped verified-claims context that auth middleware binds once:

// ONCE, in auth middleware, immediately after JWT verification.
app.use(async (c, next) => {
  const claims = await verifyJwt(c.req.header("authorization"));
  return runWithVerifiedTenantClaims(
    { userId: claims.sub, tenantId: claims.tenant_id },
    () => next(),
  );
});

// Everywhere else — no tenant, and nowhere to put one.
const rows = await withUserContextDbPostgresJs(async (db) =>
  db.select().from(invoices),
);

withUserContext / withUserContextDb / withUserContextDbPostgresJs take the callback as their only argument. autoDispatch(fn) is the same path; autoDispatch({ systemTenantId }, fn) is the system leg.

Why: the previous shape, withUserContext({ userId, tenantId }, fn), let a handler pass a request-derived tenant instead of the verified claim, and RLS accepted app.tenant_id without ever proving the principal held it. Membership was checked once at login in nodii-auth, and nowhere near the database.

Workers, cron, S2S and webhooks are unaffected — they have a legitimately resolved tenant and no user claim, and keep their explicit parameter: withSystemContext({ tenantId }, fn). Migrations use withOwnerContext (NODII_ENV=migrate-gated); Nodii staff cross-tenant access uses withPlatformOpsContext (RBAC-gated, a different predicate).

There is no escape hatch — no option to override the tenant. Binding is refused if claims are already bound (a handler cannot rebind to a different tenant), bound claims are copied and frozen (they cannot be mutated after the fact), and a blank / missing / non-string userId or tenantId is refused at bind time rather than binding an empty GUC that reads as "no rows". With no claims bound the authenticated helpers throw NoVerifiedTenantClaims before acquiring a pool — never a default, never a fallback to a passed value.

The system pool is fenced against authenticated fall-through

The services-pool predicate is the bare tenant_id = auth.get_tenant_id() — no membership proof. So an authenticated request that falls through to withSystemContext({ tenantId: req.body.tenantId }, fn) re-opens exactly the forgery the claims binding closes: the handler supplies the tenant, and nothing checks the principal holds it. That fall-through is the seam where the ₹250,000 cross-tenant refund reproduced.

Therefore, inside a claims-bound request (hasVerifiedTenantClaims() is true), withSystemContext / withSystemContextDb / withSystemContextDbPostgresJs (and autoDispatch's system leg) throw SystemContextUnderClaimsRefused — before any pool is acquired — unless the caller passes an explicit, non-blank { reason }:

// Deliberate system work inside a request — named, counted, greppable.
await withSystemContext(
  { tenantId, reason: "outbox-emit: invoice.settled fan-out" },
  async (tx) => { ... },
);

A sanctioned escape is emitted to telemetry as db_rls.cross_pool_nesting_total{outer="authenticated", inner="services", reason}, so every crossing is observable. Outside any claims-bound context (boot, cron, workers, S2S, webhooks) nothing changes — no reason is needed and the helpers behave exactly as before. That compat property is what keeps this fence from breaking every worker in the fleet.

Full migration steps, including the createSecureClient before/after, are in .changeset/db-rls-unforgeable-tenant-binding.md.