Skip to main content

Overview

mezon-sdk is a powerful TypeScript SDK providing a robust client-side interface for interacting with the Mezon platform, enabling real-time communication and efficient data management for applications and bots.

Why mezon-sdk?

This project simplifies Mezon applications and bots development by providing a comprehensive and well-structured TypeScript library. The core features include:

  • 🟒 Real-time Communication: Leverages WebSockets for instant, bidirectional communication with the Mezon server, ensuring low-latency interactions.
  • πŸ”΅ Comprehensive API: Offers a complete set of methods for interacting with all aspects of the Mezon service, including authentication, channel management, and message handling.
  • 🟑 Type Safety: Built with TypeScript and enforced strict type checking, minimizing runtime errors and improving code maintainability.
  • πŸ”΄ Efficient Message Handling: Employs asynchronous queues and caching mechanisms to optimize performance, even under high message volume.
  • 🟣 Modular Design: Well-structured and modular architecture, featuring distinct managers for sessions, sockets, channels, and events, promotes easy extension, maintenance, and integration into existing projects.
  • 🟠 Robust Error Handling: Includes comprehensive error handling throughout the codebase, ensuring application stability and a better user experience.
  • βš™οΈ Data Persistence: Integrates with SQLite for local message storage, allowing for offline access and improved performance.

Features​

ComponentDetails
βš™οΈArchitecture
  • Modular, with components like MezonClient, SessionManager, SocketManager, ChannelManager, EventManager.
  • Event-driven for real-time updates.
  • Utilizes an API client for HTTP requests and a WebSocket adapter for real-time communication.
πŸ”©Code Quality
  • Uses TypeScript for type safety.
  • Employs ESLint and Prettier for linting and formatting.
  • Jest and Jest-Cucumber for testing.
πŸ“„Documentation
  • Comprehensive (This document).
  • Generated Protocol Buffer definitions for API and real-time messages.
πŸ”ŒIntegrations
  • Uses ws for WebSocket communication.
  • better-sqlite3 for local SQLite database interaction (e.g., MessageDatabase.ts).
  • Protocol Buffers for efficient data serialization (realtime.ts, struct.ts).
  • Base64 for data encoding.
🧩Modularity
  • Organized into managers, structures, API layers, and utility functions.
  • Clear separation of concerns (e.g., API interaction, socket management, data structures).
πŸ§ͺTesting
  • Uses Jest and Jest-Cucumber.
  • Configuration in jest.config.js.
⚑️Performance
  • AsyncThrottleQueue for rate-limiting and managing asynchronous tasks.
  • CacheManager for efficient data retrieval.
  • SQLite for optimized local data access.
πŸ›‘οΈSecurity
  • Session management with JWTs (session.ts).
  • HTTPS and WSS by default.
  • Base64 encoding for certain data transformations.
πŸ“¦Dependencies
  • Core: ws, better-sqlite3, js-base64.
  • Development: TypeScript, ESLint, Prettier, Jest, Nodemon, ts-node.
πŸš€Scalability
  • Client-side scalability aided by efficient data management and asynchronous operations.
  • Server-side scalability depends on Mezon platform architecture. SQLite usage is for local client caching, not server-side primary storage.

Note: This table is based on information from the project structure and file summaries.


Project Structure​

└── mezon-sdk/
β”œβ”€β”€ jest.config.js
β”œβ”€β”€ nodemon.json
β”œβ”€β”€ package.json
β”œβ”€β”€ README.md
β”œβ”€β”€ src
β”‚ β”œβ”€β”€ api
β”‚ β”‚ └── api.ts
β”‚ β”œβ”€β”€ api.ts
β”‚ β”œβ”€β”€ client.ts
β”‚ β”œβ”€β”€ constants
β”‚ β”‚ β”œβ”€β”€ enum.ts
β”‚ β”‚ └── index.ts
β”‚ β”œβ”€β”€ google
β”‚ β”‚ └── protobuf
β”‚ β”‚ β”œβ”€β”€ struct.ts
β”‚ β”‚ β”œβ”€β”€ timestamp.ts
β”‚ β”‚ └── wrappers.ts
β”‚ β”œβ”€β”€ index.ts
β”‚ β”œβ”€β”€ interfaces
β”‚ β”‚ β”œβ”€β”€ api.ts
β”‚ β”‚ β”œβ”€β”€ client.ts
β”‚ β”‚ β”œβ”€β”€ index.ts
β”‚ β”‚ └── socket.ts
β”‚ β”œβ”€β”€ message-socket-events
β”‚ β”‚ β”œβ”€β”€ base_event.ts
β”‚ β”‚ β”œβ”€β”€ index.ts
β”‚ β”‚ β”œβ”€β”€ user_channel_added.ts
β”‚ β”‚ └── user_channel_updated.ts
β”‚ β”œβ”€β”€ mezon-client
β”‚ β”‚ β”œβ”€β”€ client
β”‚ β”‚ β”‚ └── MezonClient.ts
β”‚ β”‚ β”œβ”€β”€ manager
β”‚ β”‚ β”‚ β”œβ”€β”€ channel_manager.ts
β”‚ β”‚ β”‚ β”œβ”€β”€ event_manager.ts
β”‚ β”‚ β”‚ β”œβ”€β”€ session_manager.ts
β”‚ β”‚ β”‚ └── socket_manager.ts
β”‚ β”‚ β”œβ”€β”€ structures
β”‚ β”‚ β”‚ β”œβ”€β”€ Clan.ts
β”‚ β”‚ β”‚ β”œβ”€β”€ Message.ts
β”‚ β”‚ β”‚ β”œβ”€β”€ TextChannel.ts
β”‚ β”‚ β”‚ └── User.ts
β”‚ β”‚ └── utils
β”‚ β”‚ β”œβ”€β”€ AsyncThrottleQueue.ts
β”‚ β”‚ β”œβ”€β”€ CacheManager.ts
β”‚ β”‚ └── Collection.ts
β”‚ β”œβ”€β”€ rtapi
β”‚ β”‚ └── realtime.ts
β”‚ β”œβ”€β”€ session.ts
β”‚ β”œβ”€β”€ socket.ts
β”‚ β”œβ”€β”€ sqlite
β”‚ β”‚ └── MessageDatabase.ts
β”‚ β”œβ”€β”€ utils
β”‚ β”‚ β”œβ”€β”€ format_message_input.ts
β”‚ β”‚ β”œβ”€β”€ generate_reply_message.ts
β”‚ β”‚ β”œβ”€β”€ helper.ts
β”‚ β”‚ └── stack.ts
β”‚ β”œβ”€β”€ utils.ts
β”‚ β”œβ”€β”€ web_socket_adapter.ts
β”‚ └── web_socket_adapter_pb.ts
β”œβ”€β”€ tsconfig.esm.json
└── tsconfig.json