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

@platosdev/token-mint

v0.1.0

Published

Mint Platos session tokens from your backend — HS256 JWT signed with your entity's serviceSecret.

Downloads

16

Readme

@platosdev/token-mint

Mint Platos session tokens from your backend.

A Platos session token is an HS256 JWT signed with your entity's serviceSecret. This library takes (serviceSecret, claims, ttl) and hands you back the string your frontend can pass to @platosdev/client.

Why this exists

Every customer wiring up Platos previously had to implement HS256 signing against a specific byte layout from scratch. The spec is small but easy to get wrong — base64url padding, claim ordering, signature base construction are all traps. This library bakes in the correct recipe plus test vectors.

Install

npm install @platosdev/token-mint

Use

// server.ts
import { mintSessionToken } from "@platosdev/token-mint";

app.post("/api/platos-session", async (req, res) => {
  const token = mintSessionToken({
    serviceSecret: process.env.PLATOS_ENTITY_SERVICE_SECRET!,
    claims: {
      organizationId: "org_abc",
      projectId:      "prj_def",
      environmentId:  "env_ghi",
      userId:         req.session.userId,
      entityId:       "my-entity",
      userToken:      req.session.userToken, // forwarded to your tool backend
      // Optional — visitor identity. ScopeGuard surfaces these as
      // {{user.name}} / {{user.email}} in prompts and dynamic blocks,
      // and they land in the trace's user_display_name / user_email
      // columns. Plaintext PII; only sign in what your app already
      // collected lawfully.
      userMeta:       { name: req.user.name, email: req.user.email },
    },
    ttlSeconds: 3600, // 1 hour
  });
  res.json({ token });
});
// client.tsx
import { PlatosClient } from "@platosdev/client";

const res = await fetch("/api/platos-session", { method: "POST" });
const { token } = await res.json();

const platos = new PlatosClient({
  baseUrl: "https://platos.example.com",
  sessionToken: token,
  onTokenRefresh: async () => {
    const r = await fetch("/api/platos-session", { method: "POST" });
    const body = await r.json();
    return body.token;
  },
});

Token format

The output is a standard JWT:

base64url(header) . base64url(payload) . base64url(hmac-sha256(header + "." + payload, serviceSecret))

Header:

{ "alg": "HS256", "typ": "JWT" }

Payload example:

{
  "organizationId": "org_abc",
  "projectId": "prj_def",
  "environmentId": "env_ghi",
  "userId": "usr_jkl",
  "entityId": "my-entity",
  "userToken": "opaque-proof-123",
  "iat": 1730000000,
  "exp": 1730003600
}

Validation rules

  • serviceSecret must be ≥ 16 chars. Shorter secrets are refused because the downstream HMAC has no lower-bound enforcement and we don't want customers stumbling into dev sentinel values.
  • ttlSeconds: min 60s, max 7 days. The agent accepts longer-lived tokens but we refuse to mint them here — use onTokenRefresh instead.
  • The four scope fields (organizationId, projectId, environmentId, userId) are required.

Testing / introspection

import { decodeSessionToken } from "@platosdev/token-mint";

const { header, payload, signatureValid } = decodeSessionToken(token, serviceSecret);
// signatureValid === true when the signature matches.

Production traffic is verified by the agent itself — don't call this in a hot path.

Test vectors

See tests/vectors.test.ts in the source repo for deterministic input → output pairs against known secrets. Use these as a reference if you're implementing the same token format in another language.

Licence

Apache 2.0 — see LICENSE. Same as Platos itself.

Source + issues

  • Repo: https://github.com/winsenlabs/platos
  • Package directory: packages/platos-token-mint
  • Issues: https://github.com/winsenlabs/platos/issues
  • Docs: https://platos.dev/docs/auth-modes