hazo_chat 2.0.11 → 2.0.12

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.
Files changed (154) hide show
  1. package/README.md +43 -6
  2. package/package.json +3 -2
  3. package/dist/api/index.d.ts +0 -26
  4. package/dist/api/index.d.ts.map +0 -1
  5. package/dist/api/index.js +0 -25
  6. package/dist/api/index.js.map +0 -1
  7. package/dist/api/messages.d.ts +0 -34
  8. package/dist/api/messages.d.ts.map +0 -1
  9. package/dist/api/messages.js +0 -214
  10. package/dist/api/messages.js.map +0 -1
  11. package/dist/api/types.d.ts +0 -69
  12. package/dist/api/types.d.ts.map +0 -1
  13. package/dist/api/types.js +0 -8
  14. package/dist/api/types.js.map +0 -1
  15. package/dist/api/unread_count.d.ts +0 -57
  16. package/dist/api/unread_count.d.ts.map +0 -1
  17. package/dist/api/unread_count.js +0 -86
  18. package/dist/api/unread_count.js.map +0 -1
  19. package/dist/components/hazo_chat/hazo_chat.d.ts +0 -28
  20. package/dist/components/hazo_chat/hazo_chat.d.ts.map +0 -1
  21. package/dist/components/hazo_chat/hazo_chat.js +0 -201
  22. package/dist/components/hazo_chat/hazo_chat.js.map +0 -1
  23. package/dist/components/hazo_chat/hazo_chat_attachment_preview.d.ts +0 -17
  24. package/dist/components/hazo_chat/hazo_chat_attachment_preview.d.ts.map +0 -1
  25. package/dist/components/hazo_chat/hazo_chat_attachment_preview.js +0 -60
  26. package/dist/components/hazo_chat/hazo_chat_attachment_preview.js.map +0 -1
  27. package/dist/components/hazo_chat/hazo_chat_context.d.ts +0 -42
  28. package/dist/components/hazo_chat/hazo_chat_context.d.ts.map +0 -1
  29. package/dist/components/hazo_chat/hazo_chat_context.js +0 -273
  30. package/dist/components/hazo_chat/hazo_chat_context.js.map +0 -1
  31. package/dist/components/hazo_chat/hazo_chat_document_viewer.d.ts +0 -15
  32. package/dist/components/hazo_chat/hazo_chat_document_viewer.d.ts.map +0 -1
  33. package/dist/components/hazo_chat/hazo_chat_document_viewer.js +0 -111
  34. package/dist/components/hazo_chat/hazo_chat_document_viewer.js.map +0 -1
  35. package/dist/components/hazo_chat/hazo_chat_header.d.ts +0 -16
  36. package/dist/components/hazo_chat/hazo_chat_header.d.ts.map +0 -1
  37. package/dist/components/hazo_chat/hazo_chat_header.js +0 -24
  38. package/dist/components/hazo_chat/hazo_chat_header.js.map +0 -1
  39. package/dist/components/hazo_chat/hazo_chat_input.d.ts +0 -16
  40. package/dist/components/hazo_chat/hazo_chat_input.d.ts.map +0 -1
  41. package/dist/components/hazo_chat/hazo_chat_input.js +0 -75
  42. package/dist/components/hazo_chat/hazo_chat_input.js.map +0 -1
  43. package/dist/components/hazo_chat/hazo_chat_messages.d.ts +0 -17
  44. package/dist/components/hazo_chat/hazo_chat_messages.d.ts.map +0 -1
  45. package/dist/components/hazo_chat/hazo_chat_messages.js +0 -109
  46. package/dist/components/hazo_chat/hazo_chat_messages.js.map +0 -1
  47. package/dist/components/hazo_chat/hazo_chat_reference_list.d.ts +0 -16
  48. package/dist/components/hazo_chat/hazo_chat_reference_list.d.ts.map +0 -1
  49. package/dist/components/hazo_chat/hazo_chat_reference_list.js +0 -59
  50. package/dist/components/hazo_chat/hazo_chat_reference_list.js.map +0 -1
  51. package/dist/components/hazo_chat/hazo_chat_sidebar.d.ts +0 -18
  52. package/dist/components/hazo_chat/hazo_chat_sidebar.d.ts.map +0 -1
  53. package/dist/components/hazo_chat/hazo_chat_sidebar.js +0 -72
  54. package/dist/components/hazo_chat/hazo_chat_sidebar.js.map +0 -1
  55. package/dist/components/hazo_chat/index.d.ts +0 -16
  56. package/dist/components/hazo_chat/index.d.ts.map +0 -1
  57. package/dist/components/hazo_chat/index.js +0 -19
  58. package/dist/components/hazo_chat/index.js.map +0 -1
  59. package/dist/components/index.d.ts +0 -9
  60. package/dist/components/index.d.ts.map +0 -1
  61. package/dist/components/index.js +0 -11
  62. package/dist/components/index.js.map +0 -1
  63. package/dist/components/ui/avatar.d.ts +0 -13
  64. package/dist/components/ui/avatar.d.ts.map +0 -1
  65. package/dist/components/ui/avatar.js +0 -28
  66. package/dist/components/ui/avatar.js.map +0 -1
  67. package/dist/components/ui/badge.d.ts +0 -16
  68. package/dist/components/ui/badge.d.ts.map +0 -1
  69. package/dist/components/ui/badge.js +0 -36
  70. package/dist/components/ui/badge.js.map +0 -1
  71. package/dist/components/ui/button.d.ts +0 -18
  72. package/dist/components/ui/button.d.ts.map +0 -1
  73. package/dist/components/ui/button.js +0 -47
  74. package/dist/components/ui/button.js.map +0 -1
  75. package/dist/components/ui/chat_bubble.d.ts +0 -18
  76. package/dist/components/ui/chat_bubble.d.ts.map +0 -1
  77. package/dist/components/ui/chat_bubble.js +0 -107
  78. package/dist/components/ui/chat_bubble.js.map +0 -1
  79. package/dist/components/ui/hover-card.d.ts +0 -13
  80. package/dist/components/ui/hover-card.d.ts.map +0 -1
  81. package/dist/components/ui/hover-card.js +0 -17
  82. package/dist/components/ui/hover-card.js.map +0 -1
  83. package/dist/components/ui/index.d.ts +0 -19
  84. package/dist/components/ui/index.d.ts.map +0 -1
  85. package/dist/components/ui/index.js +0 -21
  86. package/dist/components/ui/index.js.map +0 -1
  87. package/dist/components/ui/input.d.ts +0 -11
  88. package/dist/components/ui/input.d.ts.map +0 -1
  89. package/dist/components/ui/input.js +0 -18
  90. package/dist/components/ui/input.js.map +0 -1
  91. package/dist/components/ui/loading_skeleton.d.ts +0 -19
  92. package/dist/components/ui/loading_skeleton.d.ts.map +0 -1
  93. package/dist/components/ui/loading_skeleton.js +0 -30
  94. package/dist/components/ui/loading_skeleton.js.map +0 -1
  95. package/dist/components/ui/scroll-area.d.ts +0 -12
  96. package/dist/components/ui/scroll-area.d.ts.map +0 -1
  97. package/dist/components/ui/scroll-area.js +0 -25
  98. package/dist/components/ui/scroll-area.js.map +0 -1
  99. package/dist/components/ui/separator.d.ts +0 -11
  100. package/dist/components/ui/separator.d.ts.map +0 -1
  101. package/dist/components/ui/separator.js +0 -18
  102. package/dist/components/ui/separator.js.map +0 -1
  103. package/dist/components/ui/skeleton.d.ts +0 -9
  104. package/dist/components/ui/skeleton.d.ts.map +0 -1
  105. package/dist/components/ui/skeleton.js +0 -16
  106. package/dist/components/ui/skeleton.js.map +0 -1
  107. package/dist/components/ui/textarea.d.ts +0 -11
  108. package/dist/components/ui/textarea.d.ts.map +0 -1
  109. package/dist/components/ui/textarea.js +0 -18
  110. package/dist/components/ui/textarea.js.map +0 -1
  111. package/dist/components/ui/tooltip.d.ts +0 -14
  112. package/dist/components/ui/tooltip.d.ts.map +0 -1
  113. package/dist/components/ui/tooltip.js +0 -30
  114. package/dist/components/ui/tooltip.js.map +0 -1
  115. package/dist/hooks/index.d.ts +0 -10
  116. package/dist/hooks/index.d.ts.map +0 -1
  117. package/dist/hooks/index.js +0 -10
  118. package/dist/hooks/index.js.map +0 -1
  119. package/dist/hooks/use_chat_messages.d.ts +0 -33
  120. package/dist/hooks/use_chat_messages.d.ts.map +0 -1
  121. package/dist/hooks/use_chat_messages.js +0 -466
  122. package/dist/hooks/use_chat_messages.js.map +0 -1
  123. package/dist/hooks/use_chat_references.d.ts +0 -17
  124. package/dist/hooks/use_chat_references.d.ts.map +0 -1
  125. package/dist/hooks/use_chat_references.js +0 -133
  126. package/dist/hooks/use_chat_references.js.map +0 -1
  127. package/dist/hooks/use_file_upload.d.ts +0 -23
  128. package/dist/hooks/use_file_upload.d.ts.map +0 -1
  129. package/dist/hooks/use_file_upload.js +0 -212
  130. package/dist/hooks/use_file_upload.js.map +0 -1
  131. package/dist/index.d.ts +0 -13
  132. package/dist/index.d.ts.map +0 -1
  133. package/dist/index.js +0 -17
  134. package/dist/index.js.map +0 -1
  135. package/dist/lib/config.d.ts +0 -41
  136. package/dist/lib/config.d.ts.map +0 -1
  137. package/dist/lib/config.js +0 -93
  138. package/dist/lib/config.js.map +0 -1
  139. package/dist/lib/constants.d.ts +0 -41
  140. package/dist/lib/constants.d.ts.map +0 -1
  141. package/dist/lib/constants.js +0 -72
  142. package/dist/lib/constants.js.map +0 -1
  143. package/dist/lib/index.d.ts +0 -9
  144. package/dist/lib/index.d.ts.map +0 -1
  145. package/dist/lib/index.js +0 -9
  146. package/dist/lib/index.js.map +0 -1
  147. package/dist/lib/utils.d.ts +0 -17
  148. package/dist/lib/utils.d.ts.map +0 -1
  149. package/dist/lib/utils.js +0 -20
  150. package/dist/lib/utils.js.map +0 -1
  151. package/dist/types/index.d.ts +0 -404
  152. package/dist/types/index.d.ts.map +0 -1
  153. package/dist/types/index.js +0 -11
  154. package/dist/types/index.js.map +0 -1
