prufy
Skip to the page

ComponentsInstallation

Components

Installation

Install @prufy/connect and register its elements.

On this page

Use it in any app that supports custom elements. The examples use a bundler, such as Vite or Next.js, to resolve package imports. To skip the bundler, see Without a build step.

Install the package

npm install @prufy/connect

lit and lucide install with it. react 18 or newer is an optional peer, for the React components, and ai 7 or newer is one for the guide's model loop on a server. The package is ESM only.

Before 1.0, a minor version can change the API. Pin ~0.1 to take fixes without surprises.

Register the elements

Import the package once, from your app's browser entry:

main.ts
// Your app's browser entry, once
import "@prufy/connect"

That one import registers prufy-connect, prufy-dns-record and prufy-status. In React, import the components instead. They register the elements in the browser and render them on the server:

React
import { PrufyConnect } from "@prufy/connect/react"

@prufy/connect/core, /server and /simulation register nothing, so they're safe to import anywhere, and a bundler drops what you don't use.

What the package exports

ImportWhat it is
@prufy/connectRegisters the three elements, and exports the flow with no element.
@prufy/connect/coreThe flow with no element. Registers nothing.
@prufy/connect/reactReact components and useConnect.
@prufy/connect/serverEach element as HTML, the handlers, and the page a provider returns to.
@prufy/connect/guideExperimentalRegisters prufy-guide, and exports the guide's flow.
@prufy/connect/guide/reactExperimentalPrufyGuide and useGuide.
@prufy/connect/guide/aiExperimentalcreateAiGuide, the guide's model loop on the AI SDK. Server only.
@prufy/connect/simulationDemo onlyMade-up backends for demos and tests. Never for production.

Without a build step

A plain HTML page can load the modal from unpkg, with nothing to install:

index.html
<script type="module" src="https://unpkg.com/@prufy/connect@0.1/cdn/prufy-connect.js"></script>

<prufy-connect app-name="Acme" endpoint="/api/connect"></prufy-connect>

@0.1 follows the newest 0.1 release. To keep a page on one release, use its exact version, like @prufy/connect@0.1.0. The file carries Lit and the icons, so it imports nothing else. The guide has a file of its own, https://unpkg.com/@prufy/connect@0.1/cdn/prufy-guide.js.

To host the file yourself, copy cdn/prufy-connect.js from the package into your site. Browsers only run module scripts from a server, so open the page through one, not from a file on disk.

Give it a backend

The modal talks to your server, and your server calls Prufy with your user's session. createConnectHandler takes a Request and returns a Response, so it mounts in Next.js, SvelteKit, Hono, Bun or a Worker:

app/api/connect/[action]/route.ts
import { createConnectHandler } from "@prufy/connect/server"

// Two functions. Each one calls Prufy from your server, with your user's session.
// One click would add a third, consent, but no DNS provider offers it yet.
const handler = createConnectHandler({
  detect: (domain) => findProviderAndRecord(domain),
  check: ({ domain, ticket }) => lookUpTheRecord(domain, ticket),
})

export { handler as GET, handler as POST }

The last part of the path picks the action. Give it a backend lists them.

To try the modal before you write one, give it the simulation instead:

main.ts
import { createFixtureClient } from "@prufy/connect/simulation"

// Made-up DNS answers, to try the flow. Don't ship this.
document.querySelector("prufy-connect").client = createFixtureClient({
  provider: "cloudflare",
  firstCheck: "wrong_host",
})

Its first DNS check asks for a fix, so you see that path too. Every later check passes.

In your framework

  • React and Next.js use the components in @prufy/connect/react. They pass objects as properties, turn events into callbacks like onVerified, and render on a server.

  • Svelte and plain HTML need nothing. Use the tag.

  • Vue needs one compiler option, so it doesn't look for a Vue component named prufy-connect:

vite.config.ts
// vite.config.ts
import vue from "@vitejs/plugin-vue"
import { defineConfig } from "vite"

export default defineConfig({
  plugins: [
    vue({
      template: { compilerOptions: { isCustomElement: (tag) => tag.startsWith("prufy-") } },
    }),
  ],
})

Content Security Policy

In the browser the elements adopt their styles as constructable stylesheets, which a style-src policy doesn't block. Rendered on a server, by the React components or renderConnect, an element writes a <style> into its shadow root template, and that one needs allowing. Allow it by hash, computed from connectShadowHtml() in @prufy/connect/server, so it follows the package's CSS. A theme adds a second <style> with its own hash.

Editor support

Importing an entry registers its element types with TypeScript, and the events they fire:

main.ts
import "@prufy/connect"

const modal = document.querySelector("prufy-connect") // PrufyConnectElement
modal?.addEventListener("verified", (event) => {
  saveDomain(event.detail.domain) // typed as VerifiedDetail
})

Continue with the Quick start to put the modal on a page, or read about the connect modal and guided setup.