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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@faruksina/chat-widget

v1.2.2

Published

A React chat widget component for customer-supplier communication

Readme

@avetti/chat-widget

A React chat widget component for customer-supplier communication with real-time messaging, file uploads, and unread message tracking.

Features

  • 🚀 Real-time messaging with Socket.IO
  • 👥 Customer & Supplier interfaces with different behaviors
  • 📁 File upload support with image thumbnails
  • 🔔 Unread message tracking with persistent read status
  • 🎨 Modern UI with Tailwind CSS styling
  • 📱 Responsive design for mobile and desktop
  • 🔒 JWT authentication support
  • TypeScript support

Installation

npm install @avetti/chat-widget

Quick Start

1. Basic Customer Usage

import React from "react";
import { ChatWidget, ChatWidgetProvider } from "@avetti/chat-widget";

function App() {
  const customerUser = {
    id: "customer1",
    name: "John Customer",
    email: "[email protected]",
    userType: "customer",
    immutableId: "[email protected]",
    token: "your-jwt-token-here",
  };

  return (
    <ChatWidgetProvider serverUrl="https://your-chat-server.com">
      <ChatWidget
        user={customerUser}
        vendorId="supplier1"
        onClose={() => console.log("Chat closed")}
      />
    </ChatWidgetProvider>
  );
}

2. Basic Supplier Usage

import React from "react";
import { ChatWidget, ChatWidgetProvider } from "@avetti/chat-widget";

function App() {
  const supplierUser = {
    id: "supplier1",
    name: "Tech Support",
    email: "[email protected]",
    userType: "supplier",
    vendorId: "supplier1",
    immutableId: "supplier1",
    token: "your-jwt-token-here",
  };

  return (
    <ChatWidgetProvider serverUrl="https://your-chat-server.com">
      <ChatWidget
        user={supplierUser}
        onClose={() => console.log("Chat closed")}
      />
    </ChatWidgetProvider>
  );
}

API Reference

ChatWidgetProvider

Wrapper component that provides configuration to all ChatWidget components.

Props

| Prop | Type | Default | Description | | -------------- | ---------- | ------------------------- | -------------------------------- | | serverUrl | string | "http://localhost:5001" | URL of the chat server | | config | object | {} | Additional configuration options | | onError | function | undefined | Error callback | | onConnect | function | undefined | Connection callback | | onDisconnect | function | undefined | Disconnection callback |

ChatWidget

Main chat widget component.

Props

| Prop | Type | Required | Description | | -------------- | ---------- | -------- | ------------------------------------ | | user | object | ✅ | User object with authentication info | | vendorId | string | ❌ | Target vendor ID (for customers) | | onClose | function | ❌ | Callback when chat is closed | | onConnect | function | ❌ | Connection callback | | onDisconnect | function | ❌ | Disconnection callback | | onError | function | ❌ | Error callback | | serverUrl | string | ❌ | Override server URL | | config | object | ❌ | Additional configuration |

User Object Structure

interface User {
  id: string; // Unique user ID
  name: string; // Display name
  email: string; // User email
  userType: "customer" | "supplier";
  immutableId: string; // Email for customers, vendorId for suppliers
  token: string; // JWT authentication token
  vendorId?: string; // Required for suppliers
}

Configuration

Default Configuration

const defaultConfig = {
  serverUrl: "http://localhost:5001",
  reconnectAttempts: 5,
  reconnectDelay: 1000,
  uploadMaxSize: 10 * 1024 * 1024, // 10MB
  allowedFileTypes: [
    "image/jpeg",
    "image/png",
    "image/gif",
    "application/pdf",
    "text/plain",
  ],
};

Custom Configuration

<ChatWidgetProvider
  config={{
    uploadMaxSize: 5 * 1024 * 1024, // 5MB
    allowedFileTypes: ["image/jpeg", "image/png"],
  }}
>
  <ChatWidget user={user} />
</ChatWidgetProvider>

Server Requirements

The chat widget requires a compatible server with the following endpoints:

  • POST /api/upload - File upload endpoint
  • POST /api/messages/mark-read - Mark messages as read
  • POST /api/cleanup-duplicates - Cleanup duplicate rooms
  • POST /api/clear-all-data - Clear all data
  • GET /api/health - Health check

Socket.IO events:

  • join-chat - Join a chat room
  • send-message - Send a message
  • typing - Typing indicator
  • stop-typing - Stop typing indicator

Styling

The component includes built-in Tailwind CSS styles. To customize the appearance, you can:

  1. Override CSS classes in your application
  2. Use CSS-in-JS solutions
  3. Modify the component's className props

Browser Support

  • Chrome 60+
  • Firefox 60+
  • Safari 12+
  • Edge 79+

License

MIT

Support

For support and questions, please contact the Avetti team.