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

@o3co/auth.policy-verifier.server

v0.3.1

Published

Express HTTP server for auth.policy-verifier. Provides `createApp` to assemble the application from modules and config, and `POST /verify` for authorization decisions.

Downloads

411

Readme

@o3co/auth.policy-verifier.server

Express HTTP server for auth.policy-verifier. Provides createApp to assemble the application from modules and config, and POST /verify for authorization decisions.

Install

npm install @o3co/auth.policy-verifier.server

Public API

createApp

interface CreateAppOptions {
  pathResolver: PathResolver;
  config: AppConfig;
  modules: Module[];
}

function createApp(options: CreateAppOptions): Promise<express.Express>

Assembles and returns a configured Express application. Does not start listening — call app.listen(...) separately.

Steps performed:

  1. Creates Registry instances for attribute collector, rule collector, and resource parser factories.
  2. Calls mod.init(context) for each module in order, allowing each to register factory functions.
  3. Instantiates attribute collectors and rule collectors from config.attribute.collectors and config.rule.collectors by looking up the registered factory for each collector name.
  4. Instantiates the resource parser from config.resource.parser.
  5. Mounts GET /healthcheck and POST /verify under config.http.pathPrefix.
  6. Returns the configured express.Express instance.

pathResolver must be import.meta.resolve (or a compatible resolver) from the composition root. It is passed to modules that need to resolve module-relative paths.

createVerifyRouter

interface VerifyRouterConfig {
  jwt: { secret: string; validate: boolean };
  resourceParser: ResourceParser;
  attributePipeline: AttributePipeline;
  rulePipeline: RulePipeline;
}

function createVerifyRouter(config: VerifyRouterConfig): express.Router

Returns an Express Router that handles POST /verify. createApp calls this internally; use it directly only if you need to mount the router independently.

Request flow:

  1. Extract Authorization: <type> <token> header. Returns 401 if missing.
  2. If validate is true: verify the JWT with HS256 using secret. Returns 401 on failure.
  3. If validate is false: decode the JWT without verification. Returns 401 if the token is malformed.
  4. Parse req.body.resource with resourceParser; read req.body.action and req.body.context.
  5. Include x-request-id header in CollectorContext.headers if present (collectors can forward it to upstream calls they make).
  6. Run attributePipeline.collect and rulePipeline.collect in parallel; call evaluate.
  7. Return 200 { decision: "allow" } or 403 { decision: "deny", code, message }.
  8. Return 500 { decision: "deny", code: "internal_error" } on unexpected errors.

AppConfigSchema / AppConfig

const AppConfigSchema = z.object({
  http: z.object({
    hostname: z.string().default("0.0.0.0"),
    port: z.coerce.number().default(3000),
    pathPrefix: z.string().default(""),
  }),
  oauth: z.object({
    jwt: z.object({
      secret: z.string(),
      validate: z.boolean().default(true),
    }),
  }),
  attribute: z.object({
    collectors: z.array(z.object({ collector: z.string() }).passthrough()),
  }),
  rule: z.object({
    collectors: z.array(z.object({ collector: z.string() }).passthrough()),
  }),
  resource: z.object({
    parser: z.string().default("DotNotationResourceParser"),
  }),
});

type AppConfig = z.infer<typeof AppConfigSchema>;

Each entry in attribute.collectors and rule.collectors requires a collector field (the registered factory name). Additional fields are passed through to the factory as configuration.

POST /verify

Request

POST /verify HTTP/1.1
Authorization: Bearer <jwt>
Content-Type: application/json
x-request-id: <optional>

{
  "resource": "project:1",
  "action": "read",
  "context": {}
}

Response — allow

HTTP/1.1 200 OK

{ "decision": "allow" }

Response — deny

HTTP/1.1 403 Forbidden

{ "decision": "deny", "code": "<code>", "message": "<message>" }

Response — unexpected error

HTTP/1.1 500 Internal Server Error

{ "decision": "deny", "code": "internal_error" }

Usage Example

import { resolve } from 'node:path'
import { parseFile } from '@o3co/ts.hocon'
import { validate } from '@o3co/ts.hocon/zod'
import { createApp, AppConfigSchema } from '@o3co/auth.policy-verifier.server'
import { builtinCollectorsModule } from '@o3co/auth.policy-verifier.builtins'

const config = validate(
  parseFile(resolve(import.meta.dirname, '../config/application.conf')),
  AppConfigSchema,
)

const app = await createApp({
  pathResolver: import.meta.resolve,
  config,
  modules: [builtinCollectorsModule],
})

app.listen(config.http.port, config.http.hostname, () => {
  console.log(`listening on ${config.http.hostname}:${config.http.port}`)
})

To add a custom module, implement Module from @o3co/auth.policy-verifier.core and pass it in the modules array:

import type { Module } from '@o3co/auth.policy-verifier.core'

const customModule: Module = {
  name: 'custom',
  async init(context) {
    context.attributeCollectorRegistry.register(
      'MyRoleCollector',
      (config) => new MyRoleCollector(config),
    )
  },
}

const app = await createApp({
  pathResolver: import.meta.resolve,
  config,
  modules: [builtinCollectorsModule, customModule],
})

See Also