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

@chiahq/widget

v0.0.5

Published

Embeddable subscription widget for Chia

Readme

@chiahq/widget

Embeddable subscription checkout for mobile money. Drop a single script tag onto any website and let customers subscribe to your plans.

By default the widget talks to the hosted Chia platform using your publishable key - the fastest path to live recurring billing. Running your own backend instead? Point apiBaseUrl at any server that implements the same widget endpoints and the hosted platform drops out of the picture entirely.

Installation

CDN (recommended for most sites)

<script src="https://cdn.jsdelivr.net/npm/@chiahq/widget/dist/chia-widget.min.js"></script>

The script exposes a global Chia object.

npm

npm install @chiahq/widget
import { init } from "@chiahq/widget";

Quick Start

  1. Create a publishable key in your Chia dashboard under Settings > API Keys.
  2. Add the widget to your page:
<div id="subscribe-widget"></div>
<script src="https://cdn.jsdelivr.net/npm/@chiahq/widget/dist/chia-widget.min.js"></script>
<script>
  Chia.init({
    publishableKey: "pk_live_your_key_here",
    container: "#subscribe-widget",
    planId: "your-plan-id",
    onSubscribed: function (result) {
      console.log("Subscribed:", result.subscriberId);
    },
  });
</script>

Display

The widget always renders inline, immediately, inside the container element you point it at - there is no separate "hidden until triggered" mode. If you want a modal-style presentation, call widget.open() before or shortly after init() so the overlay chrome (backdrop and close button) is applied on the widget's next render, and pair it with your own CSS if you need the container hidden until then. See Instance Methods for what open() and close() actually do.

Chia.init({
  publishableKey: "pk_live_...",
  container: "#my-container",
  planId: "plan-uuid",
});

Configuration

| Option | Type | Required | Description | | --- | --- | --- | --- | | publishableKey | string | Yes | Your publishable API key (pk_test_* or pk_live_*) | | apiBaseUrl | string | No | Backend base URL. Defaults to https://api.usechia.com; point it at your own server to run without the hosted platform | | container | string \| HTMLElement | Yes | CSS selector or DOM element to mount into | | planId | string | No | Show a specific plan by ID. Omit to show a plan selector | | planSlug | string | No | Show a specific plan by slug. Alternative to planId | | prefill | { phone?: string; name?: string } | No | Pre-fill the subscription form | | theme | ThemeOverrides | No | Visual customization (see below) | | apiBaseUrl | string | No | Override the API endpoint. Defaults to https://api.usechia.com | | redirectUrls | { onSuccess?: string; onFailure?: string; onCancellation?: string } | No | Override the plan's post-payment redirect behavior | | onReady | () => void | No | Fired when the widget has loaded its configuration | | onSubscribed | (result) => void | No | Fired when a subscription succeeds | | onError | (error) => void | No | Fired on any error | | onClose | () => void | No | Fired when the widget is closed |

Events and Callbacks

onSubscribed

Called when the subscription payment succeeds. Receives a result object:

interface SubscribeResult {
  id: string;           // Subscription intent ID
  subscriberId: string; // The new subscriber's ID
  paymentStatus: string;
  nextAction: NextAction | null;
}

Note: if nextAction.type is "redirect", the widget does not navigate the customer anywhere on its own - nextAction.redirectUrl is not currently acted on. It shows a generic "complete your payment with your provider" message and keeps polling. This is a known gap; do not rely on the widget to open a redirect URL for you.

onError

Called on any error during loading or subscription. It is not called when polling for payment status times out (see Payment Safety below) - only for outright request failures such as a failed subscribe() call or a failed config load.

interface WidgetError {
  message: string;
  code?: string;
}

onClose

Called when widget.close() runs (close button, backdrop click if you've applied the overlay via open(), or calling close() directly).

onReady

Called once the widget has fetched its configuration and is ready to display.

Payment Safety

Duplicate submits

The submit button disables itself the instant it's tapped, and handleSubscribe also guards re-entrancy internally, so a rapid double-tap (or an Enter-key double-submit, which bypasses a disabled button's click handler) can never send two subscribe requests and create two payments.

