@vex-chat/types
v2.0.0
Published
Wire protocol types for the Vex encrypted chat platform
Readme
@vex-chat/types
Wire protocol types for the Vex encrypted chat platform. Used by both the server and client so they speak the same shapes.
What's in the box
- TypeScript interfaces for every REST payload, WebSocket message, and database record on the wire.
- Zod 4 schemas (
XSchema) paired with every interface for runtime validation:UserSchema.parse(data),KeyBundleSchema.safeParse(data), etc. - OpenAPI 3.1 document generated from the Zod schemas, shipped as a subpath export (
@vex-chat/types/openapi.json). 16 REST paths. - AsyncAPI 3.0 document for the WebSocket protocol, also a subpath export (
@vex-chat/types/asyncapi.json). 11 message types across 5 client→server and 6 server→client channels. - Discriminated
WSMessageunion soswitch (msg.type)narrows exhaustively in TypeScript.
Install
npm install @vex-chat/typeszod is a required runtime dependency (auto-installed). No peer dependencies.
Usage
import { UserSchema, type User } from "@vex-chat/types";
// Compile-time: plain TypeScript interface
const alice: User = {
userID: "a-uuid",
username: "alice",
lastSeen: new Date().toISOString(),
};
// Runtime: validate untrusted input from the wire
const parsed = UserSchema.parse(incomingJson); // throws on mismatch
const safe = UserSchema.safeParse(incomingJson); // { success, data } | { success, error }For the REST/WS protocol docs:
import openapi from "@vex-chat/types/openapi.json" with { type: "json" };
import asyncapi from "@vex-chat/types/asyncapi.json" with { type: "json" };