hazo_chat 1.1.0 → 2.0.2
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 +161 -152
- package/SETUP_CHECKLIST.md +191 -587
- package/package.json +17 -7
- package/dist/components/hazo_chat/hazo_chat.d.ts +0 -16
- package/dist/components/hazo_chat/hazo_chat.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat.js +0 -155
- package/dist/components/hazo_chat/hazo_chat.js.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_attachment_preview.d.ts +0 -17
- package/dist/components/hazo_chat/hazo_chat_attachment_preview.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_attachment_preview.js +0 -60
- package/dist/components/hazo_chat/hazo_chat_attachment_preview.js.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_context.d.ts +0 -36
- package/dist/components/hazo_chat/hazo_chat_context.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_context.js +0 -249
- package/dist/components/hazo_chat/hazo_chat_context.js.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_document_viewer.d.ts +0 -15
- package/dist/components/hazo_chat/hazo_chat_document_viewer.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_document_viewer.js +0 -111
- package/dist/components/hazo_chat/hazo_chat_document_viewer.js.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_header.d.ts +0 -16
- package/dist/components/hazo_chat/hazo_chat_header.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_header.js +0 -24
- package/dist/components/hazo_chat/hazo_chat_header.js.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_input.d.ts +0 -18
- package/dist/components/hazo_chat/hazo_chat_input.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_input.js +0 -134
- package/dist/components/hazo_chat/hazo_chat_input.js.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_messages.d.ts +0 -17
- package/dist/components/hazo_chat/hazo_chat_messages.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_messages.js +0 -109
- package/dist/components/hazo_chat/hazo_chat_messages.js.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_reference_list.d.ts +0 -16
- package/dist/components/hazo_chat/hazo_chat_reference_list.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_reference_list.js +0 -59
- package/dist/components/hazo_chat/hazo_chat_reference_list.js.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_sidebar.d.ts +0 -18
- package/dist/components/hazo_chat/hazo_chat_sidebar.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_sidebar.js +0 -72
- package/dist/components/hazo_chat/hazo_chat_sidebar.js.map +0 -1
- package/dist/components/hazo_chat/index.d.ts +0 -16
- package/dist/components/hazo_chat/index.d.ts.map +0 -1
- package/dist/components/hazo_chat/index.js +0 -19
- package/dist/components/hazo_chat/index.js.map +0 -1
- package/dist/components/index.d.ts +0 -9
- package/dist/components/index.d.ts.map +0 -1
- package/dist/components/index.js +0 -11
- package/dist/components/index.js.map +0 -1
- package/dist/components/ui/avatar.d.ts +0 -13
- package/dist/components/ui/avatar.d.ts.map +0 -1
- package/dist/components/ui/avatar.js +0 -28
- package/dist/components/ui/avatar.js.map +0 -1
- package/dist/components/ui/badge.d.ts +0 -16
- package/dist/components/ui/badge.d.ts.map +0 -1
- package/dist/components/ui/badge.js +0 -36
- package/dist/components/ui/badge.js.map +0 -1
- package/dist/components/ui/button.d.ts +0 -18
- package/dist/components/ui/button.d.ts.map +0 -1
- package/dist/components/ui/button.js +0 -47
- package/dist/components/ui/button.js.map +0 -1
- package/dist/components/ui/chat_bubble.d.ts +0 -19
- package/dist/components/ui/chat_bubble.d.ts.map +0 -1
- package/dist/components/ui/chat_bubble.js +0 -101
- package/dist/components/ui/chat_bubble.js.map +0 -1
- package/dist/components/ui/index.d.ts +0 -18
- package/dist/components/ui/index.d.ts.map +0 -1
- package/dist/components/ui/index.js +0 -20
- package/dist/components/ui/index.js.map +0 -1
- package/dist/components/ui/input.d.ts +0 -11
- package/dist/components/ui/input.d.ts.map +0 -1
- package/dist/components/ui/input.js +0 -18
- package/dist/components/ui/input.js.map +0 -1
- package/dist/components/ui/loading_skeleton.d.ts +0 -19
- package/dist/components/ui/loading_skeleton.d.ts.map +0 -1
- package/dist/components/ui/loading_skeleton.js +0 -30
- package/dist/components/ui/loading_skeleton.js.map +0 -1
- package/dist/components/ui/scroll-area.d.ts +0 -12
- package/dist/components/ui/scroll-area.d.ts.map +0 -1
- package/dist/components/ui/scroll-area.js +0 -25
- package/dist/components/ui/scroll-area.js.map +0 -1
- package/dist/components/ui/separator.d.ts +0 -11
- package/dist/components/ui/separator.d.ts.map +0 -1
- package/dist/components/ui/separator.js +0 -18
- package/dist/components/ui/separator.js.map +0 -1
- package/dist/components/ui/skeleton.d.ts +0 -9
- package/dist/components/ui/skeleton.d.ts.map +0 -1
- package/dist/components/ui/skeleton.js +0 -16
- package/dist/components/ui/skeleton.js.map +0 -1
- package/dist/components/ui/textarea.d.ts +0 -11
- package/dist/components/ui/textarea.d.ts.map +0 -1
- package/dist/components/ui/textarea.js +0 -18
- package/dist/components/ui/textarea.js.map +0 -1
- package/dist/components/ui/tooltip.d.ts +0 -14
- package/dist/components/ui/tooltip.d.ts.map +0 -1
- package/dist/components/ui/tooltip.js +0 -30
- package/dist/components/ui/tooltip.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -10
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -10
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/use_chat_messages.d.ts +0 -25
- package/dist/hooks/use_chat_messages.d.ts.map +0 -1
- package/dist/hooks/use_chat_messages.js +0 -430
- package/dist/hooks/use_chat_messages.js.map +0 -1
- package/dist/hooks/use_chat_references.d.ts +0 -17
- package/dist/hooks/use_chat_references.d.ts.map +0 -1
- package/dist/hooks/use_chat_references.js +0 -133
- package/dist/hooks/use_chat_references.js.map +0 -1
- package/dist/hooks/use_file_upload.d.ts +0 -23
- package/dist/hooks/use_file_upload.d.ts.map +0 -1
- package/dist/hooks/use_file_upload.js +0 -212
- package/dist/hooks/use_file_upload.js.map +0 -1
- package/dist/index.d.ts +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -17
- package/dist/index.js.map +0 -1
- package/dist/lib/config.d.ts +0 -41
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/config.js +0 -93
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/constants.d.ts +0 -39
- package/dist/lib/constants.d.ts.map +0 -1
- package/dist/lib/constants.js +0 -70
- package/dist/lib/constants.js.map +0 -1
- package/dist/lib/index.d.ts +0 -9
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/index.js +0 -9
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/utils.d.ts +0 -17
- package/dist/lib/utils.d.ts.map +0 -1
- package/dist/lib/utils.js +0 -20
- package/dist/lib/utils.js.map +0 -1
- package/dist/types/index.d.ts +0 -367
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -8
- package/dist/types/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
A full-featured React chat component library for 1-1 communication with document sharing, file attachments, and real-time messaging capabilities.
|
|
4
4
|
|
|
5
|
+
**Version 2.0** - Now with API-first architecture! No server-side dependencies in client components.
|
|
6
|
+
|
|
5
7
|
## Features
|
|
6
8
|
|
|
7
9
|
- 📱 **Responsive Design** - Works on desktop and mobile with adaptive layout
|
|
@@ -13,117 +15,107 @@ A full-featured React chat component library for 1-1 communication with document
|
|
|
13
15
|
- ✅ **Read Receipts** - Track message read status
|
|
14
16
|
- 🗑️ **Soft Delete** - Delete messages with undo capability
|
|
15
17
|
- 🎨 **Customizable** - TailwindCSS-based theming
|
|
18
|
+
- 🚀 **API-First** - No server-side dependencies in client components
|
|
16
19
|
|
|
17
20
|
## Table of Contents
|
|
18
21
|
|
|
19
22
|
- [Installation](#installation)
|
|
20
23
|
- [Quick Start](#quick-start)
|
|
21
|
-
- [
|
|
22
|
-
- [Main Component](#main-component)
|
|
24
|
+
- [API Routes Setup](#api-routes-setup)
|
|
23
25
|
- [Props Reference](#props-reference)
|
|
24
26
|
- [Hooks](#hooks)
|
|
25
27
|
- [Types](#types)
|
|
26
28
|
- [Database Schema](#database-schema)
|
|
27
29
|
- [Configuration](#configuration)
|
|
30
|
+
- [Migration from v1.x](#migration-from-v1x)
|
|
28
31
|
- [Development](#development)
|
|
29
32
|
- [License](#license)
|
|
30
33
|
|
|
31
34
|
## Installation
|
|
32
35
|
|
|
33
36
|
```bash
|
|
34
|
-
npm install hazo_chat hazo_connect
|
|
37
|
+
npm install hazo_chat hazo_connect next
|
|
35
38
|
```
|
|
36
39
|
|
|
37
40
|
## Quick Start
|
|
38
41
|
|
|
42
|
+
### Step 1: Create API Routes
|
|
43
|
+
|
|
44
|
+
The component communicates via API calls. Create the required endpoints:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
// app/api/hazo_chat/messages/route.ts
|
|
48
|
+
import { createMessagesHandler } from 'hazo_chat/api';
|
|
49
|
+
import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
50
|
+
|
|
51
|
+
export const dynamic = 'force-dynamic';
|
|
52
|
+
|
|
53
|
+
const { GET, POST } = createMessagesHandler({
|
|
54
|
+
getHazoConnect: () => getHazoConnectSingleton()
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export { GET, POST };
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Step 2: Use the Component
|
|
61
|
+
|
|
39
62
|
```tsx
|
|
40
63
|
'use client';
|
|
41
64
|
|
|
42
65
|
import { HazoChat } from 'hazo_chat';
|
|
43
|
-
import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
44
66
|
|
|
45
|
-
|
|
46
|
-
const hazo_auth = {
|
|
47
|
-
hazo_get_auth: async () => {
|
|
48
|
-
const response = await fetch('/api/hazo_auth/me');
|
|
49
|
-
const data = await response.json();
|
|
50
|
-
return data.is_authenticated ? { id: data.user_id, email: data.email } : null;
|
|
51
|
-
},
|
|
52
|
-
hazo_get_user_profiles: async (user_ids: string[]) => {
|
|
53
|
-
const response = await fetch('/api/hazo_auth/profiles', {
|
|
54
|
-
method: 'POST',
|
|
55
|
-
headers: { 'Content-Type': 'application/json' },
|
|
56
|
-
body: JSON.stringify({ user_ids }),
|
|
57
|
-
});
|
|
58
|
-
const data = await response.json();
|
|
59
|
-
return data.profiles;
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
function ChatPage() {
|
|
64
|
-
const hazo_connect = getHazoConnectSingleton();
|
|
65
|
-
|
|
67
|
+
export default function ChatPage() {
|
|
66
68
|
return (
|
|
67
|
-
<
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
/>
|
|
69
|
+
<div className="h-screen">
|
|
70
|
+
<HazoChat
|
|
71
|
+
receiver_user_id="recipient-uuid"
|
|
72
|
+
reference_id="conversation-123"
|
|
73
|
+
reference_type="support"
|
|
74
|
+
title="Chat with Support"
|
|
75
|
+
subtitle="We're here to help"
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
77
78
|
);
|
|
78
79
|
}
|
|
79
80
|
```
|
|
80
81
|
|
|
81
|
-
|
|
82
|
+
That's it! No need to pass database adapters or authentication services - everything works via API calls.
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
## API Routes Setup
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|---------|---------|-------------|
|
|
87
|
-
| `hazo_connect` | ^2.3.1 | Database adapter (required) |
|
|
88
|
-
| `hazo_auth` | ^1.0.0 | Authentication service (required) |
|
|
89
|
-
| `react` | ^18.0.0 | React framework |
|
|
90
|
-
| `react-dom` | ^18.0.0 | React DOM |
|
|
86
|
+
hazo_chat requires these API endpoints:
|
|
91
87
|
|
|
92
|
-
|
|
88
|
+
| Endpoint | Method | Description |
|
|
89
|
+
|----------|--------|-------------|
|
|
90
|
+
| `/api/hazo_chat/messages` | GET | Fetch chat messages |
|
|
91
|
+
| `/api/hazo_chat/messages` | POST | Send a new message |
|
|
92
|
+
| `/api/hazo_auth/me` | GET | Get current authenticated user |
|
|
93
|
+
| `/api/hazo_auth/profiles` | POST | Fetch user profiles by IDs |
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
2. **Authentication** - Working hazo_auth setup with user management
|
|
96
|
-
3. **API Routes** - Backend endpoints for chat operations
|
|
97
|
-
4. **Configuration Files** - hazo_connect_config.ini for database connection
|
|
95
|
+
### Using Exportable Handlers (Recommended)
|
|
98
96
|
|
|
99
|
-
|
|
97
|
+
```typescript
|
|
98
|
+
// app/api/hazo_chat/messages/route.ts
|
|
99
|
+
import { createMessagesHandler } from 'hazo_chat/api';
|
|
100
|
+
import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
100
101
|
|
|
101
|
-
|
|
102
|
+
export const dynamic = 'force-dynamic';
|
|
102
103
|
|
|
103
|
-
|
|
104
|
+
const { GET, POST } = createMessagesHandler({
|
|
105
|
+
getHazoConnect: () => getHazoConnectSingleton(),
|
|
106
|
+
// Optional: custom authentication
|
|
107
|
+
getUserIdFromRequest: async (request) => {
|
|
108
|
+
// Return user ID from your auth system
|
|
109
|
+
return request.cookies.get('user_id')?.value || null;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
104
112
|
|
|
105
|
-
|
|
113
|
+
export { GET, POST };
|
|
114
|
+
```
|
|
106
115
|
|
|
107
|
-
|
|
108
|
-
import { HazoChat } from 'hazo_chat';
|
|
116
|
+
### Custom Implementation
|
|
109
117
|
|
|
110
|
-
|
|
111
|
-
hazo_connect={adapter}
|
|
112
|
-
hazo_auth={authService}
|
|
113
|
-
receiver_user_id="user-123"
|
|
114
|
-
document_save_location="/uploads"
|
|
115
|
-
reference_id="project-456"
|
|
116
|
-
reference_type="project_chat"
|
|
117
|
-
timezone="Australia/Sydney"
|
|
118
|
-
title="Project Discussion"
|
|
119
|
-
subtitle="Design Review"
|
|
120
|
-
additional_references={[
|
|
121
|
-
{ id: 'doc-1', type: 'document', name: 'Design.pdf', url: '/files/design.pdf', scope: 'field' }
|
|
122
|
-
]}
|
|
123
|
-
on_close={() => console.log('Chat closed')}
|
|
124
|
-
className="h-[600px]"
|
|
125
|
-
/>
|
|
126
|
-
```
|
|
118
|
+
If you need more control, implement the endpoints manually. See [SETUP_CHECKLIST.md](./SETUP_CHECKLIST.md) for detailed examples.
|
|
127
119
|
|
|
128
120
|
## Props Reference
|
|
129
121
|
|
|
@@ -131,12 +123,10 @@ import { HazoChat } from 'hazo_chat';
|
|
|
131
123
|
|
|
132
124
|
| Prop | Type | Required | Default | Description |
|
|
133
125
|
|------|------|----------|---------|-------------|
|
|
134
|
-
| `hazo_connect` | `HazoConnectAdapter` | ✅ | - | Database adapter instance |
|
|
135
|
-
| `hazo_auth` | `HazoAuthInstance` | ✅ | - | Authentication service |
|
|
136
126
|
| `receiver_user_id` | `string` | ✅ | - | UUID of the chat recipient |
|
|
137
|
-
| `
|
|
138
|
-
| `reference_id` | `string` | ❌ | - | Main reference ID for the chat |
|
|
127
|
+
| `reference_id` | `string` | ❌ | - | Reference ID for chat context grouping |
|
|
139
128
|
| `reference_type` | `string` | ❌ | `'chat'` | Type of reference |
|
|
129
|
+
| `api_base_url` | `string` | ❌ | `'/api/hazo_chat'` | Base URL for API endpoints |
|
|
140
130
|
| `additional_references` | `ReferenceItem[]` | ❌ | `[]` | Pre-loaded document references |
|
|
141
131
|
| `timezone` | `string` | ❌ | `'GMT+10'` | Timezone for timestamps |
|
|
142
132
|
| `title` | `string` | ❌ | - | Chat header title |
|
|
@@ -144,25 +134,23 @@ import { HazoChat } from 'hazo_chat';
|
|
|
144
134
|
| `on_close` | `() => void` | ❌ | - | Close button callback |
|
|
145
135
|
| `className` | `string` | ❌ | - | Additional CSS classes |
|
|
146
136
|
|
|
147
|
-
###
|
|
148
|
-
|
|
149
|
-
The authentication service must implement these methods:
|
|
137
|
+
### Example with All Props
|
|
150
138
|
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
139
|
+
```tsx
|
|
140
|
+
<HazoChat
|
|
141
|
+
receiver_user_id="user-123"
|
|
142
|
+
reference_id="project-456"
|
|
143
|
+
reference_type="project_chat"
|
|
144
|
+
api_base_url="/api/hazo_chat"
|
|
145
|
+
timezone="Australia/Sydney"
|
|
146
|
+
title="Project Discussion"
|
|
147
|
+
subtitle="Design Review"
|
|
148
|
+
additional_references={[
|
|
149
|
+
{ id: 'doc-1', type: 'document', name: 'Design.pdf', url: '/files/design.pdf', scope: 'field' }
|
|
150
|
+
]}
|
|
151
|
+
on_close={() => console.log('Chat closed')}
|
|
152
|
+
className="h-[600px]"
|
|
153
|
+
/>
|
|
166
154
|
```
|
|
167
155
|
|
|
168
156
|
## Hooks
|
|
@@ -187,10 +175,10 @@ const {
|
|
|
187
175
|
mark_as_read, // (message_id) => Promise<void>
|
|
188
176
|
refresh, // () => void - Reload messages
|
|
189
177
|
} = useChatMessages({
|
|
190
|
-
hazo_connect,
|
|
191
|
-
hazo_auth,
|
|
192
|
-
reference_id: 'chat-123',
|
|
193
178
|
receiver_user_id: 'user-456',
|
|
179
|
+
reference_id: 'chat-123',
|
|
180
|
+
reference_type: 'direct',
|
|
181
|
+
api_base_url: '/api/hazo_chat',
|
|
194
182
|
polling_interval: 5000, // Optional, default: 5000ms
|
|
195
183
|
messages_per_page: 20, // Optional, default: 20
|
|
196
184
|
});
|
|
@@ -233,10 +221,9 @@ const {
|
|
|
233
221
|
is_uploading, // boolean
|
|
234
222
|
validation_errors, // string[]
|
|
235
223
|
} = useFileUpload({
|
|
236
|
-
upload_location: '/uploads
|
|
224
|
+
upload_location: '/api/hazo_chat/uploads',
|
|
237
225
|
max_file_size_mb: 10, // Optional, default: 10
|
|
238
226
|
allowed_types: ['pdf', 'png', 'jpg'], // Optional
|
|
239
|
-
upload_function: customUploader, // Optional custom uploader
|
|
240
227
|
});
|
|
241
228
|
```
|
|
242
229
|
|
|
@@ -264,6 +251,17 @@ interface ChatMessage {
|
|
|
264
251
|
}
|
|
265
252
|
```
|
|
266
253
|
|
|
254
|
+
### HazoUserProfile
|
|
255
|
+
|
|
256
|
+
```typescript
|
|
257
|
+
interface HazoUserProfile {
|
|
258
|
+
id: string;
|
|
259
|
+
name: string;
|
|
260
|
+
email?: string;
|
|
261
|
+
avatar_url?: string;
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
267
265
|
### ChatReferenceItem
|
|
268
266
|
|
|
269
267
|
```typescript
|
|
@@ -279,18 +277,6 @@ interface ChatReferenceItem {
|
|
|
279
277
|
}
|
|
280
278
|
```
|
|
281
279
|
|
|
282
|
-
### CreateMessagePayload
|
|
283
|
-
|
|
284
|
-
```typescript
|
|
285
|
-
interface CreateMessagePayload {
|
|
286
|
-
reference_id: string;
|
|
287
|
-
reference_type: string;
|
|
288
|
-
receiver_user_id: string;
|
|
289
|
-
message_text: string;
|
|
290
|
-
reference_list?: ChatReferenceItem[];
|
|
291
|
-
}
|
|
292
|
-
```
|
|
293
|
-
|
|
294
280
|
## Database Schema
|
|
295
281
|
|
|
296
282
|
### hazo_chat Table
|
|
@@ -307,11 +293,7 @@ CREATE TABLE hazo_chat (
|
|
|
307
293
|
read_at TEXT,
|
|
308
294
|
deleted_at TEXT,
|
|
309
295
|
created_at TEXT NOT NULL,
|
|
310
|
-
changed_at TEXT NOT NULL
|
|
311
|
-
|
|
312
|
-
-- Foreign keys (if using referential integrity)
|
|
313
|
-
FOREIGN KEY (sender_user_id) REFERENCES hazo_users(id),
|
|
314
|
-
FOREIGN KEY (receiver_user_id) REFERENCES hazo_users(id)
|
|
296
|
+
changed_at TEXT NOT NULL
|
|
315
297
|
);
|
|
316
298
|
|
|
317
299
|
-- Indexes for performance
|
|
@@ -341,14 +323,56 @@ max_file_size_mb = 10
|
|
|
341
323
|
allowed_types = pdf,png,jpg,jpeg,gif,txt,doc,docx
|
|
342
324
|
```
|
|
343
325
|
|
|
344
|
-
|
|
326
|
+
## Migration from v1.x
|
|
327
|
+
|
|
328
|
+
Version 2.0 introduces breaking changes for a simpler, more reliable architecture.
|
|
329
|
+
|
|
330
|
+
### What Changed
|
|
331
|
+
|
|
332
|
+
| v1.x | v2.x |
|
|
333
|
+
|------|------|
|
|
334
|
+
| Pass `hazo_connect` prop | Not needed - uses API calls |
|
|
335
|
+
| Pass `hazo_auth` prop | Not needed - uses API calls |
|
|
336
|
+
| Pass `document_save_location` prop | Not needed |
|
|
337
|
+
| Direct database access | API-based data access |
|
|
338
|
+
|
|
339
|
+
### Migration Steps
|
|
340
|
+
|
|
341
|
+
1. **Remove adapter props:**
|
|
342
|
+
|
|
343
|
+
```tsx
|
|
344
|
+
// Before (v1.x)
|
|
345
|
+
<HazoChat
|
|
346
|
+
hazo_connect={adapter}
|
|
347
|
+
hazo_auth={authService}
|
|
348
|
+
document_save_location="/uploads"
|
|
349
|
+
receiver_user_id="..."
|
|
350
|
+
/>
|
|
351
|
+
|
|
352
|
+
// After (v2.x)
|
|
353
|
+
<HazoChat
|
|
354
|
+
receiver_user_id="..."
|
|
355
|
+
/>
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
2. **Create API routes** (see [API Routes Setup](#api-routes-setup))
|
|
359
|
+
|
|
360
|
+
3. **Update imports:**
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
// The API handler factory is new
|
|
364
|
+
import { createMessagesHandler } from 'hazo_chat/api';
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Why the Change?
|
|
368
|
+
|
|
369
|
+
The v1.x architecture required passing server-side adapters (`hazo_connect`, `hazo_auth`) to client components. This caused issues:
|
|
345
370
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
| `timezone` | 'GMT+10' | Default timezone for timestamps |
|
|
371
|
+
- "Module not found: Can't resolve 'fs'" errors
|
|
372
|
+
- Hydration mismatches
|
|
373
|
+
- Complex webpack configuration
|
|
374
|
+
|
|
375
|
+
The v2.x API-first architecture solves these by keeping all server code in API routes.
|
|
352
376
|
|
|
353
377
|
## Development
|
|
354
378
|
|
|
@@ -372,30 +396,17 @@ npm run dev:test-app
|
|
|
372
396
|
npm run build:test-app
|
|
373
397
|
```
|
|
374
398
|
|
|
375
|
-
### Project Structure
|
|
376
|
-
|
|
377
|
-
```
|
|
378
|
-
hazo_chat/
|
|
379
|
-
├── src/
|
|
380
|
-
│ ├── components/
|
|
381
|
-
│ │ ├── hazo_chat/ # Main chat components
|
|
382
|
-
│ │ └── ui/ # Reusable UI components
|
|
383
|
-
│ ├── hooks/ # React hooks
|
|
384
|
-
│ ├── lib/ # Utilities and constants
|
|
385
|
-
│ └── types/ # TypeScript definitions
|
|
386
|
-
├── test-app/ # Next.js test application
|
|
387
|
-
├── dist/ # Compiled output (git-ignored)
|
|
388
|
-
└── package.json
|
|
389
|
-
```
|
|
390
|
-
|
|
391
399
|
### Package Exports
|
|
392
400
|
|
|
393
401
|
```typescript
|
|
394
402
|
// Main export
|
|
395
403
|
import { HazoChat, useChatMessages, useChatReferences, useFileUpload } from 'hazo_chat';
|
|
396
404
|
|
|
405
|
+
// API handlers (for server-side routes)
|
|
406
|
+
import { createMessagesHandler } from 'hazo_chat/api';
|
|
407
|
+
|
|
397
408
|
// Components only
|
|
398
|
-
import { HazoChat, ChatBubble
|
|
409
|
+
import { HazoChat, ChatBubble } from 'hazo_chat/components';
|
|
399
410
|
|
|
400
411
|
// Library utilities
|
|
401
412
|
import { DEFAULT_POLLING_INTERVAL, MIME_TYPE_MAP } from 'hazo_chat/lib';
|
|
@@ -405,22 +416,20 @@ import { DEFAULT_POLLING_INTERVAL, MIME_TYPE_MAP } from 'hazo_chat/lib';
|
|
|
405
416
|
|
|
406
417
|
### Common Issues
|
|
407
418
|
|
|
408
|
-
1. **"
|
|
409
|
-
-
|
|
410
|
-
- The adapter must be the HazoConnectAdapter type, not a raw connection
|
|
419
|
+
1. **"Module not found: Can't resolve 'fs'"**
|
|
420
|
+
- This shouldn't happen in v2.x. If it does, ensure you're not importing from `hazo_connect/server` in client components.
|
|
411
421
|
|
|
412
|
-
2. **
|
|
413
|
-
-
|
|
414
|
-
-
|
|
422
|
+
2. **Messages not loading**
|
|
423
|
+
- Check that API routes exist and return correct responses
|
|
424
|
+
- Verify authentication (check `/api/hazo_auth/me`)
|
|
425
|
+
- Check browser console and network tab for errors
|
|
415
426
|
|
|
416
|
-
3. **
|
|
417
|
-
-
|
|
418
|
-
- Check
|
|
427
|
+
3. **401 Unauthorized errors**
|
|
428
|
+
- Ensure the user is logged in
|
|
429
|
+
- Check that `hazo_auth_user_id` cookie is set
|
|
419
430
|
|
|
420
|
-
4. **
|
|
421
|
-
-
|
|
422
|
-
- Check API route `/api/hazo_chat/messages` exists and works
|
|
423
|
-
- Ensure `reference_id` is provided to the component
|
|
431
|
+
4. **CORS errors**
|
|
432
|
+
- API routes should be on the same domain as the frontend
|
|
424
433
|
|
|
425
434
|
## Related Packages
|
|
426
435
|
|