package/README.md CHANGED
@@ -83,19 +83,56 @@ export default function RootLayout({ children }) {
83
83
 
84
84
  ### Required Tailwind Configuration
85
85
 
86
- Your `tailwind.config.ts` must include hazo_chat package paths in content:
86
+ Your `tailwind.config.ts` must include hazo_chat package paths in the `content` array. This ensures that Tailwind CSS scans the component library files and includes all utility classes in your final CSS bundle.
87
+
88
+ **Complete Configuration Example:**
87
89
 
88
90
  ```typescript
89
- export default {
91
+ import type { Config } from 'tailwindcss';
92
+
93
+ const config: Config = {
90
94
  content: [
91
- // ... your existing paths
92
- './node_modules/hazo_chat/dist/**/*.{js,ts,jsx,tsx}',
95
+ // Your application's content paths
96
+ './src/pages/**/*.{js,ts,jsx,tsx,mdx}',
97
+ './src/components/**/*.{js,ts,jsx,tsx,mdx}',
98
+ './src/app/**/*.{js,ts,jsx,tsx,mdx}',
99
+
100
+ // Add this line to scan the hazo_chat package
101
+ './node_modules/hazo_chat/dist/**/*.js',
93
102
  ],
94
- // ... rest of config
103
+ theme: {
104
+ extend: {
105
+ // Your theme extensions
106
+ },
107
+ },
108
+ plugins: [],
95
109
  };
110
+
111
+ export default config;
96
112
  ```
97
113
 
98
- **Important:** Without this configuration, Tailwind classes used by hazo_chat components may not be compiled, causing styling issues.
114
+ **Why This Is Required:**
115
+
116
+ The `hazo_chat` component library uses Tailwind CSS utility classes (e.g., `flex`, `h-full`, `bg-background`, `p-4`) for all styling. These classes are not compiled into CSS by default. By adding the package path to your Tailwind `content` array, Tailwind will:
117
+
118
+ 1. Scan all JavaScript files in the `hazo_chat` package
119
+ 2. Extract all Tailwind utility classes used in the components
120
+ 3. Include them in your application's final CSS bundle
121
+ 4. Ensure the component styles are correctly applied at runtime
122
+
123
+ **Important:** Without this configuration, Tailwind classes used by hazo_chat components will not be compiled, causing styling issues such as:
124
+ - Missing styles (components appear unstyled)
125
+ - Broken layouts
126
+ - Incorrect spacing and colors
127
+ - Non-functional responsive breakpoints
128
+
129
+ **Troubleshooting:**
130
+
131
+ If you're experiencing styling issues after adding the configuration:
132
+ 1. Restart your development server
133
+ 2. Clear your Next.js cache: `rm -rf .next`
134
+ 3. Verify the path matches your `node_modules` location
135
+ 4. Check that `tailwindcss` is installed: `npm list tailwindcss`
99
136
 
100
137
  ### Required CSS Variables
101
138
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hazo_chat",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "description": "Chat interface for 1-1 communication with API-first architecture",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -91,7 +91,8 @@
91
91
  "hazo_connect": "^2.3.1",
92
92
  "next": ">=14.0.0",
93
93
  "react": "^18.0.0",
94
- "react-dom": "^18.0.0"
94
+ "react-dom": "^18.0.0",
95
+ "tailwindcss": ">=3.0.0"
95
96
  },
