# Generated Centrifugo RPC Client

**DO NOT EDIT** - This file is auto-generated.

## Overview

This directory contains auto-generated TypeScript client code for Centrifugo WebSocket RPC.

## Regeneration

Base command:

```bash
poetry run python manage.py generate_centrifugo_clients --typescript
```

**Note**: Check `core/management/commands/` for a project-specific wrapper command (e.g., `generate_centrifuge_web`) or a Makefile target that handles output paths and file copying.

## Documentation

Full documentation: https://djangocfg.com/docs/features/integrations/centrifugo/

## Source

- **Generator**: `django_cfg.apps.integrations.centrifugo.codegen`
- **Command**: `generate_centrifugo_clients`
- **Django handlers**: Check your project's Centrifugo RPC handlers decorated with `@websocket_rpc`

## Files

| File | Description |
|------|-------------|
| `types.ts` | TypeScript interfaces generated from Pydantic models |
| `client.ts` | Thin wrapper with typed RPC methods |
| `index.ts` | Public exports |

## Available Methods

{% if methods %}
{% for method in methods %}
- `{{ method.name_ts }}()` - {{ method.docstring }}
{% endfor %}
{% else %}
No RPC methods discovered. Add `@websocket_rpc` decorated handlers.
{% endif %}

## CRITICAL: Authentication

### Token Types

| Token Type | Format | Usage |
|------------|--------|-------|
| **Centrifugo JWT** | `eyJhbGciOi...` | WebSocket connection - USE THIS! |
| CLI Token | `clit_xxx...` | REST API only - NOT for Centrifugo! |

### Getting Centrifugo JWT Token

**Option 1: From User Profile (Recommended)**

```json
// GET /cfg/accounts/profile/
{
  "centrifugo": {
    "token": "eyJhbGciOi...",      // <-- Use for CentrifugoRPCClient
    "centrifugo_url": "ws://...",
    "channels": ["user#4"]
  }
}
```

**Option 2: Dedicated Endpoint**

```
GET /cfg/centrifugo/auth/token/
Authorization: Bearer <jwt_access_token>
```

### Common Mistake

❌ **WRONG:** Using CLI token for Centrifugo
```typescript
// BAD - Centrifugo won't recognize this token
const client = new CentrifugoRPCClient({
  url: 'ws://...',
  token: 'clit_xxx...',  // WRONG TOKEN TYPE!
  userId: '4'
});
// Result: user="" in server logs, authentication fails
```

✅ **CORRECT:** Using Centrifugo JWT
```typescript
// GOOD - JWT from profile.centrifugo.token
const client = new CentrifugoRPCClient({
  url: profile.centrifugo.centrifugo_url,
  token: profile.centrifugo.token,  // eyJhbGciOi... format
  userId: String(profile.id)
});
```

## Usage Example

```typescript
import { APIClient } from '.';

// With existing Centrifugo client
const apiClient = new APIClient(centrifugoClient);

// Call RPC methods
{% if methods %}
const result = await apiClient.{{ methods[0].name_ts }}(params);
{% else %}
const result = await apiClient.someMethod(params);
{% endif %}
```

## Debugging

If Centrifugo server logs show `user: ""` (empty), authentication failed.
Check that you're using Centrifugo JWT, not CLI token!

---
Generated: {{ timestamp }}
