# @casual-simulation/aux-records

> Helpers and managers used by the CasualOS records system.

Latest version **4.2.7** (published 2026-08-13) · AGPL-3.0-only license · 0 weekly downloads

## Install

```sh
npm install @casual-simulation/aux-records
pnpm add @casual-simulation/aux-records
yarn add @casual-simulation/aux-records
bun add @casual-simulation/aux-records
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.2.7 |
| Published | 2026-08-13 |
| First published | 2022-01-03 |
| Weekly downloads | 0 |
| License | AGPL-3.0-only |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 33 |
| Unpacked size | 4.1 MB |
| Known vulnerabilities | 0 (+36 in 4 direct dependencies) |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 61 |
| Author | Casual Simulation, Inc. |
| Maintainers | kallyngowdyyeti, casualsimulation |

## Links

- npm: https://www.npmjs.com/package/@casual-simulation/aux-records
- Repository: https://github.com/casual-simulation/casualos
- Issues: https://github.com/casual-simulation/casualos/issues
- npm.io page: https://npm.io/package/@casual-simulation/aux-records

## Dependencies (33)

- [yjs](https://npm.io/package/yjs.md) 13.6.8
- [zod](https://npm.io/package/zod.md) 4.1.12
- [jose](https://npm.io/package/jose.md) 5.4.0
- [mime](https://npm.io/package/mime.md) 2.4.6
- [uuid](https://npm.io/package/uuid.md) 10.0.0
- [axios](https://npm.io/package/axios.md) 1.7.7
- [luxon](https://npm.io/package/luxon.md) 3.4.4
- [libsql](https://npm.io/package/libsql.md) ^0.5.20
- [openai](https://npm.io/package/openai.md) 4.89.0
- [preact](https://npm.io/package/preact.md) 10.28.4
- [hash.js](https://npm.io/package/hash.js.md) 1.1.7
- [base64-js](https://npm.io/package/base64-js.md) ^1.5.1
- [tweetnacl](https://npm.io/package/tweetnacl.md) 1.0.3
- [typesense](https://npm.io/package/typesense.md) 3.0.5
- [es-toolkit](https://npm.io/package/es-toolkit.md) 1.39.10
- [@google/genai](https://npm.io/package/@google/genai.md) ^2.8.0
- [openid-client](https://npm.io/package/openid-client.md) 5.6.1
- [@libsql/client](https://npm.io/package/@libsql/client.md) ^0.15.14
- [node-html-parser](https://npm.io/package/node-html-parser.md) ^6.1.13
- [tigerbeetle-node](https://npm.io/package/tigerbeetle-node.md) 0.16.44
- [@anthropic-ai/sdk](https://npm.io/package/@anthropic-ai/sdk.md) 0.92.0
- [@opentelemetry/api](https://npm.io/package/@opentelemetry/api.md) ^1.9.0
- [livekit-server-sdk](https://npm.io/package/livekit-server-sdk.md) 2.7.2
- [@simplewebauthn/types](https://npm.io/package/@simplewebauthn/types.md) 9.0.1
- [@simplewebauthn/server](https://npm.io/package/@simplewebauthn/server.md) 9.0.3
- [preact-render-to-string](https://npm.io/package/preact-render-to-string.md) 6.6.3
- [@opentelemetry/resources](https://npm.io/package/@opentelemetry/resources.md) ^1.25.1
- [@casual-simulation/crypto](https://npm.io/package/@casual-simulation/crypto.md) ^4.0.5
- [@casual-simulation/timesync](https://npm.io/package/@casual-simulation/timesync.md) ^4.0.0
- [@casual-simulation/aux-common](https://npm.io/package/@casual-simulation/aux-common.md) ^4.2.7
- [@casual-simulation/rate-limit-redis](https://npm.io/package/@casual-simulation/rate-limit-redis.md) ^4.0.0
- [@opentelemetry/semantic-conventions](https://npm.io/package/@opentelemetry/semantic-conventions.md) ^1.25.1
- [@casual-simulation/fast-json-stable-stringify](https://npm.io/package/@casual-simulation/fast-json-stable-stringify.md) ^4.0.5

## Recent versions

- 4.2.7 (latest) — 2026-08-13
- 4.2.8-alpha.38630400059 (alpha) — 2026-10-14
- 3.8.2-alpha.19511653187 (canary) — 2025-11-19
- 4.2.8-alpha.37327680349 — 2026-10-05
- 4.2.8-alpha.37057182636 — 2026-10-02
- 4.2.8-alpha.37022963752 — 2026-10-02
- 4.2.8-alpha.36914636537 — 2026-10-01
- 4.2.8-alpha.36630354067 — 2026-09-29
- 4.2.8-alpha.35775260651 — 2026-09-22
- 4.2.8-alpha.33195981580 — 2026-08-28
- 4.2.7-alpha.30366890271 — 2026-07-28
- 4.2.7-alpha.30323768506 — 2026-07-28
- 4.2.7-alpha.29251457588 — 2026-07-13
- 4.2.7-alpha.28971627223 — 2026-07-08
- 4.2.7-alpha.28801821297 — 2026-07-06
- … 309 more at https://npm.io/package/@casual-simulation/aux-records/versions

## README

# @casual-simulation/aux-records

A comprehensive backend server framework for CasualOS, providing a complete HTTP and WebSocket API layer for authentication, data storage, AI services, subscriptions, and real-time collaboration features.

## Overview

This package contains the `RecordsServer` class and supporting controllers that implement the complete backend infrastructure for CasualOS applications. It provides a production-ready server implementation with authentication, authorization, rate limiting, real-time synchronization, AI integration, payment processing, and more.

## Main Export: RecordsServer

### `RecordsServer`

A full-featured HTTP and WebSocket server that orchestrates multiple specialized controllers to provide a complete backend API for CasualOS applications.

**Core Capabilities:**

### Authentication & Authorization

-   **User Authentication**: Email, SMS, OAuth (OpenID Connect), and WebAuthn support
-   **Session Management**: Create, list, replace, and revoke user sessions
-   **Privo Integration**: Age-gated authentication for COPPA compliance
-   **Role-Based Access**: Support for user roles (superUser, moderator, system)
-   **Policy System**: Fine-grained permissions and resource-level access control

### Data Management

-   **Records System**: Multi-tenant data storage with owner/studio isolation
-   **Record Keys**: Public/private access keys with subjectfull/subjectless policies
-   **Events**: Publish/subscribe event system with count tracking
-   **Files**: Binary file upload/download with presigned URLs
-   **Data Storage**: Key-value data storage with markers and permissions

### Real-Time Collaboration

-   **WebSocket Support**: Full-duplex real-time communication
-   **Branch Synchronization**: Multi-user collaboration with CRDT-like updates
-   **Inst System**: Instance management for shared workspaces
-   **Time Sync**: Client-server time synchronization
-   **Action Broadcasting**: Real-time action distribution to connected clients

### AI & Machine Learning

-   **AI Chat**: Multi-model chat interface (OpenAI, Anthropic, Google)
-   **Image Generation**: AI-powered image creation (OpenAI DALL-E, Stability AI)
-   **Skybox Generation**: 360° skybox generation (Blockade Labs)
-   **3D Model Generation**: AI-driven 3D model creation (Sloyd)
-   **Hume AI**: Emotion AI integration with access token management
-   **OpenAI Realtime**: Real-time audio/video AI capabilities

### Subscriptions & Payments

-   **Stripe Integration**: Full payment processing via Stripe
-   **Subscription Management**: Create, modify, cancel subscriptions
-   **Usage Tracking**: Monitor subscription limits and features
-   **Webhook Handling**: Process Stripe webhooks for payment events
-   **Customer Portal**: Redirect to Stripe's customer management UI

### Studio & comID System

-   **Studios**: Multi-tenant workspaces with member management
-   **comID**: Custom domain support for branded experiences
-   **Member Roles**: Admin and member role assignments
-   **Configuration**: Studio-specific settings (logos, player config, Loom, Hume)
-   **Custom Domains**: Associate custom domains with studios for white-labeling

### Additional Features

-   **Rate Limiting**: Configurable rate limits for API and WebSocket endpoints
-   **Livekit Integration**: Video conferencing with room tokens
-   **Loom Integration**: Video recording capabilities
-   **Moderation**: Content moderation and reporting
-   **Notifications**: Push notifications via web push
-   **Search**: Full-text search across records
-   **Packages**: Package publishing and versioning system
-   **Database**: SQL database access for advanced queries
-   **Webhooks**: HTTP webhook support for external integrations
-   **Contracts**: Smart contract-like functionality

### HTTP API Structure

The server exposes both procedure-based and traditional REST endpoints:

**Procedure-Based API:**

```typescript
// Procedures with HTTP bindings
POST /api/v3/callProcedure
{
    "procedure": "requestLogin",
    "input": { "address": "user@example.com" }
}
```

**REST Endpoints:**

-   `/` - Player index page
-   `/api/v2/login`, `/api/v2/logout` - Authentication
-   `/api/v2/records/*` - Record management
-   `/api/v2/studios/*` - Studio operations
-   `/api/v2/ai/*` - AI services
-   `/api/v2/subscriptions/*` - Subscription management
-   `/api/v2/websocket` - WebSocket upgrade endpoint
-   And many more...

### WebSocket Protocol

The server implements a custom WebSocket protocol for real-time features:

**Event Types:**

-   `login` - Authenticate WebSocket connection
-   `repo/watch_branch` - Subscribe to branch updates
-   `repo/add_updates` - Send updates to a branch
-   `repo/send_action` - Broadcast actions to collaborators
-   `repo/time_sync` - Synchronize time with server
-   `repo/request_missing_permission` - Request elevated permissions

### Usage Example

```typescript
import { RecordsServer } from '@casual-simulation/aux-records';
import {
    AuthController,
    RecordsController,
    // ... other controllers
} from '@casual-simulation/aux-records';

// Create server instance
const server = new RecordsServer({
    allowedAccountOrigins: new Set(['https://app.example.com']),
    allowedApiOrigins: new Set(['https://api.example.com']),
    authController: new AuthController(/* ... */),
    recordsController: new RecordsController(/* ... */),
    eventsController: new EventRecordsController(/* ... */),
    dataController: new DataRecordsController(/* ... */),
    filesController: new FileRecordsController(/* ... */),
    subscriptionController: new SubscriptionController(/* ... */),
    aiController: new AIController(/* ... */),
    websocketController: new WebsocketController(/* ... */),
    // ... other controllers
});

