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

@zynli/react-widget

v0.2.6

Published

Embed the Zynli support chat widget in React and Next.js apps

Readme

@zynli/react-widget

Embed the Zynli support chat widget in React and Next.js applications.

The component checks your workspace embed allowlist before loading embed.js — unauthorized host sites never see the chat bubble.

Install

npm install @zynli/react-widget

Peer dependencies: react, react-dom. For Next.js, install next (optional peer).

Quick start

import { ZynliWidget } from "@zynli/react-widget";

<ZynliWidget
  tenant={process.env.NEXT_PUBLIC_ZYNLI_TENANT!}
  appUrl={process.env.NEXT_PUBLIC_ZYNLI_APP_URL!}
/>

In-app (logged-in) embeds

For chat inside an authenticated product (not a public marketing site):

  1. In your Zynli workspace: Settings → Embed → generate an identity secret, add your app origins under Allowed embed domains, and enable Require verified identity.
  2. Mount with requireUser + eager so the widget never appears anonymously and identifies immediately.
  3. Sign users on your server (see below) via identityUrl or the user prop.
  4. On SPA navigations, call updateZynliContext so agents see the current page / plan.
import { ZynliWidget, updateZynliContext } from "@zynli/react-widget";
import { useEffect } from "react";
import { usePathname } from "next/navigation";

export function InAppSupportChat() {
  const pathname = usePathname();

  useEffect(() => {
    void updateZynliContext({
      url: typeof window !== "undefined" ? window.location.href : undefined,
      path: pathname,
    });
  }, [pathname]);

  return (
    <ZynliWidget
      tenant={process.env.NEXT_PUBLIC_ZYNLI_TENANT!}
      appUrl={process.env.NEXT_PUBLIC_ZYNLI_APP_URL!}
      identityUrl="/api/zynli/identity"
      requireUser
      eager
    />
  );
}
  • requireUser — do not load until a signed user exists; teardown on logout (user: null / reset).
  • eager — skip idle deferral in auth shells.
  • Allowlist preflight is fail-open (only an explicit allowed: false blocks mount; CORS/network errors still mount — /widget enforces the allowlist).

Identified users

Two options — pick one:

A. identityUrl (recommended)

Point at your session endpoint that returns a signed identity. The package fetches it with cookies and calls setUser after the embed is ready.

<ZynliWidget
  tenant={tenantApiKey}
  appUrl="https://your-workspace.zynli.ai"
  identityUrl="/api/zynli/identity"
  identityCredentials="include"
/>

Your endpoint should return either:

{ "user": { "id": "…", "email": "…", "name": "…", "hash": "…", "expiresAt": 1710000000, "traits": { "plan": "pro" } } }

or { "authenticated": false } / { "user": null } when logged out.

B. user prop

Sign on the server and pass the object directly (or use useZynliIdentity):

import { ZynliWidget, useZynliIdentity } from "@zynli/react-widget";

function SupportChat() {
  const { user } = useZynliIdentity({ url: "/api/zynli/identity" });
  return (
    <ZynliWidget
      tenant={tenantApiKey}
      appUrl={appUrl}
      user={user}
    />
  );
}

Server signing (Node)

Payload: {tenantApiKey}|{userId}|{email or empty}|{expiresAtUnixSeconds}
HMAC-SHA256 hex, secret from Settings → Embed → Verified visitor identity.

import { createHmac } from "crypto";

export function signZynliUser(args: {
  tenantApiKey: string;
  secret: string;
  userId: string;
  email?: string;
  name?: string;
  traits?: Record<string, string | number | boolean>;
}) {
  const expiresAt = Math.floor(Date.now() / 1000) + 86400;
  const payload = [args.tenantApiKey, args.userId, args.email ?? "", expiresAt].join("|");
  const hash = createHmac("sha256", args.secret).update(payload).digest("hex");
  return {
    id: args.userId,
    email: args.email,
    name: args.name,
    hash,
    expiresAt,
    traits: args.traits,
  };
}

Never expose the identity secret to the browser.

Props

| Prop | Required | Description | |------|----------|-------------| | tenant | Yes | Workspace API key (or slug) from Settings → Embed | | appUrl | Yes* | Workspace origin for /widget + API (data-app-url) | | scriptUrl | No | Override embed.js URL (defaults to Spaces CDN; local appUrl → {appUrl}/embed.js) | | offset | No | "0" (default) or "default" (16px host margin) | | enabled | No | false to skip loading | | locale | No | BCP-47 locale, e.g. en, sv | | user | No | Signed identity object | | identityUrl | No | Your API that returns { user } (cookie auth) | | identityCredentials | No | Fetch credentials (default include) | | identityRefreshMs | No | Re-fetch identity on an interval | | onIdentify / onReset | No | Callbacks after identify / logout | | requireUser | No | When true, skip loading until a signed user is available (platform embeds) | | eager | No | Mount immediately (data-eager); use in authenticated app shells |

* Pass appUrl so the CDN loader knows which workspace hosts /widget. Override with scriptUrl only when you need a custom/self-hosted loader.

Imperative helpers

import {
  setZynliUser,
  resetZynliUser,
  openZynliWidget,
  closeZynliWidget,
  toggleZynliWidget,
  setZynliLocale,
  updateZynliContext,
} from "@zynli/react-widget";

await setZynliUser(signedUser);
await resetZynliUser(); // logout
await updateZynliContext({ path: "/settings", plan: "pro" });
await openZynliWidget();

Same surface as window.Zynli after embed.js loads.

Next.js

import { ZynliWidgetNext } from "@zynli/react-widget/next";

<ZynliWidgetNext
  tenant={process.env.NEXT_PUBLIC_ZYNLI_TENANT!}
  appUrl={process.env.NEXT_PUBLIC_ZYNLI_APP_URL!}
  identityUrl="/api/zynli/identity"
  requireUser
  eager
/>

Troubleshooting

| Issue | Check | |-------|--------| | Widget does not appear | Host origin listed under Settings → Embed → Allowed embed domains; only an explicit allowlist denial blocks the React preflight — CORS/proxy noise still mounts | | Identity not applied | Endpoint returns hash + expiresAt; identity secret enabled; use requireUser for in-app | | Stale user after logout | Return { user: null } from identityUrl, or user={null} / resetZynliUser() | | “Sign in required” in widget | Workspace has Require verified identity on — call setUser / provide identityUrl |

License

Apache-2.0