hazo_chat 3.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,14 +2,17 @@
2
2
 
3
3
  A full-featured React chat component library for group-based communication with document sharing, file attachments, and real-time messaging capabilities.
4
4
 
5
- **Version 3.0** - Now with group-based chat! Multiple users can participate in a single chat group, perfect for support staff rotating on client sessions.
5
+ **Version 3.1** - Generic schema supporting multiple chat patterns: support (client-to-staff), peer (1:1), and group conversations.
6
+
7
+ **Version 3.0** - Introduced group-based chat architecture. Multiple users can participate in a single chat group, perfect for support staff rotating on client sessions.
6
8
 
7
9
  **Version 2.0** introduced API-first architecture with no server-side dependencies in client components.
8
10
 
9
11
  ## Features
10
12
 
11
13
  - 👥 **Group-Based Chat** - Multiple users can participate in a single chat group
12
- - 🔄 **Role-Based Access** - Support for 'client' and 'staff' roles within groups
14
+ - 🏗️ **Multiple Chat Patterns** - Support for support (client-to-staff), peer (1:1), and group conversations
15
+ - 🔄 **Role-Based Access** - Support for 'client', 'staff', 'owner', 'admin', and 'member' roles within groups
13
16
  - 📱 **Responsive Design** - Works on desktop and mobile with adaptive layout
14
17
  - 💬 **Real-time Messaging** - Polling or manual refresh modes for message updates with optimistic UI
15
18
  - 📎 **File Attachments** - Support for documents and images with preview
