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

@affinity-health/elements

v1.1.1

Published

Secure embedded clinical components for the Affinity platform API.

Readme

Affinity Elements

Affinity Elements renders secure Affinity clinical workflows inside a platform application.

The platform authenticates its user. The platform backend creates a short-lived component session. The browser receives only the single-use component client secret.

Install

bun add @affinity-health/elements

Before you start

Your platform backend must:

  1. Authenticate the current user.
  2. Resolve the Affinity user, practice, and verified provider mapping.
  3. Call POST /v1/component-sessions.
  4. Return only clientSecret to the intended browser.

Never put an Affinity API key in browser or mobile code.

JavaScript

import { initializeAffinity } from "@affinity-health/elements";

const affinity = initializeAffinity({
  fetchClientSecret: async () => {
    const response = await fetch("/api/affinity/component-session", {
      credentials: "include",
      method: "POST",
    });

    if (!response.ok) {
      throw new Error("Could not create an Affinity component session");
    }

    const session = await response.json();
    return session.clientSecret;
  },
});

const composer = affinity.create("prescription-composer");
const mounted = composer.mount("#affinity-prescription-composer", {
  onLoadError(error) {
    console.error(error);
  },
  onReady() {
    console.log("Affinity is ready");
  },
  onEvent(event) {
    if (event.type === "order.submitted") {
      console.log(event.orderId, event.fulfillmentIds);
    }
  },
});

// Call mounted.destroy() when the owning view is removed.

React

import { AffinityProvider, PrescriptionComposer } from "@affinity-health/elements/react";

export function Prescribe() {
  return (
    <AffinityProvider fetchClientSecret={fetchClientSecret}>
      <PrescriptionComposer
        onLoadError={(error) => {
          console.error(error);
        }}
        onReady={() => {
          console.log("Affinity is ready");
        }}
        onOrderDraftCreated={({ orderId, prescriptionIds }) => {
          console.log(orderId, prescriptionIds);
        }}
        onOrderSigned={({ orderId, prescriptionIds }) => {
          console.log(orderId, prescriptionIds);
        }}
        onOrderSubmitted={({ orderId, fulfillmentIds }) => {
          console.log(orderId, fulfillmentIds);
        }}
      />
    </AffinityProvider>
  );
}

Keep fetchClientSecret stable in React. Use useCallback when the function depends on component state.

Staging

Set the staging Connect URL while you test a staging integration:

const affinity = initializeAffinity({
  connectUrl: "https://connect-staging.joinaffinityai.com",
  fetchClientSecret,
});

The default URL is https://connect.joinaffinityai.com.

Appearance

Use approved appearance variables:

const affinity = initializeAffinity({
  appearance: {
    theme: "light",
    variables: {
      borderRadius: "10px",
      colorBackground: "#ffffff",
      colorBorder: "#d8dee8",
      colorPrimary: "#2563eb",
      colorPrimaryText: "#ffffff",
      colorText: "#172033",
      fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif",
    },
  },
  fetchClientSecret,
});

Affinity controls the clinical layout, behavior, accessibility, and security. The package does not accept arbitrary CSS, selectors, scripts, or remote font URLs.

Events

The prescription composer sends patient-order events:

| Event | Payload | Meaning | | --------------------- | ---------------------------- | ------------------------------------------------------------------------ | | order.draft_created | orderId, prescriptionIds | Affinity created one patient order and its unsigned prescription drafts. | | order.signed | orderId, prescriptionIds | The provider signed every prescription in the order inside Affinity. | | order.submitted | orderId, fulfillmentIds | Affinity submitted one pharmacy fulfillment for each prescription. |

Arrays preserve the complete order membership. Do not assume an order contains one prescription or one fulfillment. Use browser events for interface updates. Use signed webhooks and the Order API for authoritative state.

Destroy the mounted component when its owning view unmounts. Create a new component session before the next mount. Client secrets are single-use and cannot refresh or reconnect a previous iframe.

Security

  • Add the exact parent origin to the matching platform mode settings.
  • Create a new component session immediately before you mount the element.
  • Do not put a client secret in a URL, log, analytics event, or persistent storage.
  • Do not send clinical fields or keystrokes through parent-window messages.

See the Affinity platform documentation.