96
97
  "peerDependenciesMeta": {
97
98
  "hazo_connect": {
@@ -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
@@ -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
@@ -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"}
@@ -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"}
@@ -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
@@ -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,qBAAqB,CAAC;AAIxD,kCAAkC;AAClC,SAAS,YAAY;IACnB,OAAO,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAS,CAAC;QACvE,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACjC,MAAM,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACxB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,2BAA2B;IACxC,MAAM,WAAW,GAAG,MAAM,OAAO,EAAE,CAAC;IACpC,OAAO,WAAW,CAAC,GAAG,CAAC,mBAAmB,CAAC,E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AAE,MAAM,EAAE,GAAG,EAAE,CAChB,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AACvB,CAAC"}
@@ -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
@@ -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
@@ -1,8 +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
- export {};
8
- //# sourceMappingURL=types.js.map
@@ -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"}
@@ -1,86 +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
- import { createCrudService } from 'hazo_connect/server';
23
- /**
24
- * Creates a function to get unread message counts by reference_id
25
- *
26
- * @param options - Configuration options
27
- * @returns Function that takes receiver_user_id and returns unread counts
28
- */
29
- export function createUnreadCountFunction(options) {
30
- const { getHazoConnect } = options;
31
- /**
32
- * Get unread message counts grouped by reference_id for a receiver user
33
- *
34
- * @param receiver_user_id - The user ID to get unread counts for
35
- * @returns Array of objects with reference_id and count of unread messages
36
- */
37
- return async function hazo_chat_get_unread_count(receiver_user_id) {
38
- try {
39
- if (!receiver_user_id || receiver_user_id.trim() === '') {
40
- console.error('[hazo_chat_get_unread_count] Missing receiver_user_id');
41
- return [];
42
- }
43
- console.log('[hazo_chat_get_unread_count] Fetching unread counts for:', {
44
- receiver_user_id,
45
- });
46
- // Get hazo_connect instance and create CRUD service
47
- const hazoConnect = getHazoConnect();
48
- const chatService = createCrudService(hazoConnect, 'hazo_chat');
49
- // Fetch all unread messages for this receiver
50
- const unread_messages = await chatService.list((qb) => {
51
- return qb
52
- .select('*')
53
- .where('receiver_user_id', 'eq', receiver_user_id)
54
- .where('read_at', 'is', null)
55
- .where('deleted_at', 'is', null);
56
- });
57
- // Group by reference_id and count
58
- const count_map = new Map();
59
- for (const message of unread_messages) {
60
- const ref_id = message.reference_id || '';
61
- const current_count = count_map.get(ref_id) || 0;
62
- count_map.set(ref_id, current_count + 1);
63
- }
64
- // Convert map to array of results
65
- const results = Array.from(count_map.entries()).map(([reference_id, count]) => ({
66
- reference_id,
67
- count,
68
- }));
69
- // Sort by count descending (most unread first)
70
- results.sort((a, b) => b.count - a.count);
71
- console.log('[hazo_chat_get_unread_count] Found unread counts:', {
72
- receiver_user_id,
73
- total_references: results.length,
74
- total_unread: unread_messages.length,
75
- });
76
- return results;
77
- }
78
- catch (error) {
79
- const error_message = error instanceof Error ? error.message : 'Unknown error';
80
- console.error('[hazo_chat_get_unread_count] Error:', error_message, error);
81
- // Return empty array on error rather than throwing
82
- return [];
83
- }
84
- };
85
- }
86
- //# sourceMappingURL=unread_count.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unread_count.js","sourceRoot":"","sources":["../../src/api/unread_count.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAkCxD;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAmC;IAC3E,MAAM,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IAEnC;;;;;OAKG;IACH,OAAO,KAAK,UAAU,0BAA0B,CAC9C,gBAAwB;QAExB,IAAI,CAAC;YACH,IAAI,CAAC,gBAAgB,IAAI,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;gBACxD,OAAO,C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