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

@superwall/host

v2.7.2

Published

A Superwall paywall host for browsers and tests: answers the paywall's ping the way the SDKs do and replies to its events with the SDK's messages.

Readme

What this is not

It is not a paywall, and it never runs inside one. It is not a mock: every message it sends is a message a real host sends, in the order a real host sends it. It is not React.

Install

npm install @superwall/host

Hosting an iframe

import { createWindowHost, defaultDevice, DEFAULT_USER, DEFAULT_PARAMS } from "@superwall/host";

const iframe = document.querySelector("iframe");
iframe.src = `${snapshotUrl}?transport=editor`;

const { host, detach } = createWindowHost({
  target: iframe.contentWindow,
  state: {
    paywallId: "123",
    paywallIdentifier: "my_paywall",
    device: defaultDevice(),
    user: DEFAULT_USER,
    params: DEFAULT_PARAMS,
    products: [{ reference: "primary", productId: "com.app.annual", variables: { price: "$89.99" } }],
  },
  delegate: {
    event: (message) => log(message),
    purchase: async (product) => (await ask(`Purchase ${product.reference}?`)) ? "completed" : "abandoned",
    restore: async () => ((await ask("Restore?")) ? "restored" : "failed"),
    close: () => toast("closed"),
    openUrl: (url, kind) => toast(`${kind}: ${url}`),
    custom: (data) => toast(data),
    customPlacement: (name) => toast(name),
    permission: async (type) => ((await ask(`Grant ${type}?`)) ? "granted" : "denied"),
    callback: async () => ({ status: "success" }),
  },
});

host.update({ device: { interfaceStyle: "Light" } });

The paywall pings on its own once it loads. The host answers with one envelope, in this order: template_variables, experiment, products, template_substitutions_prefix, paywall_open. That is the web host's order (web-paywalls/src/controller/index.ts); the iOS SDK sends the same set.

update(patch) merges into the state and re-sends only what changed: template_variables for device, user, params or product variables; products when a product id changed; experiment when it changed; template_substitutions_prefix when introductory offer eligibility flipped. That is the visual editor's granularity.

Replies

| Paywall sends | Delegate decides | Host replies | | ------------------------------------------------------------------------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | purchase | completed / abandoned / failed | transaction_start first; then transaction_complete (+ freeTrial_start when eligible and the product has trial days), transaction_abandon, or transaction_fail | | restore | restored / failed | restore_start; then transaction_restore + restore_complete, or restore_fail | | close | — | paywall_close | | request_permission | a permission status | permission_result | | request_callback | { status, data? } | callback_result | | user_attribute_updated | — | nothing; merged into the host's user for the next template_variables | | open_url, open_url_external, open_deep_link, custom, custom_placement | called | nothing | | anything else | event() only | nothing |

Every message the paywall sends reaches delegate.event first.

In-process transport

createHostTransport({ state, delegate }) returns an ITransport plus the host behind it. Hand the transport to a runtime session and the session is hosted exactly as it would be by an iframe host, with no window involved. Replies are delivered on a microtask, or after latencyMs when set.

Defaults

@superwall/host/defaults carries the values a host falls back to when it has no live data: the API's default device sample (UserDataService.ts in the dashboard repo, the device-properties-sample endpoint's answer for an app with no traffic) plus its derived time fields, the default user sample, the default placement params, and the visual editor's example product (paywall-preview-variables.ts FALLBACK_PRODUCT_EXAMPLE). withoutTrial strips every trial key, which is what the editor does for a slot it has no product for. Change these only when their sources change.

Layout

src/
  state.ts        HostState: paywall identity, device, user, params, products,
                  introductory offer eligibility, experiment; merge helpers
  messages/       one builder per to_paywall message, grouped by concern:
                  ping.ts (the burst), transaction.ts, restore.ts, results.ts
  delegate/       HostDelegate (types.ts) and the recording delegate for tests
  host/           createPaywallHost (index.ts) routes paywall events; flows.ts
                  holds the purchase, restore, permission and callback flows
  adapters/       window.ts (iframe over postMessage), transport.ts (in-process
                  ITransport for sessions and tests)
  defaults/       device.ts, user.ts, params.ts, product.ts: values copied from
                  the dashboard, see Defaults above

Sources of every default (dashboard repo unless noted), so a diff is one grep:

| Constant | Copied from | | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- | | DEFAULT_DEVICE, derivedDeviceProperties | packages/api/src/v2/repository/users/UserDataService.ts (EXAMPLE_DEVICE_EVENT, derivedDeviceProperties) | | DEFAULT_USER | same file, EXAMPLE_USER_PROPERTIES | | DEFAULT_PARAMS | this repo, packages/superwall/src/preview/project.ts SAMPLE_DEFAULTS.params, what superwall dev always showed | | EXAMPLE_PRODUCT_VARIABLES, withoutTrial | apps/web2/src/lib/paywall-preview-variables.ts (FALLBACK_PRODUCT_EXAMPLE, FALLBACK_PRODUCT_EXAMPLE_NO_TRIAL) |

Develop

Lives in the superwall/superwall monorepo; read its AGENTS.md first.

bun run test
bun run typecheck

The message builders are tested against the fixtures in @superwall/protocol's test/fixtures/host/, which are literal captures from the production hosts.

License

Functional Source License (FSL-1.1-ALv2).