hazo_chat 2.0.14 → 2.0.15
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 +41 -5
- package/SETUP_CHECKLIST.md +73 -0
- package/package.json +1 -1
- package/dist/api/index.d.ts +0 -26
- package/dist/api/index.d.ts.map +0 -1
- package/dist/api/index.js +0 -25
- package/dist/api/index.js.map +0 -1
- package/dist/api/messages.d.ts +0 -34
- package/dist/api/messages.d.ts.map +0 -1
- package/dist/api/messages.js +0 -214
- package/dist/api/messages.js.map +0 -1
- package/dist/api/types.d.ts +0 -69
- package/dist/api/types.d.ts.map +0 -1
- package/dist/api/types.js +0 -8
- package/dist/api/types.js.map +0 -1
- package/dist/api/unread_count.d.ts +0 -57
- package/dist/api/unread_count.d.ts.map +0 -1
- package/dist/api/unread_count.js +0 -86
- package/dist/api/unread_count.js.map +0 -1
- package/dist/components/hazo_chat/hazo_chat.d.ts +0 -28
- package/dist/components/hazo_chat/hazo_chat.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat.js +0 -201
- 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 -42
- package/dist/components/hazo_chat/hazo_chat_context.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_context.js +0 -273
- 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 -140
- 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 -16
- package/dist/components/hazo_chat/hazo_chat_input.d.ts.map +0 -1
- package/dist/components/hazo_chat/hazo_chat_input.js +0 -75
- 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 -18
- package/dist/components/ui/chat_bubble.d.ts.map +0 -1
- package/dist/components/ui/chat_bubble.js +0 -107
- package/dist/components/ui/chat_bubble.js.map +0 -1
- package/dist/components/ui/hover-card.d.ts +0 -13
- package/dist/components/ui/hover-card.d.ts.map +0 -1
- package/dist/components/ui/hover-card.js +0 -17
- package/dist/components/ui/hover-card.js.map +0 -1
- package/dist/components/ui/index.d.ts +0 -19
- package/dist/components/ui/index.d.ts.map +0 -1
- package/dist/components/ui/index.js +0 -21
- 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 -33
- package/dist/hooks/use_chat_messages.d.ts.map +0 -1
- package/dist/hooks/use_chat_messages.js +0 -466
- 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 -41
- package/dist/lib/constants.d.ts.map +0 -1
- package/dist/lib/constants.js +0 -72
- 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 -404
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -11
- package/dist/types/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -316,11 +316,47 @@ This section defines the visual design standards and component behavior specific
|
|
|
316
316
|
|
|
317
317
|
**Important:** When wrapping HazoChat in containers (e.g., Card components):
|
|
318
318
|
|
|
319
|
-
1. **
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
319
|
+
1. **Container Height Requirement:**
|
|
320
|
+
- The `HazoChat` component uses `h-full` which requires its parent container to have a **defined height**.
|
|
321
|
+
- **Required:** Parent container must have a fixed height (e.g., `h-[600px]`, `h-screen`, `min-h-[500px]`).
|
|
322
|
+
- **Example:**
|
|
323
|
+
```tsx
|
|
324
|
+
<div className="h-[600px]"> {/* Required: parent must have height */}
|
|
325
|
+
<HazoChat receiver_user_id={...} />
|
|
326
|
+
</div>
|
|
327
|
+
```
|
|
328
|
+
- **Without a defined height**, the component may not render correctly and the chat message area may collapse.
|
|
329
|
+
|
|
330
|
+
2. **Container Width Requirements:**
|
|
331
|
+
- **Recommended minimum width:** 500px for optimal two-column layout (document viewer + chat messages).
|
|
332
|
+
- **For narrow containers (< 500px):** Document references will automatically open in a new tab when clicked instead of showing in the preview panel.
|
|
333
|
+
- **Document viewer defaults to collapsed** to maximize chat space. Users can expand it using the toggle button.
|
|
334
|
+
- **Example:**
|
|
335
|
+
```tsx
|
|
336
|
+
{/* Recommended: at least 500px width */}
|
|
337
|
+
<div className="w-[600px] h-[600px]">
|
|
338
|
+
<HazoChat receiver_user_id={...} />
|
|
339
|
+
</div>
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
3. **Avoid nested `overflow-hidden`**: Nested overflow-hidden containers can clip rounded corners. Use overflow-hidden only on the HazoChat component itself.
|
|
343
|
+
|
|
344
|
+
4. **Padding**: If wrapping in a Card, ensure proper padding is maintained. Avoid `p-0` on CardContent as it may affect internal spacing.
|
|
345
|
+
|
|
346
|
+
5. **Tailwind Configuration**: Ensure `./node_modules/hazo_chat/dist/**/*.{js,ts,jsx,tsx}` is included in your Tailwind `content` array so all utility classes (including `rounded-*` classes) are compiled.
|
|
347
|
+
|
|
348
|
+
**Complete Container Example:**
|
|
349
|
+
```tsx
|
|
350
|
+
<div className="w-[600px] h-[600px] flex-shrink-0">
|
|
351
|
+
<div className="rounded-xl border shadow-lg p-0 h-full">
|
|
352
|
+
<HazoChat
|
|
353
|
+
receiver_user_id="user-123"
|
|
354
|
+
title="Chat"
|
|
355
|
+
className="h-full"
|
|
356
|
+
/>
|
|
357
|
+
</div>
|
|
358
|
+
</div>
|
|
359
|
+
```
|
|
324
360
|
|
|
325
361
|
#### Typography
|
|
326
362
|
|
package/SETUP_CHECKLIST.md
CHANGED
|
@@ -397,6 +397,79 @@ export default function ChatPage() {
|
|
|
397
397
|
}
|
|
398
398
|
```
|
|
399
399
|
|
|
400
|
+
### Step 5.3: Container Requirements
|
|
401
|
+
|
|
402
|
+
**Critical:** The `HazoChat` component requires specific container dimensions to render correctly.
|
|
403
|
+
|
|
404
|
+
#### Container Height Requirement
|
|
405
|
+
|
|
406
|
+
The component uses `h-full`, which requires its parent container to have a **defined height**. Without this, the chat message area may collapse.
|
|
407
|
+
|
|
408
|
+
**Required:** Parent container must have a fixed height:
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
<div className="h-[600px]"> {/* ✅ Required: parent must have height */}
|
|
412
|
+
<HazoChat receiver_user_id={...} />
|
|
413
|
+
</div>
|
|
414
|
+
|
|
415
|
+
// OR
|
|
416
|
+
|
|
417
|
+
<div className="h-screen"> {/* ✅ Full screen height */}
|
|
418
|
+
<HazoChat receiver_user_id={...} />
|
|
419
|
+
</div>
|
|
420
|
+
|
|
421
|
+
// ❌ WRONG - will cause layout issues
|
|
422
|
+
<div> {/* No height defined */}
|
|
423
|
+
<HazoChat receiver_user_id={...} />
|
|
424
|
+
</div>
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
#### Container Width Requirements
|
|
428
|
+
|
|
429
|
+
- **Recommended minimum width:** 500px for optimal two-column layout (document viewer + chat messages).
|
|
430
|
+
- **For narrow containers (< 500px):** Document references will automatically open in a new tab when clicked instead of showing in the preview panel.
|
|
431
|
+
- **Document viewer defaults to collapsed** to maximize chat space. Users can expand it using the toggle button.
|
|
432
|
+
|
|
433
|
+
```typescript
|
|
434
|
+
// ✅ Recommended: at least 500px width
|
|
435
|
+
<div className="w-[600px] h-[600px]">
|
|
436
|
+
<HazoChat receiver_user_id={...} />
|
|
437
|
+
</div>
|
|
438
|
+
|
|
439
|
+
// ✅ Narrow container: documents will open in new tab
|
|
440
|
+
<div className="w-[400px] h-[600px]">
|
|
441
|
+
<HazoChat receiver_user_id={...} />
|
|
442
|
+
</div>
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
#### Complete Container Example
|
|
446
|
+
|
|
447
|
+
```typescript
|
|
448
|
+
'use client';
|
|
449
|
+
|
|
450
|
+
import { HazoChat } from 'hazo_chat';
|
|
451
|
+
|
|
452
|
+
export default function ChatPage() {
|
|
453
|
+
return (
|
|
454
|
+
<div className="w-[600px] h-[600px] flex-shrink-0">
|
|
455
|
+
<div className="rounded-xl border shadow-lg p-0 h-full">
|
|
456
|
+
<HazoChat
|
|
457
|
+
receiver_user_id="user-123"
|
|
458
|
+
title="Chat"
|
|
459
|
+
className="h-full"
|
|
460
|
+
/>
|
|
461
|
+
</div>
|
|
462
|
+
</div>
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
**Verification:**
|
|
468
|
+
- [ ] Parent container has defined height (e.g., `h-[600px]`, `h-screen`)
|
|
469
|
+
- [ ] Container width is at least 500px for optimal layout (or accept narrow width behavior)
|
|
470
|
+
- [ ] Component renders with proper chat message area visible
|
|
471
|
+
- [ ] Document viewer toggle button is accessible
|
|
472
|
+
|
|
400
473
|
---
|
|
401
474
|
|
|
402
475
|
## 6. UI Components and Styling Setup
|
package/package.json
CHANGED
package/dist/api/index.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hazo_chat API Module
|
|
3
|
-
*
|
|
4
|
-
* Provides exportable API route handlers for Next.js applications.
|
|
5
|
-
* These handlers can be imported and re-exported in your API routes.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // app/api/hazo_chat/messages/route.ts
|
|
10
|
-
* import { createMessagesHandler } from 'hazo_chat/api';
|
|
11
|
-
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
12
|
-
*
|
|
13
|
-
* export const dynamic = 'force-dynamic';
|
|
14
|
-
*
|
|
15
|
-
* const { GET, POST } = createMessagesHandler({
|
|
16
|
-
* getHazoConnect: () => getHazoConnectSingleton()
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* export { GET, POST };
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export { createMessagesHandler } from './messages.js';
|
|
23
|
-
export { createUnreadCountFunction } from './unread_count.js';
|
|
24
|
-
export type { MessagesHandlerOptions, ChatMessageInput, ChatMessageRecord } from './types.js';
|
|
25
|
-
export type { UnreadCountFunctionOptions, UnreadCountResult } from './unread_count.js';
|
|
26
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/api/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAG9D,YAAY,EACV,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,0BAA0B,EAC1B,iBAAiB,EAClB,MAAM,mBAAmB,CAAC"}
|
package/dist/api/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* hazo_chat API Module
|
|
3
|
-
*
|
|
4
|
-
* Provides exportable API route handlers for Next.js applications.
|
|
5
|
-
* These handlers can be imported and re-exported in your API routes.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // app/api/hazo_chat/messages/route.ts
|
|
10
|
-
* import { createMessagesHandler } from 'hazo_chat/api';
|
|
11
|
-
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
12
|
-
*
|
|
13
|
-
* export const dynamic = 'force-dynamic';
|
|
14
|
-
*
|
|
15
|
-
* const { GET, POST } = createMessagesHandler({
|
|
16
|
-
* getHazoConnect: () => getHazoConnectSingleton()
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* export { GET, POST };
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
// Export handler factories
|
|
23
|
-
export { createMessagesHandler } from './messages.js';
|
|
24
|
-
export { createUnreadCountFunction } from './unread_count.js';
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
package/dist/api/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,2BAA2B;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/api/messages.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Messages API Handler Factory
|
|
3
|
-
*
|
|
4
|
-
* Creates GET and POST handlers for the /api/hazo_chat/messages endpoint.
|
|
5
|
-
* These handlers should be used in a Next.js API route.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // app/api/hazo_chat/messages/route.ts
|
|
10
|
-
* import { createMessagesHandler } from 'hazo_chat/api';
|
|
11
|
-
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
12
|
-
*
|
|
13
|
-
* export const dynamic = 'force-dynamic';
|
|
14
|
-
*
|
|
15
|
-
* const { GET, POST } = createMessagesHandler({
|
|
16
|
-
* getHazoConnect: () => getHazoConnectSingleton()
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* export { GET, POST };
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
import { NextRequest, NextResponse } from 'next/server';
|
|
23
|
-
import type { MessagesHandlerOptions } from './types.js';
|
|
24
|
-
/**
|
|
25
|
-
* Creates GET and POST handlers for chat messages
|
|
26
|
-
*
|
|
27
|
-
* @param options - Configuration options
|
|
28
|
-
* @returns Object with GET and POST handlers
|
|
29
|
-
*/
|
|
30
|
-
export declare function createMessagesHandler(options: MessagesHandlerOptions): {
|
|
31
|
-
GET: (request: NextRequest) => Promise<NextResponse>;
|
|
32
|
-
POST: (request: NextRequest) => Promise<NextResponse>;
|
|
33
|
-
};
|
|
34
|
-
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,EAAuC,MAAM,YAAY,CAAC;AAmB9F;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB;mBAWvC,WAAW,KAAG,OAAO,CAAC,YAAY,CAAC;oBA+FlC,WAAW,KAAG,OAAO,CAAC,YAAY,CAAC;EA0GjE"}
|
package/dist/api/messages.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Messages API Handler Factory
|
|
3
|
-
*
|
|
4
|
-
* Creates GET and POST handlers for the /api/hazo_chat/messages endpoint.
|
|
5
|
-
* These handlers should be used in a Next.js API route.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // app/api/hazo_chat/messages/route.ts
|
|
10
|
-
* import { createMessagesHandler } from 'hazo_chat/api';
|
|
11
|
-
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
12
|
-
*
|
|
13
|
-
* export const dynamic = 'force-dynamic';
|
|
14
|
-
*
|
|
15
|
-
* const { GET, POST } = createMessagesHandler({
|
|
16
|
-
* getHazoConnect: () => getHazoConnectSingleton()
|
|
17
|
-
* });
|
|
18
|
-
*
|
|
19
|
-
* export { GET, POST };
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
import { NextResponse } from 'next/server';
|
|
23
|
-
import { cookies } from 'next/headers';
|
|
24
|
-
import { createCrudService } from 'hazo_connect/server';
|
|
25
|
-
// UUID generation for message IDs
|
|
26
|
-
function generateUUID() {
|
|
27
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
28
|
-
const r = Math.random() * 16 | 0;
|
|
29
|
-
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
30
|
-
return v.toString(16);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Default function to get user ID from request cookies
|
|
35
|
-
*/
|
|
36
|
-
async function defaultGetUserIdFromRequest() {
|
|
37
|
-
const cookieStore = await cookies();
|
|
38
|
-
return cookieStore.get('hazo_auth_user_id')?.value || null;
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Creates GET and POST handlers for chat messages
|
|
42
|
-
*
|
|
43
|
-
* @param options - Configuration options
|
|
44
|
-
* @returns Object with GET and POST handlers
|
|
45
|
-
*/
|
|
46
|
-
export function createMessagesHandler(options) {
|
|
47
|
-
const { getHazoConnect, getUserIdFromRequest } = options;
|
|
48
|
-
/**
|
|
49
|
-
* GET handler - Fetch chat messages
|
|
50
|
-
*
|
|
51
|
-
* Query params:
|
|
52
|
-
* - receiver_user_id (required): The other user in the conversation
|
|
53
|
-
* - reference_id (optional): Filter by reference ID
|
|
54
|
-
* - reference_type (optional): Filter by reference type
|
|
55
|
-
*/
|
|
56
|
-
async function GET(request) {
|
|
57
|
-
try {
|
|
58
|
-
// Get current user ID
|
|
59
|
-
const current_user_id = getUserIdFromRequest
|
|
60
|
-
? await getUserIdFromRequest(request)
|
|
61
|
-
: await defaultGetUserIdFromRequest();
|
|
62
|
-
if (!current_user_id) {
|
|
63
|
-
console.error('[hazo_chat/messages GET] No user ID - not authenticated');
|
|
64
|
-
return NextResponse.json({ success: false, error: 'User not authenticated', messages: [] }, { status: 401 });
|
|
65
|
-
}
|
|
66
|
-
// Get query params
|
|
67
|
-
const { searchParams } = new URL(request.url);
|
|
68
|
-
const receiver_user_id = searchParams.get('receiver_user_id');
|
|
69
|
-
const reference_id = searchParams.get('reference_id') || '';
|
|
70
|
-
const reference_type = searchParams.get('reference_type') || '';
|
|
71
|
-
if (!receiver_user_id) {
|
|
72
|
-
console.error('[hazo_chat/messages GET] Missing receiver_user_id');
|
|
73
|
-
return NextResponse.json({ success: false, error: 'receiver_user_id is required', messages: [] }, { status: 400 });
|
|
74
|
-
}
|
|
75
|
-
console.log('[hazo_chat/messages GET] Fetching messages:', {
|
|
76
|
-
current_user_id,
|
|
77
|
-
receiver_user_id,
|
|
78
|
-
reference_id,
|
|
79
|
-
reference_type,
|
|
80
|
-
});
|
|
81
|
-
// Get hazo_connect instance and create CRUD service
|
|
82
|
-
const hazoConnect = getHazoConnect();
|
|
83
|
-
const chatService = createCrudService(hazoConnect, 'hazo_chat');
|
|
84
|
-
let messages = [];
|
|
85
|
-
try {
|
|
86
|
-
// Fetch all messages with reference filters
|
|
87
|
-
const all_messages = await chatService.list((qb) => {
|
|
88
|
-
let builder = qb.select('*');
|
|
89
|
-
if (reference_id) {
|
|
90
|
-
builder = builder.where('reference_id', 'eq', reference_id);
|
|
91
|
-
}
|
|
92
|
-
if (reference_type) {
|
|
93
|
-
builder = builder.where('reference_type', 'eq', reference_type);
|
|
94
|
-
}
|
|
95
|
-
return builder.order('created_at', 'asc');
|
|
96
|
-
});
|
|
97
|
-
// Filter to only messages between current user and receiver
|
|
98
|
-
messages = all_messages.filter((msg) => {
|
|
99
|
-
const is_sent_by_me = msg.sender_user_id === current_user_id && msg.receiver_user_id === receiver_user_id;
|
|
100
|
-
const is_sent_to_me = msg.sender_user_id === receiver_user_id && msg.receiver_user_id === current_user_id;
|
|
101
|
-
return is_sent_by_me || is_sent_to_me;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
catch (dbError) {
|
|
105
|
-
console.error('[hazo_chat/messages GET] Database error:', dbError);
|
|
106
|
-
throw dbError;
|
|
107
|
-
}
|
|
108
|
-
console.log('[hazo_chat/messages GET] Found messages:', messages.length);
|
|
109
|
-
return NextResponse.json({
|
|
110
|
-
success: true,
|
|
111
|
-
messages,
|
|
112
|
-
current_user_id,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
const error_message = error instanceof Error ? error.message : 'Unknown error';
|
|
117
|
-
console.error('[hazo_chat/messages GET] Error:', error_message, error);
|
|
118
|
-
return NextResponse.json({ success: false, error: 'Failed to fetch messages', messages: [] }, { status: 500 });
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* POST handler - Create a new chat message
|
|
123
|
-
*
|
|
124
|
-
* Request body:
|
|
125
|
-
* - receiver_user_id (required): The recipient user ID
|
|
126
|
-
* - message_text (required): The message content
|
|
127
|
-
* - reference_id (optional): Reference ID for context grouping
|
|
128
|
-
* - reference_type (optional): Reference type (default: 'chat')
|
|
129
|
-
*/
|
|
130
|
-
async function POST(request) {
|
|
131
|
-
try {
|
|
132
|
-
// Get current user ID (sender)
|
|
133
|
-
const sender_user_id = getUserIdFromRequest
|
|
134
|
-
? await getUserIdFromRequest(request)
|
|
135
|
-
: await defaultGetUserIdFromRequest();
|
|
136
|
-
if (!sender_user_id) {
|
|
137
|
-
console.error('[hazo_chat/messages POST] No user ID - not authenticated');
|
|
138
|
-
return NextResponse.json({ success: false, error: 'User not authenticated' }, { status: 401 });
|
|
139
|
-
}
|
|
140
|
-
// Parse request body
|
|
141
|
-
const body = await request.json();
|
|
142
|
-
const { receiver_user_id, message_text, reference_id, reference_type } = body;
|
|
143
|
-
// Validate required fields
|
|
144
|
-
if (!receiver_user_id) {
|
|
145
|
-
console.error('[hazo_chat/messages POST] Missing receiver_user_id');
|
|
146
|
-
return NextResponse.json({ success: false, error: 'receiver_user_id is required' }, { status: 400 });
|
|
147
|
-
}
|
|
148
|
-
if (!message_text || message_text.trim() === '') {
|
|
149
|
-
console.error('[hazo_chat/messages POST] Missing or empty message_text');
|
|
150
|
-
return NextResponse.json({ success: false, error: 'message_text is required' }, { status: 400 });
|
|
151
|
-
}
|
|
152
|
-
// Get hazo_connect instance and create CRUD service
|
|
153
|
-
const hazoConnect = getHazoConnect();
|
|
154
|
-
const chatService = createCrudService(hazoConnect, 'hazo_chat');
|
|
155
|
-
// Generate message ID and timestamps
|
|
156
|
-
const message_id = generateUUID();
|
|
157
|
-
const now = new Date().toISOString();
|
|
158
|
-
// Create message record
|
|
159
|
-
const message_record = {
|
|
160
|
-
id: message_id,
|
|
161
|
-
reference_id: reference_id || '',
|
|
162
|
-
reference_type: reference_type || 'chat',
|
|
163
|
-
sender_user_id,
|
|
164
|
-
receiver_user_id,
|
|
165
|
-
message_text: message_text.trim(),
|
|
166
|
-
reference_list: null,
|
|
167
|
-
read_at: null,
|
|
168
|
-
deleted_at: null,
|
|
169
|
-
created_at: now,
|
|
170
|
-
changed_at: now,
|
|
171
|
-
};
|
|
172
|
-
console.log('[hazo_chat/messages POST] Saving message:', {
|
|
173
|
-
id: message_id,
|
|
174
|
-
sender_user_id,
|
|
175
|
-
receiver_user_id,
|
|
176
|
-
reference_id: reference_id || '',
|
|
177
|
-
reference_type: reference_type || 'chat',
|
|
178
|
-
message_length: message_text.length,
|
|
179
|
-
});
|
|
180
|
-
// Save to database
|
|
181
|
-
try {
|
|
182
|
-
await chatService.insert(message_record);
|
|
183
|
-
}
|
|
184
|
-
catch (dbError) {
|
|
185
|
-
console.error('[hazo_chat/messages POST] Database error:', dbError);
|
|
186
|
-
throw dbError;
|
|
187
|
-
}
|
|
188
|
-
console.log('[hazo_chat/messages POST] Message saved successfully:', message_id);
|
|
189
|
-
return NextResponse.json({
|
|
190
|
-
success: true,
|
|
191
|
-
message: {
|
|
192
|
-
id: message_id,
|
|
193
|
-
sender_user_id,
|
|
194
|
-
receiver_user_id,
|
|
195
|
-
reference_id: reference_id || '',
|
|
196
|
-
reference_type: reference_type || 'chat',
|
|
197
|
-
message_text: message_text.trim(),
|
|
198
|
-
reference_list: null,
|
|
199
|
-
read_at: null,
|
|
200
|
-
deleted_at: null,
|
|
201
|
-
created_at: now,
|
|
202
|
-
changed_at: now,
|
|
203
|
-
},
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
catch (error) {
|
|
207
|
-
const error_message = error instanceof Error ? error.message : 'Unknown error';
|
|
208
|
-
console.error('[hazo_chat/messages POST] Error:', error_message, error);
|
|
209
|
-
return NextResponse.json({ success: false, error: 'Failed to save message' }, { status: 500 });
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return { GET, POST };
|
|
213
|
-
}
|
|
214
|
-
//# sourceMappingURL=messages.js.map
|
package/dist/api/messages.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/api/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAe,YAAY,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,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AChC,cAAc,EAAE,cAAc,IAAI,MAAM;oBACxC,YAAY,EAAE,YAAY,CAAC,IAAI,EAAE;oBACjC,cAAc,EAAE,IAAI;oBACpB,OAAO,EAAE,IAAI;oBACb,UAAU,EAAE,IAAI;oBAChB,UAAU,EAAE,GAAG;oBACf,UAAU,EAAE,GAAG;iBAChB;aACF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,aAAa,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC;YAC/E,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;YAExE,OAAO,YAAY,CAAC,IAAI,CACtB,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,wBAAwB,EAAE,EACnD,EAAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AACvB,CAAC"}
|
package/dist/api/types.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* API Handler Types
|
|
3
|
-
*
|
|
4
|
-
* Shared types for the exportable API route handlers.
|
|
5
|
-
* These are used by consumers when setting up their API routes.
|
|
6
|
-
*/
|
|
7
|
-
import type { NextRequest } from 'next/server';
|
|
8
|
-
/**
|
|
9
|
-
* Options for creating message API handlers
|
|
10
|
-
*/
|
|
11
|
-
export interface MessagesHandlerOptions {
|
|
12
|
-
/**
|
|
13
|
-
* Function to get the hazo_connect adapter instance.
|
|
14
|
-
* Called on each request to get a fresh connection.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
19
|
-
*
|
|
20
|
-
* const options = {
|
|
21
|
-
* getHazoConnect: () => getHazoConnectSingleton()
|
|
22
|
-
* };
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
getHazoConnect: () => unknown;
|
|
26
|
-
/**
|
|
27
|
-
* Optional function to extract user ID from the request.
|
|
28
|
-
* Defaults to reading from 'hazo_auth_user_id' cookie.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* // Custom auth extraction
|
|
33
|
-
* const options = {
|
|
34
|
-
* getUserIdFromRequest: (request) => {
|
|
35
|
-
* const token = request.headers.get('Authorization');
|
|
36
|
-
* return decodeToken(token)?.userId || null;
|
|
37
|
-
* }
|
|
38
|
-
* };
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
getUserIdFromRequest?: (request: NextRequest) => string | null | Promise<string | null>;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Chat message input for creating new messages
|
|
45
|
-
*/
|
|
46
|
-
export interface ChatMessageInput {
|
|
47
|
-
receiver_user_id: string;
|
|
48
|
-
message_text: string;
|
|
49
|
-
reference_id?: string;
|
|
50
|
-
reference_type?: string;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Chat message database record
|
|
54
|
-
*/
|
|
55
|
-
export interface ChatMessageRecord {
|
|
56
|
-
id: string;
|
|
57
|
-
reference_id: string;
|
|
58
|
-
reference_type: string;
|
|
59
|
-
sender_user_id: string;
|
|
60
|
-
receiver_user_id: string;
|
|
61
|
-
message_text: string;
|
|
62
|
-
reference_list: string | null;
|
|
63
|
-
read_at: string | null;
|
|
64
|
-
deleted_at: string | null;
|
|
65
|
-
created_at: string;
|
|
66
|
-
changed_at: string;
|
|
67
|
-
[key: string]: unknown;
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/api/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;;;;;;;;OAYG;IACH,cAAc,EAAE,MAAM,OAAO,CAAC;IAE9B;;;;;;;;;;;;;;OAcG;IACH,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACzF;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB"}
|
package/dist/api/types.js
DELETED
package/dist/api/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/api/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unread Count Library Function Factory
|
|
3
|
-
*
|
|
4
|
-
* Creates a function to get unread message counts grouped by reference_id
|
|
5
|
-
* for a given receiver user ID.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* // In your server-side code
|
|
10
|
-
* import { createUnreadCountFunction } from 'hazo_chat/api';
|
|
11
|
-
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
12
|
-
*
|
|
13
|
-
* const getUnreadCount = createUnreadCountFunction({
|
|
14
|
-
* getHazoConnect: () => getHazoConnectSingleton()
|
|
15
|
-
* });
|
|
16
|
-
*
|
|
17
|
-
* // Use the function
|
|
18
|
-
* const unreadCounts = await getUnreadCount('receiver-user-id-123');
|
|
19
|
-
* // Returns: [{ reference_id: 'ref-1', count: 5 }, { reference_id: 'ref-2', count: 3 }]
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
/**
|
|
23
|
-
* Options for creating the unread count function
|
|
24
|
-
*/
|
|
25
|
-
export interface UnreadCountFunctionOptions {
|
|
26
|
-
/**
|
|
27
|
-
* Function to get the hazo_connect adapter instance.
|
|
28
|
-
* Called each time the function is invoked to get a fresh connection.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* import { getHazoConnectSingleton } from 'hazo_connect/nextjs/setup';
|
|
33
|
-
*
|
|
34
|
-
* const options = {
|
|
35
|
-
* getHazoConnect: () => getHazoConnectSingleton()
|
|
36
|
-
* };
|
|
37
|
-
* ```
|
|
38
|
-
*/
|
|
39
|
-
getHazoConnect: () => unknown;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Result type for unread count function
|
|
43
|
-
*/
|
|
44
|
-
export interface UnreadCountResult {
|
|
45
|
-
/** The reference ID */
|
|
46
|
-
reference_id: string;
|
|
47
|
-
/** Number of unread messages for this reference */
|
|
48
|
-
count: number;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Creates a function to get unread message counts by reference_id
|
|
52
|
-
*
|
|
53
|
-
* @param options - Configuration options
|
|
54
|
-
* @returns Function that takes receiver_user_id and returns unread counts
|
|
55
|
-
*/
|
|
56
|
-
export declare function createUnreadCountFunction(options: UnreadCountFunctionOptions): (receiver_user_id: string) => Promise<UnreadCountResult[]>;
|
|
57
|
-
//# sourceMappingURL=unread_count.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unread_count.d.ts","sourceRoot":"","sources":["../../src/api/unread_count.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAMH;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;;;;;;;;;OAYG;IACH,cAAc,EAAE,MAAM,OAAO,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uBAAuB;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,0BAA0B,IAUzE,kBAAkB,MAAM,KACvB,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA2DhC"}
|