Polling timeout

The widget polls for payment status every 3 seconds for up to 120 seconds (POLL_TIMEOUT_MS). If 3 consecutive polls fail (network trouble), it shows a small "Having trouble connecting. Still checking..." note without leaving the processing screen, and keeps polling.

If the full 120 seconds elapses without a terminal status, the widget stops polling and shows an indeterminate "timeout" screen with a "Check again" button that resumes polling.

This timeout is not a payment failure. The server is the authority on whether a payment has actually failed or expired - it reports expired explicitly when that happens. A client-side polling timeout only means the widget lost contact with the server; the payment may still complete or may already have succeeded. onError is never called for this path, and the widget never shows "failed" text for it. Do not treat this state as a failed payment - do not refund, cancel, or re-charge a customer based on it alone. Check the subscription/payment status from your backend before taking any action.

close() vs destroy()

Both stop polling immediately, so no further status requests are made after either is called. close() clears the currently rendered widget and fires onClose - use it when you want to dismiss the widget but may re-initialize or reuse the container later. destroy() additionally tears down the widget's shadow root - use it when removing the widget from the page for good (for example, in a React useEffect cleanup function).

Instance Methods

const widget = Chia.init({ ... });

widget.open();    // Apply overlay chrome (backdrop, close button) on the next render
widget.close();   // Stop polling, clear the rendered widget, and fire onClose
widget.destroy(); // Stop polling and remove the widget's shadow root entirely

widget.update({
  planId: "new-plan-id",           // Switch to a different plan
  theme: { primaryColor: "#000" }, // Update theme at runtime
});

Customization

Theme Overrides

Pass a theme object to customize the widget's appearance:

Chia.init({
  publishableKey: "pk_live_...",
  container: "#widget",
  theme: {
    primaryColor: "#7c3aed",
    borderRadius: "12px",
    fontFamily: "Inter, sans-serif",
  },
});

| Property | Default | Description | | --- | --- | --- | | primaryColor | #2563eb | Buttons, focus rings, and accent color | | borderRadius | 8px | Corner radius for cards and inputs | | fontFamily | System font stack | Font family for all widget text |

CSS Variables

The widget uses Shadow DOM for style isolation. The following CSS custom properties are set on the :host and can be used if you need deeper customization by passing a theme:

  • --chia-primary - primary/accent color
  • --chia-radius - border radius
  • --chia-font - font family
  • --chia-gray-50 through --chia-gray-900 - gray scale
  • --chia-green - success color
  • --chia-red - error color

TypeScript Support

The package includes full type definitions. All types are exported from the package root:

import { ChiaWidget, init } from "@chiahq/widget";
import type {
  ChiaWidgetConfig,
  ThemeOverrides,
  SubscribeResult,
  WidgetError,
  Plan,
  IntentStatus,
} from "@chiahq/widget";

Browser Compatibility

The widget works in all modern browsers:

  • Chrome/Edge 80+
  • Firefox 80+
  • Safari 14+
  • iOS Safari 14+
  • Chrome for Android 80+

Requires fetch, ShadowRoot, and Promise support. No polyfills are needed for the browsers listed above.

Development

pnpm install
pnpm dev    # watch mode with rollup
pnpm build  # production build to dist/

Build outputs:

  • dist/chia-widget.js - IIFE bundle (use via <script> tag)
  • dist/chia-widget.min.js - Minified IIFE bundle (CDN)
  • dist/index.js - ES module (use via import)
  • dist/index.d.ts - TypeScript declarations

License

Business Source License 1.1 (BUSL-1.1). You may use this package in production only when it connects to the official Chia platform. Non-production use is otherwise permitted, and the license converts to MIT on the Change Date. See LICENSE for the full terms, including the Additional Use Grant.