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

@opiniom/core

v0.6.0

Published

Framework-agnostic core client for the OpinioM chat SDK — real-time messaging, WebSocket, authentication, and state management

Downloads

51

Readme

@opiniom/core

Framework-agnostic core client for the OpinioM chat SDK. Handles authentication, real-time messaging via Socket.io, state management, reconnection, and offline caching.

Use this package directly if you're building with vanilla JS, Svelte, Vue, Angular, or any non-React framework. For React, use @opiniom/react instead.

Install

npm install @opiniom/core @opiniom/types

Quick Start

import { createClient } from "@opiniom/core";

const client = await createClient({
  projectKey: "pk_live_abc123",
  jwt: customerSignedJwt,
});

// Listen for new messages
client.on("message:new", (message) => {
  console.log(`${message.sender.name}: ${message.content}`);
});

// Send a message
await client.sendMessage("conversation-id", {
  content: "Hello from OpinioM!",
});

Configuration

const client = await createClient({
  // Required
  projectKey: "pk_live_abc123",    // Your public project key
  jwt: "eyJhbGciOi...",           // JWT signed with your API secret

  // Optional
  apiUrl: "https://api.opiniom.io", // Custom API endpoint
  wsUrl: "https://api.opiniom.io",  // Custom WebSocket endpoint
  mode: "floating",                   // "floating" | "inline"
  container: "#chat-container",       // Required when mode is "inline"
  locale: "en",                       // UI language
  startOpen: false,                   // Start with widget open
  zIndex: 2147483600,                 // Widget z-index
  debug: false,                       // Verbose console logging
  cache: false,                       // IndexedDB offline persistence

  // Callbacks
  onReady: (client) => {},            // Client connected and ready
  onError: (err) => {},               // Unhandled error
  onTokenExpiring: async () => {      // Return a fresh JWT
    return await fetchNewToken();
  },
});

API Reference

Lifecycle

client.state;          // "connected" | "connecting" | "reconnecting" | "disconnected" | ...
client.user;           // Current user (User | null)
client.widgetConfig;   // Widget theme config (WidgetConfig | null)
client.projectName;    // Project name (string | null)
client.version;        // SDK version
client.locale;         // Current locale

client.destroy();                      // Disconnect and clean up
await client.updateAuth(newJwt);       // Swap JWT at runtime
await client.refreshSession();         // Force session refresh
client.setLocale("fr");                // Change UI language

Conversations

// Create a conversation
const conv = await client.createConversation({
  type: "direct",           // "direct" | "group" | "channel" | "support"
  member_ids: ["user-123"],
  title: "Support Chat",    // Optional
});

// List, join, leave
const conversations = client.listConversations();
await client.joinConversation(conversationId);
await client.leaveConversation(conversationId);

Messages

// Send a message (with optimistic UI updates)
const message = await client.sendMessage(conversationId, {
  content: "Hello!",
  client_id: "optional-client-uuid",  // For deduplication
});

// Edit and delete
await client.editMessage(messageId, conversationId, "Updated text");
await client.deleteMessage(messageId, conversationId);

// Fetch messages
const messages = client.getMessages(conversationId);         // Cached
const older = await client.loadMoreMessages(conversationId); // Paginated

File Upload

// Upload returns metadata for attaching to a message
const attachment = await client.uploadFile(fileObject);
// { file_name, file_size, mime_type, url }

await client.sendMessage(conversationId, {
  content: "See attached",
  attachments: [attachment],
});

Reactions

await client.addReaction(messageId, "thumbsup");
await client.removeReaction(messageId, "thumbsup");

Typing & Read Receipts

client.setTyping(conversationId, true);   // Start typing
client.setTyping(conversationId, false);  // Stop typing
client.markRead(conversationId, messageId);

Events

Subscribe to real-time events:

const unsub = client.on("message:new", (message) => { ... });
client.on("message:updated", (message) => { ... });
client.on("message:deleted", ({ id, conversation_id }) => { ... });
client.on("conversation:created", (conversation) => { ... });
client.on("reaction:added", (reaction) => { ... });
client.on("reaction:removed", (reaction) => { ... });
client.on("presence:changed", (presence) => { ... });
client.on("typing:start", ({ conversation_id, user_id }) => { ... });
client.on("typing:stop", ({ conversation_id, user_id }) => { ... });
client.on("state:changed", ({ from, to }) => { ... });
client.on("error", (error) => { ... });

// Unsubscribe
unsub();
// or
client.off("message:new", handler);

Connection States

The client follows this state machine:

idle → authenticating → connecting → connected
                                        ↓
                                    degraded ←→ reconnecting
                                        ↓
                                   disconnected → destroyed

Listen for state changes:

client.on("state:changed", ({ from, to }) => {
  if (to === "reconnecting") showBanner("Reconnecting...");
  if (to === "connected") hideBanner();
});

JWT Format

Your backend signs a JWT with your OpinioM API secret key:

// Required claims
{
  sub: "user-id",         // Unique user identifier
  name: "Jane Doe",       // Display name
  email: "[email protected]"
}

The JWT must have exactly 3 dot-separated segments. Max lifetime: 24 hours.

Bundle Size

| Format | Size (gzip) | |---|---| | ESM | ~34 KB | | CJS | ~25 KB |

Related Packages

| Package | Description | |---|---| | @opiniom/react | React provider, hooks, and components | | @opiniom/web | Lit-based web component widget | | @opiniom/types | TypeScript type definitions |

License

MIT