// Handle HTTP requests
const response = await server.handleHttpRequest({
    path: '/api/v2/login',
    method: 'POST',
    body: JSON.stringify({
        address: 'user@example.com',
        addressType: 'email',
    }),
    headers: {
        'content-type': 'application/json',
        origin: 'https://app.example.com',
    },
    ipAddress: '192.168.1.1',
    pathParams: {},
    query: {},
});

// Handle WebSocket upgrades
const wsResponse = await server.handleHttpRequest({
    path: '/api/v2/websocket',
    method: 'GET',
    headers: {
        upgrade: 'websocket',
        connection: 'upgrade',
    },
    // ... other websocket upgrade details
});
```

### Exported Controllers

The package exports numerous controller classes that can be composed together:

-   **AuthController** - User authentication and session management
-   **RecordsController** - Record CRUD operations and access control
-   **EventRecordsController** - Event publishing and subscription
-   **DataRecordsController** - Key-value data storage
-   **FileRecordsController** - Binary file management
-   **SubscriptionController** - Payment and subscription handling
-   **PolicyController** - Permission and policy management
-   **AIController** - AI service orchestration
-   **WebsocketController** - Real-time WebSocket communication
-   **ModerationController** - Content moderation
-   **LivekitController** - Video conferencing
-   **LoomController** - Video recording
-   **RateLimitController** - Rate limiting
-   **NotificationRecordsController** - Push notifications
-   **PackageRecordsController** - Package management
-   **SearchRecordsController** - Full-text search
-   **DatabaseRecordsController** - SQL database access
-   **WebhookRecordsController** - Webhook management
-   **ContractRecordsController** - Contract operations
-   **PurchasableItemRecordsController** - In-app purchases

### Configuration Options

The `RecordsServer` constructor accepts comprehensive configuration:

```typescript
interface RecordsServerOptions {
    allowedAccountOrigins: Set<string>;
    allowedApiOrigins: Set<string>;
    authController: AuthController;
    recordsController: RecordsController;
    eventsController: EventRecordsController;
    dataController: DataRecordsController;
    manualDataController: DataRecordsController;
    filesController: FileRecordsController;
    policyController: PolicyController;
    subscriptionController?: SubscriptionController | null;
    rateLimitController?: RateLimitController | null;
    aiController?: AIController | null;
    websocketController?: WebsocketController | null;
    websocketRateLimitController?: RateLimitController | null;
    moderationController?: ModerationController | null;
    loomController?: LoomController | null;
    webhooksController?: WebhookRecordsController | null;
    notificationsController?: NotificationRecordsController | null;
    packagesController?: PackageRecordsController | null;
    packageVersionController?: PackageVersionRecordsController | null;
    searchRecordsController?: SearchRecordsController | null;
    databaseRecordsController?: DatabaseRecordsController | null;
    contractRecordsController?: ContractRecordsController | null;
    purchasableItemsController?: PurchasableItemRecordsController | null;
    viewTemplateRenderer?: ViewTemplateRenderer | null;
}
```

### Security Features

-   **CORS**: Configurable allowed origins for account and API endpoints
-   **Rate Limiting**: Protect against abuse with configurable limits
-   **Session Validation**: Automatic session key validation for protected endpoints
-   **Origin Validation**: Ensure requests come from authorized sources
-   **Permission System**: Fine-grained resource-level permissions
-   **Audit Logging**: Track operations via OpenTelemetry tracing

### OpenTelemetry Integration

The server includes built-in distributed tracing support:

-   HTTP request/response tracing
-   Semantic conventions for HTTP attributes
-   Custom metrics for request counts and durations
-   Integration with OpenTelemetry collectors

## Dependencies

Major dependencies include:

-   **@casual-simulation/aux-common**: Shared types and utilities
-   **@opentelemetry/api**: Distributed tracing support
-   **zod**: Runtime type validation
-   **axios**: HTTP client for external services
-   **stripe**: Payment processing
-   **@anthropic-ai/sdk**: Anthropic AI integration
-   **@google/genai**: Google AI integration
-   **livekit-server-sdk**: Video conferencing
-   And many more specialized libraries

## Installation

```bash
npm install @casual-simulation/aux-records
```

## Use Cases

-   **Multi-Tenant SaaS**: Build collaborative applications with studio/workspace isolation
-   **AI-Powered Apps**: Integrate multiple AI providers with unified interface
-   **Real-Time Collaboration**: Build Google Docs-like collaborative experiences
-   **Monetized Platforms**: Add subscriptions and payment processing
-   **Branded Experiences**: White-label with custom domains and configuration
-   **Educational Platforms**: Age-gated authentication with Privo
-   **Plugin Marketplaces**: Package publishing and versioning system

---
_Source: https://npm.io/package/@casual-simulation/aux-records · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
