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

@kahu-logic/site-kit

v0.1.33

Published

The toolkit a Kahu website is built with: an honest contact form, SEO and sitemap helpers, consent-gated analytics, and Next.js edge middleware that keeps preview URLs out of search results.

Readme

@kahu-logic/site-kit

The toolkit your Kahu website is built with: a contact form that tells the truth, SEO and sitemap helpers, cookie-consented analytics, a Shopify cart, and edge middleware that keeps preview URLs out of Google.

Your site is an ordinary Next.js project and you own the code. This package is the only Kahu-specific part of it. Remove it and you still have a working site — you lose the forms and the SEO conveniences, nothing else.

npm install @kahu-logic/site-kit

What you get

A contact form that never lies

import { KahuForm, parseSiteManifest } from '@kahu-logic/site-kit';
import raw from '../kahu.site.json';

const site = parseSiteManifest(raw);

<KahuForm formId="contact" manifest={site} />

The fields come from kahu.site.json, so the form on the page and the fields the server accepts can never disagree.

It shows success only when the server actually accepted the message. If it isn't connected to anything yet it renders as visibly unwired and refuses to submit, rather than quietly dropping enquiries — a silent form is worse than no form.

Since 0.1.12 that includes the spam check. The form is protected by Cloudflare Turnstile, which used to sit visibly on the form and turn to a green "Success!" before the visitor had typed a word. Now it stays out of sight and does its check in the background while they fill the form in. A visitor only sees it if Cloudflare wants them to tick a box, and the form tells them so if they press Send first. If they press Send before the check has finished, the button says "Sending…" until it has.

A form can take a file, too — a CV, a photo, a proof of address. Declare a field with "type": "file", and optionally "accept" (any of application/pdf, image/jpeg, image/png, image/webp, image/heic) and "maxSizeMb" (up to 10). Up to two per form. Kahu checks what each file actually is, not what it is called, keeps it privately, and gives you a download link from the submission in the Kahu app. Files are kept for 12 months.

SEO that can't drift out of step

import { pageMetadata, buildSitemap, localBusinessJsonLd } from '@kahu-logic/site-kit';

Page titles, descriptions, JSON-LD, sitemap.xml, robots.txt and llms.txt all come from one file, kahu.site.json. Ask for metadata for a page that file doesn't list and the build fails — so your sitemap and navigation can never silently disagree with the pages you actually have.

Analytics that asks first

import { KahuAnalytics, KahuConsent } from '@kahu-logic/site-kit';

Nothing is measured unless you set a Google Analytics ID (or, since 0.1.5, a Google Tag Manager container), and even then no request reaches Google until a visitor accepts. Consent defaults to denied, the choice is remembered for a year, and a "manage preferences" link lets visitors change their mind. With a container set, the container loads on that same gate and owns the tags — the direct Analytics tag is not loaded beside it, so nothing is counted twice.

That is the default posture, analytics.consentMode: "opt_in". A site can instead declare "regional": visitors in the EEA, the UK, Iceland, Liechtenstein, Norway and Switzerland are still asked first, and everyone else is measured from the first page with the banner shown as a notice whose Decline turns it off and deletes the identifiers it set. The notice's "OK" is remembered as seen, not as agreed, so the same visitor is still asked properly if a later visit places them inside that list. A banner with Customize is different since 0.1.22: it offers the choice, so its "Accept all", or Save choices with both switches on, is remembered as agreed. That is what lets a Meta pixel or a LinkedIn Insight Tag, which load only on agreement, load for a visitor outside that list who accepts. The visitor's country comes from the site's own edge through kahuMiddleware (which must be given the manifest), never from a lookup that would slow the page; a visitor it cannot place is asked first. In either posture a browser sending Do-Not-Track is never measured and never given an identifier, whatever is pressed. (Global Privacy Control is not read for Analytics yet: every Kahu engine has to agree on it at once.)

