{"id":46802,"library":"wexa-chat","title":"wexa-chat","description":"Chat core library built in TypeScript with MongoDB persistence and optional Redis pub/sub for cross-instance fanout. Current stable version 0.3.4. It provides a server-side API via initChat() and a lightweight browser client bundle (SocketProvider, useSocket, getSocketManager). Requires mongoose and ioredis as peer dependencies. Ships its own WebSocket transport using the ws library, with server-driven authentication via query parameters. Differentiators: server & client in one package, optional Redis for horizontal scaling, built-in text search, and a Next.js demo app pattern.","status":"active","version":"0.3.4","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","chat","mongodb","redis","websocket","ws","typescript"],"install":[{"cmd":"npm install wexa-chat","lang":"bash","label":"npm"},{"cmd":"yarn add wexa-chat","lang":"bash","label":"yarn"},{"cmd":"pnpm add wexa-chat","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for MongoDB models and connection","package":"mongoose","optional":false},{"reason":"Required peer dependency for Redis pub/sub (optional at runtime via config)","package":"ioredis","optional":true},{"reason":"Required peer dependency for WebSocket transport","package":"ws","optional":false},{"reason":"Required peer dependency for client bundle (SocketProvider, useSocket)","package":"react","optional":false}],"imports":[{"note":"ESM export; CommonJS require will not work (package is ESM-only). Use dynamic import if needed.","wrong":"const initChat = require('wexa-chat')","symbol":"initChat","correct":"import { initChat } from 'wexa-chat'"},{"note":"Client symbols are in a subpath export 'wexa-chat/client'. Importing from the top-level will fail.","wrong":"import { SocketProvider } from 'wexa-chat'","symbol":"SocketProvider","correct":"import { SocketProvider } from 'wexa-chat/client'"},{"note":"Same as SocketProvider; use the /client subpath.","wrong":"import { useSocket } from 'wexa-chat'","symbol":"useSocket","correct":"import { useSocket } from 'wexa-chat/client'"},{"note":"ESM-only. Also note that getSocketManager is a singleton getter, not a constructor.","wrong":"const getSocketManager = require('wexa-chat/client');","symbol":"getSocketManager","correct":"import { getSocketManager } from 'wexa-chat/client'"},{"note":"This is a TypeScript type, not a value. Use import type.","symbol":"ChatEvent","correct":"import type { ChatEvent } from 'wexa-chat/client'"}],"quickstart":{"code":"import mongoose from 'mongoose';\nimport { initChat } from 'wexa-chat';\n\nasync function main() {\n  await mongoose.connect(process.env.MONGODB_URI ?? '');\n  const chat = await initChat(mongoose, {\n    participantModels: ['User'],\n    memberRoles: ['member', 'admin'],\n    mongoUri: process.env.MONGODB_URI ?? '',\n    enableTextSearch: true,\n  });\n  console.log('Chat initialized');\n}\nmain().catch(console.error);","lang":"typescript","description":"Initializes chat with MongoDB, no WebSocket server. Shows required peer mongoose and basic options."},"warnings":[{"fix":"Always pass httpServer only when it is available (e.g., after Next.js server is ready). Use the lazy initialization pattern shown in the README.","message":"initChat() expected three arguments but the third (httpServer) is optional. If provided, it must be an HTTP server instance (not null or undefined) to attach WebSocket transport. Passing undefined when server not ready may cause runtime errors.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Ensure server socket.path (if set) equals client's expected path. Both default to '/ws'.","message":"Client bundle path must match server's socket.path. If you omit socket.path on server, it defaults to '/ws'. Client expects '/ws' by default; mismatch leads to 404.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use conditional: if (process.env.REDIS_URL) { redis: { url: process.env.REDIS_URL } } else if (process.env.REDIS_HOST) { ... }.","message":"Redis configuration is optional but if provided, both url OR (host and port) must be set. Missing fields cause runtime error.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Do not rely on cors option; configure CORS at the HTTP server level instead.","message":"SocketConfig.cors option is currently accepted but not enforced. It may be removed in a future version.","severity":"deprecated","affected_versions":"<=0.3.4"}],"env_vars":null,"search_vec":"'0.3.4':25 'api':32 'app':88 'authent':64 'browser':38 'built':7,80 'built-in':79 'bundl':40 'chat':3,4,91 'client':39,70 'core':5 'cross':19 'cross-inst':18 'current':22 'demo':87 'depend':50 'differenti':68 'driven':63 'fanout':21 'getsocketmanag':43 'horizont':77 'initchat':34 'instanc':20 'ioredi':47 'javascript':90 'librari':6,59 'lightweight':37 'mongodb':11,92 'mongoos':45 'next.js':86 'one':72 'option':14,74 'packag':73 'paramet':67 'pattern':89 'peer':49 'persist':12 'provid':27 'pub/sub':16 'queri':66 'redi':15,75,93 'requir':44 'scale':78 'search':83 'server':30,62,69 'server-driven':61 'server-sid':29 'ship':51 'side':31 'socketprovid':41 'stabl':23 'text':82 'transport':55 'typescript':9,96 'use':56 'usesocket':42 'version':24 'via':33,65 'websocket':54,94 'wexa':2 'wexa-chat':1 'ws':58,95","created_at":"2026-06-07T13:01:41.850752+00:00","updated_at":"2026-06-07T13:01:41.850752+00:00","problems":[{"fix":"Update tsconfig.json: set 'moduleResolution' to 'bundler' or 'node16'. Or use paths: { 'wexa-chat/client': ['./node_modules/wexa-chat/dist/client/index.d.ts'] }.","cause":"TypeScript cannot resolve subpath export. Ensure package.json exports includes './client'.","error":"Cannot find module 'wexa-chat/client' or its corresponding type declarations."},{"fix":"Change to: import { initChat } from 'wexa-chat' (or dynamic import).","cause":"CommonJS require() used instead of ESM import.","error":"TypeError: initChat is not a function"},{"fix":"Do not start a separate HTTP server; pass the existing Next.js HTTP server to initChat(). In Next.js, use the socket warm-up route.","cause":"WebSocket server is trying to attach to a port already in use (e.g., Next.js dev server).","error":"Error: listen EADDRINUSE :::3000"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"wexa-chat","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}