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

@collab-kit/utils

v0.0.17

Published

Shared types and utilities for Collab-Kit

Readme

Collab-Kit Utils

Shared types and utilities for Collab-Kit.

Install

npm install @collab-kit/utils

Store Schemas

Define typed KV store schemas with defineStores(). The schema is used by @collab-kit/client for type-safe CRUD operations and by the server for validation.

import { defineStores } from '@collab-kit/utils';

const stores = defineStores({
  settings: {
    theme: { type: 'string', required: true, default: 'light' },
    fontSize: { type: 'number', required: true, default: 14 },
    notifications: { type: 'boolean', default: true },
  },
  cursors: {
    x: { type: 'number', required: true },
    y: { type: 'number', required: true },
    color: { type: 'string', default: '#000000' },
  },
});

Field Options

| Option | Type | Description | |---|---|---| | type | 'string' \| 'number' \| 'boolean' | Field primitive type | | required | boolean | If true, field must be present on set. Defaults to false | | default | string \| number \| boolean | Default value applied when field is missing on set |

Type Inference

Schemas are automatically inferred as TypeScript types via InferDocument<S>:

import type { InferDocument } from '@collab-kit/utils';

// Given a schema:
const schema = {
  theme: { type: 'string' as const, required: true as const },
  fontSize: { type: 'number' as const, required: true as const },
  notifications: { type: 'boolean' as const },
};

// InferDocument<typeof schema> resolves to:
// { theme: string; fontSize: number; notifications?: boolean }

Fields with required: true become mandatory keys. All others become optional.

Types

Core Types

import type {
  CollabKitClientOptions,
  CollabKitUser,
  CollabKitRoom,
  CollabKitOrganization,
  ServerResponse,
} from '@collab-kit/utils';

CollabKitClientOptions<T>

Options passed to the client constructor.

{
  serverUrl: string;     // Base HTTP(S) URL of the server
  authToken: string;     // JWT from POST /v1/accounts/:accountId/users
  stores?: T;            // Optional store schemas from defineStores()
}

CollabKitUser

{
  id: string;
  room_id: string;
  name: string;
  profile_picture?: string;
  custom_id?: string;          // optional external identifier
  created_at: string;
  joined_at?: string;
  left_at?: string;
  status: 'online' | 'offline';
  token?: string;              // JWT, present when created via POST /v1/accounts/:accountId/users
  following?: string[];        // ordered chain of followed user IDs
  followers?: string[];        // user IDs who transitively follow this user
}

CollabKitRoom

{
  id: string;
  account_id: string;
  name: string;
  custom_id?: string;          // optional external identifier
  created_at: string;
  state: 'active' | 'disabled';
  duration_seconds: number;
  active_participants: number;
  total_users_created: number;
}

ServerResponse<T>

Standard response envelope used across all server responses.

{
  type: string;
  success: boolean;
  description: string;
  data: T;
  error: ServerResponseError | null;
  requestId?: string;
}

Storage Types

import type {
  UploadResult,
  StorageFile,
  StorageGetAllOptions,
} from '@collab-kit/utils';

| Type | Fields | |---|---| | UploadResult | { key: string; url: string } | | StorageFile | { key, url, filename, mimeType, size, uploadedAt, uploadedBy } | | StorageGetAllOptions | { mimeType?: string \| string[]; userId?: string } |

Socket Types

Types for building custom WebSocket integrations.

import type {
  SocketClientMessage,      // Union of all client-to-server messages
  SocketServerMessage,      // Union of all server-to-client messages
  SocketClientEventMap,     // Lifecycle event map (connected, disconnected, etc.)
  SocketState,              // Connection state enum
  SocketClientOptions,      // Socket constructor options
  SocketMessageResponseMap, // Maps each request MessageType to its response data shape
  InferResponseData,        // Infers response data type from a client message type
} from '@collab-kit/utils';

Type-Safe Responses

SocketMessageResponseMap maps each client request type to the shape of the server's response data field. InferResponseData<T> uses this to infer the response type from a request message, eliminating the need for manual type casts when using sendMessagePromise:

// Before (manual cast):
const response = (await socket.sendMessagePromise(message)) as ServerResponse<{
  comment: CollabKitComment;
}>;

// After (automatically inferred):
const response = await socket.sendMessagePromise(message);
// response.data is typed as { comment: CollabKitComment }

Comment Types

import type {
  CollabKitComment,        // Comment data model (id, text, reactions, tags, replies)
  AddCommentMessage,       // Client -> Server: add a comment
  DeleteCommentMessage,    // Client -> Server: delete a comment
  GetAllCommentsMessage,   // Client -> Server: fetch all comments
} from '@collab-kit/utils';

CollabKitComment

{
  id: string;
  userId: string;
  text: string;
  reactions: Record<string, string[]>; // reaction text -> userIds
  tags: string[];                       // tagged userIds
  parentId: string | null;              // null for top-level, parent ID for replies
  replies: CollabKitComment[];          // nested replies (one level)
  createdAt: string;
}