Since 0.1.14 the banner appears with the rest of the page instead of once the page's scripts have started, so on a phone it is no longer the last thing to paint, and a press on it before those scripts have taken over still counts. A "regional" site is served with the notice's wording, so a visitor there who is asked first still sees their banner appear once the scripts have started. The banner paints when the browser reaches it in the page, so where it can be the largest text on a phone, render <KahuConsent> first in <body> rather than last: it is fixed in place, so nothing moves on screen.

Since 0.1.11 the site can also run your own Microsoft Clarity project: set analytics.clarityProjectId to the id from your Clarity dashboard (ten or so lower-case letters and digits). Clarity rides the same gate as Analytics, in either posture, and never loads on its own; a site with only a Clarity id still shows the banner. It is never loaded for a browser sending Do-Not-Track or Global Privacy Control. Decline (or withdrawing later from the "manage preferences" link) stops it on the page at once and clears its cookies, and stops it again straight away whenever Clarity starts itself later in the visit, for example when the visitor comes Back to the page from another site; each such restart can still send Microsoft one last upload before it is stopped. Since 0.1.14 that holds for the Clarity Microsoft serves today, which went on recording after a Decline in 0.1.11 to 0.1.13. Since 0.1.14 Clarity also starts only once the page has finished loading, so it no longer holds up the page's load. Whenever Clarity is set, the banner adds "This includes Microsoft Clarity, which records how visitors use the site." and a link to the Microsoft privacy statement, after your own wording if you supplied some: Microsoft's terms require a site that uses Clarity to say so. Since 0.1.18, <KahuConsent clarityInBanner={false}> leaves that sentence off the banner, for a site whose own privacy or cookie page carries it and the link instead; Clarity still loads only on the answers that allow it. <KahuForm> is masked in recordings whatever masking your Clarity project is set to, and a confirmed submission is recorded as the Clarity event kahu_form_submit (a failed one as kahu_form_error). Microsoft's terms do not allow Clarity on sites for health care, financial services or government, or on sites aimed at under-18s.

Since 0.1.15 a choice made on one page or tab reaches the others. A page the browser brings back with Back or Forward, and a tab left open while the visitor chose in another, used to run on under the choice it had when it was last loaded: declining on one page left Analytics and Clarity running on the page the visitor went Back to. Now such a page re-reads the choice when it comes back, when another tab changes it, and when the visitor returns to the tab, and does what a fresh load of it would: it stops after a Decline made anywhere on the site, starts after an Accept, and the banner closes or reopens to match. Once a Decline has stopped a page, only an Accept starts it again before the next load. A Decline also sets Google's ga-disable-<id> opt-out for the Google Analytics tag, because once that tag has loaded, Google's denied signal alone still lets it send cookieless pings; with the opt-out set, the tag drops every event that reaches it after the Decline. A hit it had already queued before then can still leave, typically the page view of a page declined on within seconds of loading. An Accept lifts the opt-out. A Tag Manager container's own tags are for the container to configure.

Since 0.1.17 the banner can offer Customize, so a visitor allows Analytics and Marketing separately. It is off unless you turn it on, and it has to be turned on in both places:

<KahuAnalytics manifest={site} consentCategories />
<KahuConsent manifest={site} acceptLabel="Accept all" customize={{ title: 'Your privacy, your choice' }} />

The banner gains a Customize button between Accept and Decline, and a panel with an Analytics switch, a Marketing switch, an Essential row that is always on, and Save choices. Analytics is Google Analytics' measurement and Microsoft Clarity. Marketing is Google's advertising signals, and the first-party kahu_cid cookie that joins a visit to a later enquiry, with the click details the landing carried. Switching one off stops it on the page at once. The answer is kept beside the Accept / Decline choice rather than in place of it, so no visitor who has already answered is asked again, and anything that only knows the Accept / Decline choice reads a mixed answer as a Decline. On a "regional" site the switches start on for a visitor outside the list above (those tools are already running for them) and off for one inside it, and a mixed answer given outside the list is asked again if a later visit places the visitor inside it. Every word on the banner is a prop, and the class hooks are listed at the top of KahuConsent.tsx.

