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

@napplet/nub

v0.5.0

Published

All 12 napplet NAP domains (relay, storage, ifc, keys, theme, media, notify, identity, config, resource, connect, class) as layered subpath exports

Readme

@napplet/nub

All 12 napplet NAP domains (relay, storage, ifc, keys, theme, media, notify, identity, config, resource, connect, class) as layered subpath exports. The package name remains @napplet/nub for compatibility.

Install

pnpm add @napplet/nub

@napplet/nub has no root export — consumers MUST import from a domain subpath. See Subpath Patterns for the three available entry-point shapes per domain.

Quick Start

// Barrel — types + shim installer + sdk helper together
import { installRelayShim, relaySubscribe, RelaySubscribeMessage } from '@napplet/nub/relay';
// Granular — types only (zero runtime cost)
import type { IfcEventMessage } from '@napplet/nub/ifc/types';

Shells that only need to mount a NUB import the shim subpath directly:

// Granular — shim installer only (no SDK helpers bundled)
import { installStorageShim } from '@napplet/nub/storage/shim';

Napplet authors that want a typed wrapper over window.napplet without the installer pull from the SDK subpath:

// Granular — SDK helpers only (no shim installer bundled)
import { notifySend } from '@napplet/nub/notify/sdk';

End-to-end: a napplet subscribes to a relay stream using the SDK helper, while the shell mounts the matching installer on the napplet window:

// In the napplet (runs inside the sandboxed iframe)
import { relaySubscribe } from '@napplet/nub/relay/sdk';

const sub = relaySubscribe(
  [{ kinds: [1], limit: 20 }],
  {
    onEvent: (event) => console.log('note', event),
    onEose: () => console.log('caught up'),
  },
);

// Later, tear down the subscription
sub.close();
// In the shell (runs on the host page)
import { installRelayShim } from '@napplet/nub/relay/shim';

installRelayShim(nappletWindow, {
  // shell-provided relay pool, ACL, etc.
});

12 Domains

Each domain is an independent subpath. Barrel imports bundle types + shim installer + SDK helpers; granular subpaths isolate each surface.

| Domain | Barrel | Types | Shim | SDK | Purpose | |--------|--------|-------|------|-----|---------| | relay | @napplet/nub/relay | @napplet/nub/relay/types | @napplet/nub/relay/shim | @napplet/nub/relay/sdk | Nostr relay proxy (subscribe/publish/query) | | storage | @napplet/nub/storage | @napplet/nub/storage/types | @napplet/nub/storage/shim | @napplet/nub/storage/sdk | Scoped key-value storage | | ifc | @napplet/nub/ifc | @napplet/nub/ifc/types | @napplet/nub/ifc/shim | @napplet/nub/ifc/sdk | Inter-frame communication (topic pub/sub) | | keys | @napplet/nub/keys | @napplet/nub/keys/types | @napplet/nub/keys/shim | @napplet/nub/keys/sdk | Keyboard bindings + action registration | | theme | @napplet/nub/theme | @napplet/nub/theme/types | — | — | Read-only shell theme access (types-only today) | | media | @napplet/nub/media | @napplet/nub/media/types | @napplet/nub/media/shim | @napplet/nub/media/sdk | Ownership-aware media sessions + playback | | notify | @napplet/nub/notify | @napplet/nub/notify/types | @napplet/nub/notify/shim | @napplet/nub/notify/sdk | Shell-rendered notifications | | identity | @napplet/nub/identity | @napplet/nub/identity/types | @napplet/nub/identity/shim | @napplet/nub/identity/sdk | Read-only user queries (pubkey, metadata) | | config | @napplet/nub/config | @napplet/nub/config/types | @napplet/nub/config/shim | @napplet/nub/config/sdk | Declarative per-napplet config (schema-driven) | | resource | @napplet/nub/resource | @napplet/nub/resource/types | @napplet/nub/resource/shim | @napplet/nub/resource/sdk | Sandboxed byte fetching (https/blossom/nostr/data) via bytes(url) → Blob | | connect | @napplet/nub/connect | @napplet/nub/connect/types | @napplet/nub/connect/shim | @napplet/nub/connect/sdk | User-gated direct network access (state-only; no wire — grants flow via CSP + discovery meta tag) | | class | @napplet/nub/class | @napplet/nub/class/types | @napplet/nub/class/shim | @napplet/nub/class/sdk | Shell-assigned integer class via class.assigned wire envelope; exposes window.napplet.class |