@@ -1079,33 +1082,160 @@ interface ChatReferenceItem {
1079
1082
 
1080
1083
  **Note on MIME Type:** The `mime_type` property is optional. If not provided, the component will automatically infer the MIME type from the file extension (e.g., `.jpg` → `image/jpeg`, `.pdf` → `application/pdf`). This ensures document preview works even when `mime_type` is not explicitly set. Supported file extensions for inference include: `pdf`, `png`, `jpg`, `jpeg`, `gif`, `webp`, `txt`, `doc`, `docx`.
1081
1084
 
1085
+ ### ChatGroup (NEW in v3.0, UPDATED in v3.1)
1086
+
1087
+ ```typescript
1088
+ interface ChatGroup {
1089
+ id: string;
1090
+ client_user_id: string | null | undefined; // NULLABLE in v3.1 (only required for 'support' groups)
1091
+ group_type: ChatGroupType; // NEW in v3.1
1092
+ name?: string | null;
1093
+ created_at: string;
1094
+ changed_at: string;
1095
+ }
1096
+ ```
1097
+
1098
+ ### ChatGroupType (NEW in v3.1)
1099
+
1100
+ ```typescript
1101
+ type ChatGroupType = 'support' | 'peer' | 'group';
1102
+ ```
1103
+
1104
+ **Group Type Definitions:**
1105
+ - `'support'`: Client-to-staff support conversation (requires `client_user_id`)
1106
+ - `'peer'`: Peer-to-peer direct message between two users
1107
+ - `'group'`: Multi-user group conversation
1108
+
1109
+ ### ChatGroupUser (NEW in v3.0, UPDATED in v3.1)
1110
+
1111
+ ```typescript
1112
+ interface ChatGroupUser {
1113
+ chat_group_id: string;
1114
+ user_id: string;
1115
+ role: ChatGroupUserRole; // EXPANDED in v3.1
1116
+ created_at: string;
1117
+ changed_at: string;
1118
+ }
1119
+ ```
1120
+
1121
+ ### ChatGroupUserRole (NEW in v3.0, EXPANDED in v3.1)
1122
+
1123
+ ```typescript
1124
+ // v3.0
1125
+ type ChatGroupUserRole = 'client' | 'staff';
1126
+
1127
+ // v3.1 (expanded)
1128
+ type ChatGroupUserRole = 'client' | 'staff' | 'owner' | 'admin' | 'member';
1129
+ ```
1130
+
1131
+ **Role Definitions:**
1132
+ - `'client'`: Customer/end-user in support scenarios
1133
+ - `'staff'`: Support personnel in support scenarios
1134
+ - `'owner'`: Creator/owner of peer or group chats
1135
+ - `'admin'`: Delegated administrator in group chats
1136
+ - `'member'`: Standard participant in peer or group chats
1137
+
1138
+ ### ChatGroupWithMembers (NEW in v3.0, UPDATED in v3.1)
1139
+
1140
+ ```typescript
1141
+ interface ChatGroupWithMembers extends ChatGroup {
1142
+ members: (ChatGroupUser & { profile?: HazoUserProfile })[];
1143
+ owner_profile?: HazoUserProfile; // NEW in v3.1 - profile of the group owner
1144
+ }
1145
+ ```
1146
+
1082
1147
  ## Database Schema
1083
1148
 
1084
1149
  **Breaking Changes in v3.0:** The database schema has been updated to support group-based chat. Migration required.
1085
1150
 
1086
- ### hazo_chat_group Table (NEW in v3.0)
1151
+ **New in v3.1:** Generic schema supporting multiple chat patterns - support, peer, and group conversations.
1152
+
1153
+ ### PostgreSQL Enum Types (RECOMMENDED)
1154
+
1155
+ For PostgreSQL installations, create these custom enum types for type safety and consistency:
1087
1156
 
1088
1157
  ```sql
1089
- -- PostgreSQL
1158
+ -- Reference type for chat contexts
1159
+ CREATE TYPE hazo_enum_chat_type AS ENUM ('chat', 'field', 'project', 'support', 'general');
1160
+
1161
+ -- Group type for conversation patterns (v3.1)
1162
+ CREATE TYPE hazo_enum_group_type AS ENUM ('support', 'peer', 'group');
1163
+
1164
+ -- Membership roles (v3.1)
1165
+ CREATE TYPE hazo_enum_group_role AS ENUM ('client', 'staff', 'owner', 'admin', 'member');
1166
+ ```
1167
+
1168
+ ### Group Types
1169
+
1170
+ hazo_chat supports three distinct group types to accommodate different conversation patterns:
1171
+
1172
+ | Type | Description | Use Case | `client_user_id` | Typical Roles |
1173
+ |------|-------------|----------|------------------|---------------|
1174
+ | **support** | Client-to-staff support conversation | Customer support, helpdesk | Required (identifies the client) | 'client', 'staff' |
1175
+ | **peer** | Peer-to-peer direct message (1:1) | Direct messaging between equals | Not used (null) | 'owner', 'member' |
1176
+ | **group** | Multi-user group conversation | Team collaboration, channels | Not used (null) | 'owner', 'admin', 'member' |
1177
+
1178
+ ### Role Types
1179
+
1180
+ The `role` field in `hazo_chat_group_users` defines each member's permissions and relationship to the group:
1181
+
1182
+ | Role | Description | Used In | Capabilities |
1183
+ |------|-------------|---------|--------------|
1184
+ | **client** | Customer/end-user receiving support | support groups | Send messages, view messages |
1185
+ | **staff** | Support personnel helping clients | support groups | Send messages, view messages, assist client |
1186
+ | **owner** | Creator/owner of the conversation | peer, group | Full control, can add/remove members |
1187
+ | **admin** | Delegated administrator | group | Can manage members, moderate content |
1188
+ | **member** | Standard participant | peer, group | Send messages, view messages |
1189
+
1190
+ ### hazo_chat_group Table (UPDATED in v3.1)
1191
+
1192
+ ```sql
1193
+ -- PostgreSQL with enums (RECOMMENDED)
1194
+ CREATE TABLE hazo_chat_group (
1195
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
1196
+ client_user_id UUID REFERENCES hazo_users(id), -- NULLABLE in v3.1
1197
+ group_type hazo_enum_group_type NOT NULL DEFAULT 'support', -- NEW in v3.1
1198
+ name VARCHAR(255),
1199
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
1200
+ changed_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
1201
+ );
1202
+
1203
+ -- PostgreSQL without enums (alternative)
1090
1204
  CREATE TABLE hazo_chat_group (
1091
1205
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
1092
- client_user_id UUID NOT NULL REFERENCES hazo_users(id),
1206
+ client_user_id UUID REFERENCES hazo_users(id), -- NULLABLE in v3.1
1207
+ group_type VARCHAR(20) NOT NULL DEFAULT 'support' CHECK (group_type IN ('support', 'peer', 'group')), -- NEW in v3.1
1093
1208
  name VARCHAR(255),
1094
1209
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
1095
1210
  changed_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
1096
1211
  );
1097
1212
 
1098
1213
  CREATE INDEX idx_hazo_chat_group_client ON hazo_chat_group(client_user_id);
1214
+ CREATE INDEX idx_hazo_chat_group_type ON hazo_chat_group(group_type); -- NEW in v3.1
1099
1215
  ```
1100
1216
 
1101
- ### hazo_chat_group_users Table (NEW in v3.0)
1217
+ **Column Changes in v3.1:**
1218
+ - `client_user_id`: Changed from `NOT NULL` to nullable - only required for 'support' type groups
1219
+ - `group_type`: NEW field - defines the conversation pattern ('support', 'peer', 'group')
1220
+
1221
+ ### hazo_chat_group_users Table (UPDATED in v3.1)
1102
1222
 
1103
1223
  ```sql
1104
- -- PostgreSQL
1224
+ -- PostgreSQL with enums (RECOMMENDED)
1105
1225
  CREATE TABLE hazo_chat_group_users (
1106
1226
  chat_group_id UUID NOT NULL REFERENCES hazo_chat_group(id) ON DELETE CASCADE,
1107
1227
  user_id UUID NOT NULL REFERENCES hazo_users(id) ON DELETE CASCADE,
1108
- role VARCHAR(20) NOT NULL CHECK (role IN ('client', 'staff')),
1228
+ role hazo_enum_group_role NOT NULL, -- EXPANDED in v3.1
1229
+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
1230
+ changed_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
1231
+ PRIMARY KEY (chat_group_id, user_id)
1232
+ );
1233
+
1234
+ -- PostgreSQL without enums (alternative)
1235
+ CREATE TABLE hazo_chat_group_users (
1236
+ chat_group_id UUID NOT NULL REFERENCES hazo_chat_group(id) ON DELETE CASCADE,
1237
+ user_id UUID NOT NULL REFERENCES hazo_users(id) ON DELETE CASCADE,
1238
+ role VARCHAR(20) NOT NULL CHECK (role IN ('client', 'staff', 'owner', 'admin', 'member')), -- EXPANDED in v3.1
1109
1239
  created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
1110
1240
  changed_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
1111
1241
  PRIMARY KEY (chat_group_id, user_id)
@@ -1113,8 +1243,12 @@ CREATE TABLE hazo_chat_group_users (
1113
1243
 
1114
1244
  CREATE INDEX idx_hazo_chat_group_users_user ON hazo_chat_group_users(user_id);
1115
1245
  CREATE INDEX idx_hazo_chat_group_users_group ON hazo_chat_group_users(chat_group_id);
1246
+ CREATE INDEX idx_hazo_chat_group_users_role ON hazo_chat_group_users(role); -- NEW in v3.1
1116
1247
  ```
1117
1248
 
1249
+ **Column Changes in v3.1:**
1250
+ - `role`: EXPANDED from ('client', 'staff') to ('client', 'staff', 'owner', 'admin', 'member')
1251
+
1118
1252
  ### hazo_chat Table (MODIFIED in v3.0)
1119
1253
 
1120
1254
  ```sql
@@ -1209,6 +1343,157 @@ max_file_size_mb = 10
1209
1343
  allowed_types = pdf,png,jpg,jpeg,gif,txt,doc,docx
1210
1344
  ```
1211
1345
 
1346
+ ## Migration from v3.0 to v3.1
1347
+
1348
+ **Version 3.1** introduces schema changes to support multiple chat patterns (support, peer, group) while maintaining backward compatibility.
1349
+
1350
+ ### What Changed in v3.1
1351
+
1352
+ | v3.0 | v3.1 |
1353
+ |------|------|
1354
+ | Fixed support pattern only | Three patterns: support, peer, group |
1355
+ | `client_user_id` always required | `client_user_id` nullable (only for support groups) |
1356
+ | 2 roles: 'client', 'staff' | 5 roles: 'client', 'staff', 'owner', 'admin', 'member' |
1357
+ | No `group_type` field | NEW `group_type` field ('support', 'peer', 'group') |
1358
+
1359
+ ### Migration Steps (v3.0 to v3.1)
1360
+
1361
+ **Important:** v3.1 is backward compatible with v3.0 schema. Existing support-type groups continue to work without changes.
1362
+
1363
+ 1. **Create PostgreSQL Enum Types (Optional but Recommended):**
1364
+
1365
+ ```sql
1366
+ -- Reference type for chat contexts
1367
+ CREATE TYPE hazo_enum_chat_type AS ENUM ('chat', 'field', 'project', 'support', 'general');
1368
+
1369
+ -- Group type for conversation patterns
1370
+ CREATE TYPE hazo_enum_group_type AS ENUM ('support', 'peer', 'group');
1371
+
1372
+ -- Membership roles
1373
+ CREATE TYPE hazo_enum_group_role AS ENUM ('client', 'staff', 'owner', 'admin', 'member');
1374
+ ```
1375
+
1376
+ 2. **Add group_type Column to hazo_chat_group:**
1377
+
1378
+ ```sql
1379
+ -- Add group_type column (defaults to 'support' for backward compatibility)
1380
+ ALTER TABLE hazo_chat_group
1381
+ ADD COLUMN group_type VARCHAR(20) NOT NULL DEFAULT 'support'
1382
+ CHECK (group_type IN ('support', 'peer', 'group'));
1383
+
1384
+ -- Or with enum type (if you created the enum):
1385
+ ALTER TABLE hazo_chat_group
1386
+ ADD COLUMN group_type hazo_enum_group_type NOT NULL DEFAULT 'support';
1387
+
1388
+ -- Add index for group_type
1389
+ CREATE INDEX idx_hazo_chat_group_type ON hazo_chat_group(group_type);
1390
+ ```
1391
+
1392
+ 3. **Make client_user_id Nullable:**
1393
+
1394
+ ```sql
1395
+ -- Remove NOT NULL constraint from client_user_id
1396
+ ALTER TABLE hazo_chat_group
1397
+ ALTER COLUMN client_user_id DROP NOT NULL;
1398
+ ```
1399
+
1400
+ 4. **Update Role Constraint in hazo_chat_group_users:**
1401
+
1402
+ ```sql
1403
+ -- Drop old constraint
1404
+ ALTER TABLE hazo_chat_group_users
1405
+ DROP CONSTRAINT IF EXISTS hazo_chat_group_users_role_check;
1406
+
1407
+ -- Add new constraint with expanded roles
1408
+ ALTER TABLE hazo_chat_group_users
1409
+ ADD CONSTRAINT hazo_chat_group_users_role_check
1410
+ CHECK (role IN ('client', 'staff', 'owner', 'admin', 'member'));
1411
+
1412
+ -- Or with enum type (if you created the enum):
1413
+ ALTER TABLE hazo_chat_group_users
1414
+ ALTER COLUMN role TYPE hazo_enum_group_role
1415
+ USING role::hazo_enum_group_role;
1416
+
1417
+ -- Add index for role
1418
+ CREATE INDEX idx_hazo_chat_group_users_role ON hazo_chat_group_users(role);
1419
+ ```
1420
+
1421
+ 5. **Verify Existing Data:**
1422
+
1423
+ ```sql
1424
+ -- All existing groups should have group_type = 'support'
1425
+ SELECT group_type, COUNT(*)
1426
+ FROM hazo_chat_group
1427
+ GROUP BY group_type;
1428
+
1429
+ -- All existing members should have role IN ('client', 'staff')
1430
+ SELECT role, COUNT(*)
1431
+ FROM hazo_chat_group_users
1432
+ GROUP BY role;
1433
+ ```
1434
+
1435
+ ### Creating New Group Types
1436
+
1437
+ After migration, you can create peer and group conversations:
1438
+
1439
+ ```typescript
1440
+ // Support group (v3.0 style - still works)
1441
+ await db.insert_with_result('hazo_chat_group', {
1442
+ client_user_id: 'client-uuid',
1443
+ group_type: 'support',
1444
+ name: 'Customer Support'
1445
+ });
1446
+
1447
+ // Peer-to-peer chat (v3.1)
1448
+ await db.insert_with_result('hazo_chat_group', {
1449
+ client_user_id: null, // Not used for peer chats
1450
+ group_type: 'peer',
1451
+ name: 'Alice & Bob'
1452
+ });
1453
+
1454
+ // Group conversation (v3.1)
1455
+ await db.insert_with_result('hazo_chat_group', {
1456
+ client_user_id: null, // Not used for group chats
1457
+ group_type: 'group',
1458
+ name: 'Project Team'
1459
+ });
1460
+ ```
1461
+
1462
+ ### No Code Changes Required
1463
+
1464
+ The v3.1 schema changes are transparent to the component API. Your existing code continues to work:
1465
+
1466
+ ```tsx
1467
+ // This works for all group types (support, peer, group)
1468
+ <HazoChat
1469
+ chat_group_id="group-123"
1470
+ reference_id="chat-456"
1471
+ reference_type="support"
1472
+ />
1473
+ ```
1474
+
1475
+ ### TypeScript Type Updates
1476
+
1477
+ If you use TypeScript types from hazo_chat:
1478
+
1479
+ ```typescript
1480
+ // v3.1 types (automatically available after updating package)
1481
+ import type {
1482
+ ChatGroup, // client_user_id is now optional
1483
+ ChatGroupType, // 'support' | 'peer' | 'group'
1484
+ ChatGroupUserRole // 'client' | 'staff' | 'owner' | 'admin' | 'member'
1485
+ } from 'hazo_chat';
1486
+
1487
+ const group: ChatGroup = {
1488
+ id: 'group-123',
1489
+ client_user_id: null, // ✅ Now optional
1490
+ group_type: 'peer', // ✅ New field
1491
+ name: 'Chat',
1492
+ created_at: new Date().toISOString(),
1493
+ changed_at: new Date().toISOString()
1494
+ };
1495
+ ```
1496
+
1212
1497
  ## Migration from v2.x to v3.0
1213
1498
 
1214
1499
  **Version 3.0** introduces breaking changes to support group-based chat architecture.
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../src/api/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAIxD,OAAO,KAAK,EAAE,sBAAsB,EAAkG,MAAM,YAAY,CAAC;AA0FzJ;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB;mBAcvC,WAAW,KAAG,OAAO,CAAC,YAAY,CAAC;oBA2KlC,WAAW,KAAG,OAAO,CAAC,YAAY,CAAC;EAiJjE;AAED;;;;;;;;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