Since 0.1.19 the site can also carry your own Google Ads tag and Meta pixel: analytics.googleAdsId (AW- and your account's conversion tracking number) and analytics.metaPixelId (the pixel's number, written as a string). Kahu sets both when you connect the ad account, and either one alone shows the banner. The Google Ads tag loads with Analytics, on the same gate, and is a page tag only: it lets Google Ads build audiences and remember the ad click, and it sends no conversion of its own, because Kahu reports each enquiry to Google Ads from its own servers and a second report would count it twice. The Meta pixel loads only after a visitor presses Accept, in either posture (Meta ignores Google's consent signals, so the notice is not enough), never for a browser sending Do-Not-Track, and sends PageView then and Lead once <KahuForm> has a confirmed submission, under the same event id the form sent Kahu, so Meta counts that enquiry once even though Kahu also reports it from its servers. A Decline stops it sending anything more from the page. With Customize on, both are Marketing: the Google Ads tag loads when Marketing is allowed, and the pixel when Marketing is allowed by a press (not by the notice). With a Tag Manager container set, the container owns both, as it owns Analytics: neither is loaded beside it, so nothing is counted twice, and a tag you want must be in the container.

Since 0.1.21 it can carry your LinkedIn Insight Tag too: analytics.linkedinPartnerId, the partner number LinkedIn's Campaign Manager shows under Signals manager, written as a string. Kahu sets it when you connect LinkedIn Ads and pick an ad account (or you paste your own on My Site, which Kahu then never replaces), and it alone shows the banner. It loads on the Meta pixel's terms: only after a visitor presses Accept, never for a browser sending Do-Not-Track, as Marketing under Customize, and never beside a Tag Manager container. It sends no conversion of its own: where a workspace has a LinkedIn conversion sink, Kahu's conversion hub reports leads to LinkedIn from its servers. A Decline switches it off on the page and removes the cookies it keeps on this site.

Since 0.1.24 each <KahuForm> submission also tells Kahu the visitor's answer (adConsent: granted, denied or unanswered), because Kahu's servers never see the banner. Kahu reports an enquiry to LinkedIn only when it says granted, which is exactly when this page was allowed to load the Insight Tag: an Accept, or Marketing switched on under Customize, never the notice's OK and never under Do-Not-Track. A form you wire yourself through submitKahuForm sends it too.

A privacy page that says what the site does

import { KahuPrivacyVendors } from '@kahu-logic/site-kit';

<KahuPrivacyVendors manifest={site} />

Since 0.1.13, put this on your privacy page and it says, in plain words, how the site learns where a visitor came from and which tools it loads, filled in from kahu.site.json: your business name, your consent mode, and whichever of Google Analytics, Google Ads, Google Tag Manager, Meta and Microsoft Clarity you have set (Google Ads and Meta since 0.1.19). When Clarity is set it adds the paragraph Microsoft's terms ask for: that Microsoft receives the data as an independent controller, may use it for Microsoft Advertising, and where to read the Microsoft Privacy Statement. Change your analytics and the paragraphs change with the next build; there is nothing to rewrite by hand. The wording is fixed on purpose. Style it with className, paragraphClassName or paragraphStyle. It renders a <div> of paragraphs, so put it beside your page's paragraphs, not inside one.

Every enquiry says what brought the visitor

Since 0.1.6, <KahuAnalytics> also remembers, in the visitor's own tab, the campaign parameters and referrer they arrived with — the utm_* values on a link from a newsletter, a text message, a social post or an ad. It sets no cookie, sends nothing anywhere and forgets everything when the tab closes; <KahuForm> simply includes what the tab remembers with the submission, so the CRM can say "this enquiry came from the spring email" even when the form was on a different page from the landing. List the other hosts your visitors continue to — a booking engine, a checkout, an app — under attribution.linkedHosts in kahu.site.json and a click to one of them carries the same parameters across, with the Analytics session following through Google's linker. Since 0.1.17 the click also carries the address of the site that referred the visitor, as kahu_ref and reduced to its origin (https://www.google.com/), so a visitor who arrived from a search engine or a social post without any campaign tag is still credited to it on the other side.

A form you build yourself gets all of this too, since 0.1.10: submitKahuForm reads what the tab remembered and the correlation cookie on its own, and fires the Analytics generate_lead event once the lead is confirmed. Pass null for attribution or correlationId to send none, and track: false only if your code fires its own event (otherwise every lead would be counted twice).

Preview URLs stay out of Google

import { kahuMiddleware } from '@kahu-logic/site-kit/middleware';

Draft and preview addresses are marked "do not index". Once your real domain is connected, the temporary address redirects to it — so search engines only ever see one version of your site.

Old addresses still land

Since 0.1.8, the same middleware serves a redirect map. A site rebuilt from an older one keeps that site's URLs — the ones search engines rank, printed material carries and other sites link to — and the rebuild does not always keep the same paths. redirects in kahu.site.json says where each old address now goes:

"redirects": [
  { "from": "/index.php/about-us", "to": "/about" },
  { "from": "/brochure.pdf", "to": "/legacy/brochure.pdf" },
  { "from": "/book", "to": "https://book.example.com/acme" }
]

Every row answers a permanent redirect (301), and the address's query string travels with it, so a ?utm_source= on an old link is still credited. The rules, each of which fails the build rather than shipping a broken row:

  • from is a path only — no query, no #, no whitespace. It is matched with its trailing slash stripped (/about-us/ and /about-us are the same row, and writing both is refused as a duplicate). It cannot be one of your own pages, because the redirect would hide the page.
  • to is one of your declared pages, a file under public/ (it needs a file extension, so a mistyped page path cannot become a redirect to nothing), or an absolute https:// address.
  • A row cannot point at itself, and cannot point at another row's from: the map is one hop, so write the final destination.
  • At most 1000 rows, because the file ships inside every page.

A site built fresh has nothing to redirect and simply leaves the key out.

The Kahu Assist chat bubble, switched from the app

Since 0.1.16, <KahuAnalytics> also renders <KahuAssist>: one small async script from chat.kahulogic.ai, named by your site's slug. While Assist is turned on for your workspace in the Kahu app it loads the chat bubble; while it is off it is an empty script and nothing appears. Turning it on or off never needs a rebuild. It sets no cookie and records nothing, so it is not behind the consent banner, and the bubble itself calls nothing until a visitor opens it.

To leave it out of a site entirely, pass assistOrigin={null} to <KahuAnalytics>.

Online booking that falls back to a form

import { KahuBooking } from '@kahu-logic/site-kit';

<KahuBooking manifest={site} mode="appointment"
  fields={[{ label: 'Service', type: 'select', options: ['Cut', 'Colour'], required: true }]}
  theme={{ accent: 'var(--brand)', ink: 'var(--ink)' }} />

Since 0.1.16. Visitors book a time (mode="appointment": a salon, a spa, a consultation) or a table (mode="table", with partyMax) straight into your Kahu Bookings diary. It turns on when kahu.site.json carries your booking key:

"booking": { "siteKey": "ws_…" }

That is the key Kahu issues when the chat assistant (Assist) is turned on for your workspace, not the form's publicSiteKey.

Until the key is there, or whenever the booking widget can't run on the page, the block shows your site's booking form instead: the first form in kahu.site.json whose kind is booking, or the one you name with formId, or anything you pass as fallback. A booking request is never lost. It keeps working when visitors move between pages without a reload. theme sets the widget's colours from your own design tokens.

A booking widget you built in the app

<KahuBooking manifest={site} widget="dinner-bookings" />
<KahuBooking manifest={site} widget="dinner-bookings" floating buttonLabel="Book a table" buttonColor="#c0392b" />

Since 0.1.25. A widget published in the Kahu app (Bookings → Website widget) goes on the page by its name, the data-kahu-form value in the embed code the app shows. No booking key is needed and the site's source holds no script tag: the block loads Kahu's widget for your site's own slug and draws it in the page, or as a floating button with floating. The widget's fields, rules, pages and design are the ones you published, and a change you publish in the app shows here with no rebuild. If the widget cannot load at all, the block shows the booking form, as above.

Opening hours from one place

<OpeningHours manifest={site} />

Since 0.1.16. One row per day from business.openingHours, the same lines your search listing reads ("Tu-Sa 09:00-17:00"), so the two can never disagree. Times follow your site's locale (12- or 24-hour). A day no line mentions says "Closed". The component never guesses: a line it can't read is shown exactly as written, and then no day is called closed.

A map without an API key

<MapEmbed manifest={site} />

Since 0.1.16. A Google map of business.address, with an "Open in Google Maps" link. It needs no key. It loads only when a visitor scrolls to it, and it shows nothing without a street address. Once it loads it is Google's page, so list Google Maps on your privacy page if you have one.

A shop that checks out on Shopify

import raw from '@/data/shopify.json';
import { AddToCart, CartCount, KahuCartProvider, asShopCatalogue, variantFor } from '@kahu-logic/site-kit/shop';

const catalogue = asShopCatalogue(raw)!;

// app/layout.tsx, once around the site
<KahuCartProvider cartUrl={catalogue.shop.cartUrl}>{children}</KahuCartProvider>

// the header
<a href="/cart">Cart <CartCount /></a>

// a product page
const variant = variantFor(product, selected);
<AddToCart product={product} variant={variant} />

Since 0.1.26, from @kahu-logic/site-kit/shop. When your business sells through Shopify, Kahu writes the store's catalogue into your site as data/shopify.json; this module reads it and does the parts every shop needs:

  • Types for the file (ShopCatalogue, ShopProduct, ShopVariant…) and asShopCatalogue, which reads the imported JSON as one and leaves out a product it could not draw rather than failing the build.
  • Options. defaultVariant is where a product page starts, variantFor finds the variant the visitor's picks name, and isOptionValueAvailable says which sizes or colours are sold out.
  • A cart in the visitor's browser. <KahuCartProvider> keeps it in localStorage (it survives a reload and follows the visitor between tabs), and useKahuCart() gives its lines, count, subtotal, add, remove, set and checkoutUrl. Hand it cartIndexOf(catalogue) on the cart page to show the store's current prices and to mark anything it no longer sells. <AddToCart> and <CartCount> are an unstyled button and span for your own design to style.
  • Checkout on Shopify. checkoutUrl (or cartPermalink) is Shopify's cart permalink, https://<store>/cart/<variant>:<qty>,…, which opens the store's own checkout with the cart in it. Nothing here takes a payment, holds a token or sends anything anywhere before the visitor presses Checkout.
  • Search. productJsonLdScript(product, site) is the product page's schema.org markup: price, currency and stock per variant.
  • Pictures. shopImageUrl(src, 800) and shopImageSrcSet(src) ask Shopify's image service for the width the page needs.

kahu.site.json

One file describes your site: its name, pages, contact details and options. It's validated against schema/kahu.site.schema.json, which ships with this package, so most editors will autocomplete it and flag mistakes as you type.

Requirements

Next.js (App Router) on Node 20+. Built for deployment on Cloudflare Workers via OpenNext, which is how Kahu sites are hosted — the helpers themselves are ordinary Next.js code.

Licence

MIT. Yours to keep, fork or delete.