Subpath Patterns

Each domain exposes up to three patterns (four including the barrel). Pick the shape that matches what your code actually needs:

  • Barrel (@napplet/nub/<domain>): re-exports types + shim installer + SDK helpers together. Most ergonomic for consumers that want everything a domain offers.
  • Types-only (@napplet/nub/<domain>/types): pure TypeScript types, zero runtime code. Ideal for shells writing typed message handlers without shipping the shim installer.
  • Shim (@napplet/nub/<domain>/shim): installer + message handlers. For shell/host code mounting a NUB into the napplet window.
  • SDK (@napplet/nub/<domain>/sdk): named-function helpers (e.g., relaySubscribe, storageGet). For napplet consumer code that wants a typed wrapper over window.napplet.

Tree-Shaking Contract

  • @napplet/nub publishes with sideEffects: false
  • Every subpath in the exports map is a discrete entry point; a bundler importing only @napplet/nub/relay/types produces zero bytes from the other 8 domains
  • Verified end-to-end in Phase 121 with a minimal-consumer smoke test

The exports map in package.json declares 46 entry points:

  • 12 domain barrels (@napplet/nub/<domain>)
  • 12 granular types entries (@napplet/nub/<domain>/types)
  • 11 granular shim entries (theme omitted — see Theme Exception)
  • 11 granular sdk entries (theme omitted — see Theme Exception)

Each entry maps to its own pre-built .js + .d.ts pair under dist/<domain>/<surface>.{js,d.ts}. No root . key exists, and there is no top-level main/module/types field — attempting import '@napplet/nub' fails with ERR_PACKAGE_PATH_NOT_EXPORTED by design.

Theme Exception

Theme is types-only today — only @napplet/nub/theme (barrel, re-exports ./types) and @napplet/nub/theme/types exist. There is no @napplet/nub/theme/shim or @napplet/nub/theme/sdk entry in the exports map. Shell-side theme handling stays in the host shell; this may change in a future milestone if a theme shim/sdk surface is added upstream.

Resource NUB (v0.28.0)

The resource domain ships in v0.28.0 alongside the milestone of browser-enforced resource isolation. It defines a single scheme-pluggable byte-fetching primitive:

import { bytes, bytesAsObjectURL } from '@napplet/nub/resource/sdk';

// Fetch any URL the shell accepts under its policy. URL space is scheme-pluggable.
const blob: Blob = await bytes('https://example.com/avatar.png');

// Synchronous handle for <img src> use; revoke when done.
const handle = bytesAsObjectURL('blossom:sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855');
imgEl.src = handle.url;
// later
handle.revoke();

Four canonical schemes are defined in the spec:

  • data: — RFC 2397, decoded inside the napplet shim with zero shell round-trip
  • https: — shell-side network fetch under the default resource policy (private-IP block list at DNS time, MIME byte-sniffing, size cap, timeout, rate limit, redirect cap)
  • blossom:sha256:<hex> — Blossom hash → bytes; shell verifies hash before delivery
  • nostr:<bech32> — single-hop NIP-19 resolution against the shell's relay pool

Errors arrive as one of 8 typed codes: not-found, blocked-by-policy, timeout, too-large, unsupported-scheme, decode-failed, network-error, quota-exceeded.

See NAP-RESOURCE for the normative spec, the default shell resource policy, and the SVG rasterization MUSTs.

Identity NAP

The identity domain is read-only. It exposes the shell-user pubkey and public identity data, but it does not sign, encrypt, or decrypt. Startup code should take one snapshot with getPublicKey() and then subscribe to shell-pushed identity.changed updates instead of polling while a signer connects.

import '@napplet/shim';

const pubkey = await window.napplet.identity.getPublicKey(); // "" when signed out

const sub = window.napplet.identity.onChanged((nextPubkey) => {
  if (nextPubkey === '') {
    // signed out or signer disconnected
    return;
  }
  // identity-dependent work can refresh here
});

The wire surface includes identity.changed as a shell-to-napplet push message with { pubkey } and no correlation id. The public key shape matches identity.getPublicKey.result: a hex pubkey when connected, or "" when no user/signer is connected.

