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

fhirstarterjs

v1.0.8

Published

SMART Backend Services auth lifecycle for any FHIR client

Readme

🔥 fhirStarter

SMART on FHIR Backend Services auth lifecycle for any FHIR client.

Install

npm install fhirstarterjs

Usage

This example uses the official fhirclient package as the FHIR client; fhirStarter only manages auth.

import FHIR from "fhirclient"
import fhirStarter from "fhirstarterjs"

const auth = new fhirStarter({
   clientId: "your-client-id",
   privateKey: "./privatekey.pem",
   tokenEndpointUrl: "https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token",
   scopes: ["system/Patient.rs", "system/Observation.rs"],
})

await auth.start()

const client = FHIR.client({
   serverUrl: "https://fhir.epic.com/interconnect-fhir-oauth/api/FHIR/R4",
   tokenResponse: auth.tokenResponse(),
})

const bundle = await client.request("Patient?family=Smith")

auth.start() fetches the first token and starts the proactive refresh loop. auth.tokenResponse() returns a live getter-backed object — fhirclient reads access_token dynamically per request, so it always picks up the latest token.

fhirStarter does not fetch FHIR resources and does not bundle a FHIR client. It manages the auth lifecycle; the FHIR client does the rest.

privateKey can be PEM text, a Buffer from readFileSync, or a path to a PKCS#8 PEM file.

TypeScript types

If needed, you can import the public types directly:

import type { AuthConfig, JwkSet, LiveTokenResponse, Provider } from "fhirstarterjs"

Other FHIR clients

For clients with a bearer token setter (e.g. fhir-kit-client):

const unsubscribe = auth.onRefresh((token) => {
   client.bearerToken = token
})

For raw fetch or any other HTTP client:

const token = await auth.getAccessToken()
const res = await fetch(url, {
   headers: { Authorization: `Bearer ${token}` },
})

API

new fhirStarter(config)

| Member | Returns | Description | |---|---|---| | start() | Promise<void> | Fetch first token and begin proactive refresh loop | | stop() | void | Clear the refresh timer | | token | string \| null | Current valid token, or null if expired | | expiresIn | number \| null | Seconds until actual expiry, or null | | authorizationHeader | string \| null | Bearer <token> or null | | getAccessToken() | Promise<string> | Async valid token with lazy refresh | | tokenResponse() | LiveTokenResponse | Getter-backed token response for fhirclient | | onRefresh(callback) | () => void | Subscribe to token updates — returns unsubscribe | | getJwks() | Promise<JwkSet> | Public JWKS derived from the private key | | fhirStarter.thumbprint(privateKey) | string | RFC 7638 JWK Thumbprint (base64url SHA-256) |

getJwks() strips private key material — host the output JSON at your registered JWKS URL and pass that URL as jwksUrl so the JWT jku header is set automatically.

Thumbprint

Derive a deterministic kid from a private key without instantiating the class:

import fhirStarter from "fhirstarterjs"

const kid = fhirStarter.thumbprint("./privatekey.pem")
console.log(kid) // base64url SHA-256 of the canonical RSA public JWK

This implements RFC 7638 — the SHA-256 of the sorted canonical JWK members {e, kty, n}, base64url-encoded. Use it as the keyId when registering your JWKS.

JWKS

Some SMART Backend Services registrations require a public JWKS URL when using jku. Generate it from the same private key you use for auth:

import { writeFileSync } from "node:fs"
import fhirStarter from "fhirstarterjs"

const auth = new fhirStarter({
   clientId: "your-client-id",
   privateKey: "./privatekey.pem",
   tokenEndpointUrl: "https://fhir.epic.com/interconnect-fhir-oauth/oauth2/token",
   scopes: ["system/Patient.rs"],
   keyId: "my-key-id",
   jwksUrl: "https://example.com/.well-known/jwks.json",
})

// No need to call auth.start() — getJwks() only needs the private key.
const jwks = await auth.getJwks()
writeFileSync("./jwks.json", JSON.stringify(jwks, null, 3))

Host jwks.json at the exact URL you register with your authorization server, then pass that URL as jwksUrl. If you set keyId, the generated key includes kid, and signed JWTs use the same kid header.

Compatibility

tokenResponse() is designed for fhirclient.request(). If a client copies the token at construction time rather than reading it per-request, use onRefresh() to update or recreate that client instead. If fhirclient clears its internal state after a 401, recreate the client instance with auth.tokenResponse().

Scripts

| Command | What | |---|---| | npm run check | tsc --noEmit | | npm run build | Compile to dist/ |

Notes

  • Call auth.start() to fetch the first token and begin the proactive refresh loop — call auth.stop() during shutdown in long-running processes
  • Tokens are cached with separate refresh and expiry timestamps — if a refresh fails but the token is not yet expired, the old token remains usable
  • Concurrent callers share a single in-flight token refresh
  • JWT assertions are signed RS384, expire after 5 minutes
  • Requires Node 20+, a PKCS#8 RSA key, and SMART Backend Services scopes