See the NAP-IDENTITY draft spec for the current read-only contract.

Connect + Class NUBs (v0.29.0)

v0.29.0 adds two subpaths that work together to express user-gated direct network access and shell-assigned security class.

@napplet/nub/connect

State-only NUB — NO postMessage wire. Grants flow through the runtime CSP the shell serves with the napplet HTML, plus a shell-injected <meta name="napplet-connect-granted" content="<space-separated-origins>"> tag read synchronously by the napplet shim at install time.

import type { NappletConnect } from '@napplet/nub/connect/types';
import { installConnectShim, normalizeConnectOrigin } from '@napplet/nub/connect';

// Napplet-side (runs inside the sandboxed iframe)
// The shim populates window.napplet.connect synchronously at install time.
if (window.napplet.connect.granted) {
  const res = await fetch(`${window.napplet.connect.origins[0]}/items`, { method: 'POST', body: '{}' });
}

// Build-side / shell-side (shared origin validator; throws on invalid input)
const o = normalizeConnectOrigin('https://api.example.com');   // 'https://api.example.com'

NappletConnect is { readonly granted: boolean; readonly origins: readonly string[] }. Default on shells that do not implement nap:connect, on denied prompts, or pre-injection: { granted: false, origins: [] } (never undefined).

@napplet/nub/class

Wire-driven NAP with a single shell -> napplet envelope class.assigned ({ type: 'class.assigned'; id: string; class: number }). Sent at iframe-ready time, exactly once per napplet lifecycle. The napplet shim writes the received integer to window.napplet.class via a defineProperty getter.

import type { ClassAssignedMessage, NappletClass } from '@napplet/nub/class/types';
import { installClassShim, getClass } from '@napplet/nub/class';

// Napplet-side (runs inside the sandboxed iframe)
// installClassShim() registers the class.assigned dispatcher handler via registerNub.
// Before the envelope arrives, or if the shell does not implement nap:class:
// window.napplet.class === undefined (never 0, never null).
if (window.napplet.shell.supports('nap:class') && getClass() === 2) {
  // NAP-CLASS-2 posture -- user approved direct network access.
}

The class integer is an identifier into the NAP-CLASS-$N sub-track (1 = strict baseline, 2 = user-approved explicit-origin). See the NAP-CLASS specs at napplet/naps for posture semantics.

See NAP-CONNECT and NAP-CLASS for the normative specs, the canonical connect:origins aggregateHash fold, the origin format rules, the consent-flow MUSTs, and the at-most-one-terminal-envelope-per-lifecycle constraint.

Package Surface

@napplet/nub is the compatibility package for every NAP domain. Import each domain through the package subpath:

import { mediaCreateSession } from '@napplet/nub/media/sdk';
import type { MediaNapMessage } from '@napplet/nub/media/types';

Domain barrels are also available at @napplet/nub/relay, @napplet/nub/storage, @napplet/nub/ifc, @napplet/nub/keys, @napplet/nub/theme, @napplet/nub/media, @napplet/nub/notify, @napplet/nub/identity, @napplet/nub/config, @napplet/nub/resource, @napplet/nub/connect, and @napplet/nub/class.

Optional Peer Dependency

@napplet/nub declares json-schema-to-ts@^3.1.1 as an optional peer dependency (via peerDependenciesMeta.json-schema-to-ts.optional: true). Install it in your napplet if you want FromSchema<typeof schema> type inference for your config.subscribe callback — the values parameter is then inferred directly from your schema (enums, required fields, defaults all flow through). Authors who skip it pay no install cost and config.subscribe still works with the default Record<string, unknown> typing.

// With json-schema-to-ts installed — values is fully typed
import { configSubscribe } from '@napplet/nub/config/sdk';
import type { FromSchema } from 'json-schema-to-ts';

const schema = {
  type: 'object',
  properties: {
    relayUrl: { type: 'string', format: 'uri' },
    maxResults: { type: 'integer', minimum: 1, default: 20 },
  },
  required: ['relayUrl'],
} as const;

configSubscribe<FromSchema<typeof schema>>((values) => {
  // values.relayUrl: string
  // values.maxResults: number | undefined
});

Protocol Reference

  • NIP-5D — Napplet-shell protocol specification (JSON envelope + NUB negotiation)

License

MIT

Repository: github.com/sandwichfarm/napplet