@venturekit-pro/chat 0.0.0-dev.20260507015349
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/LICENSE +191 -0
- package/README.md +73 -0
- package/dist/chat/manager.d.ts +119 -0
- package/dist/chat/manager.d.ts.map +1 -0
- package/dist/chat/manager.js +180 -0
- package/dist/chat/manager.js.map +1 -0
- package/dist/chat/types.d.ts +118 -0
- package/dist/chat/types.d.ts.map +1 -0
- package/dist/chat/types.js +7 -0
- package/dist/chat/types.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2025 VentureKit Contributors
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# @venturekit-pro/chat
|
|
2
|
+
|
|
3
|
+
Real-time chat for VentureKit — 1-1, group, and channel rooms with message history, presence, and read receipts.
|
|
4
|
+
|
|
5
|
+
> **Pre-release** — API may change before 1.0.
|
|
6
|
+
|
|
7
|
+
## Scope
|
|
8
|
+
|
|
9
|
+
This package implements **chat** only:
|
|
10
|
+
|
|
11
|
+
- 1-1, group, and channel rooms with participant roles (`owner` / `admin` / `member` / `guest`)
|
|
12
|
+
- Message types: `text`, `image`, `file`, `system`
|
|
13
|
+
- Edit / soft-delete + read receipts
|
|
14
|
+
- Typing indicators + presence (`online` / `away` / `offline`)
|
|
15
|
+
- Pluggable `ChatStore` interface — Phase 1 ships the in-memory adapter; bring your own DynamoDB / Postgres / Redis adapter for production.
|
|
16
|
+
|
|
17
|
+
Transactional notifications (email / WhatsApp / SMS / push) used to live alongside this package; they now have their own home in [`@venturekit/notify`](../../notify) on the free tier. See the migration note at the bottom for what changed.
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { createChatManager, type ChatStore } from '@venturekit-pro/chat';
|
|
23
|
+
|
|
24
|
+
const store: ChatStore = /* your storage adapter */;
|
|
25
|
+
|
|
26
|
+
const chat = createChatManager(store);
|
|
27
|
+
|
|
28
|
+
// Direct (1-1) room
|
|
29
|
+
const room = await chat.createDirectRoom('user-1', 'user-2');
|
|
30
|
+
|
|
31
|
+
// Send + read
|
|
32
|
+
await chat.sendMessage({ roomId: room.id, senderId: 'user-1', content: 'Hello!' });
|
|
33
|
+
const messages = await chat.getMessages(room.id, { limit: 50 });
|
|
34
|
+
await chat.markRead(room.id, 'user-2', messages[0].id);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## API surface
|
|
38
|
+
|
|
39
|
+
| Symbol | Role |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `createChatManager(store)` | Builds the chat manager bound to a store. |
|
|
42
|
+
| `ChatStore` | Adapter interface — implement to plug Postgres/Dynamo/etc. |
|
|
43
|
+
| `RoomType`, `ParticipantRole`, `ChatMessageType` | Discriminated unions for rooms / participants / messages. |
|
|
44
|
+
| `ChatRoom`, `Participant`, `ChatMessage`, `UnreadCount` | Public read shapes returned by the manager. |
|
|
45
|
+
| `TypingEvent`, `UserPresence`, `PresenceStatus` | Live state primitives — propagated by the consumer's transport. |
|
|
46
|
+
|
|
47
|
+
## Storage
|
|
48
|
+
|
|
49
|
+
The package is transport-agnostic. The `ChatStore` interface declares 12 methods covering rooms, messages, and read receipts. Implement it against:
|
|
50
|
+
|
|
51
|
+
- **DynamoDB** — single-table layout, recommended for serverless apps already on the Lambda + DynamoDB stack.
|
|
52
|
+
- **Postgres** — reuse the project's existing DB; pair with `pg_listen` for fan-out.
|
|
53
|
+
- **In-memory** — useful for tests + the local dev path; we may ship a built-in test adapter in a future release.
|
|
54
|
+
|
|
55
|
+
There is intentionally no real-time transport baked in — pair with WebSocket (API Gateway WS), Server-Sent Events, or any pub-sub the consumer already runs.
|
|
56
|
+
|
|
57
|
+
## Migration from `@venturekit-pro/comms` (v0.x)
|
|
58
|
+
|
|
59
|
+
The 0.1 cut of `@venturekit-pro/comms` bundled email, push, SMS, WhatsApp, broadcast, templates, preferences, **and** chat. That surface area has now split:
|
|
60
|
+
|
|
61
|
+
| Old import (`@venturekit-pro/comms`) | New home |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| `createChatManager`, `ChatStore`, `ChatRoom`, … | `@venturekit-pro/chat` (this package) |
|
|
64
|
+
| `createEmailProvider`, `createPushProvider`, `createSmsProvider` | `@venturekit/notify` |
|
|
65
|
+
| `createCommsClient`, `BroadcastRequest`, … | `@venturekit/notify` (`createNotifyClient`) |
|
|
66
|
+
| `createTemplateRegistry`, `MessageTemplate` | `@venturekit/notify` (`NotifyTemplate` + `createTemplateRegistry`) |
|
|
67
|
+
| `NotificationPreference`, `isQuietHours`, … | `@venturekit/notify` (`NotificationPreferenceRow` + admin helpers) |
|
|
68
|
+
|
|
69
|
+
Update both packages with one `pnpm add @venturekit-pro/chat @venturekit/notify` and adjust imports. The chat API is unchanged; the notify API is intent-driven (declare in `vk.config.ts`, get auto-provisioned SES + outbox + dispatcher).
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
Apache-2.0
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VentureKit Chat Room Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages chat rooms, participants, and messages.
|
|
5
|
+
* Storage backend is pluggable via the ChatStore interface.
|
|
6
|
+
*/
|
|
7
|
+
import type { ChatRoom, ChatMessage, RoomType, ParticipantRole, ChatMessageType, UnreadCount } from './types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Chat storage interface.
|
|
10
|
+
* Implement this to plug in any storage backend (Postgres, DynamoDB, etc.).
|
|
11
|
+
*/
|
|
12
|
+
export interface ChatStore {
|
|
13
|
+
createRoom(room: ChatRoom): Promise<ChatRoom>;
|
|
14
|
+
getRoom(roomId: string): Promise<ChatRoom | null>;
|
|
15
|
+
updateRoom(roomId: string, updates: Partial<ChatRoom>): Promise<void>;
|
|
16
|
+
deleteRoom(roomId: string): Promise<void>;
|
|
17
|
+
listRoomsForUser(userId: string): Promise<ChatRoom[]>;
|
|
18
|
+
sendMessage(message: ChatMessage): Promise<ChatMessage>;
|
|
19
|
+
getMessage(messageId: string): Promise<ChatMessage | null>;
|
|
20
|
+
listMessages(roomId: string, options?: {
|
|
21
|
+
limit?: number;
|
|
22
|
+
before?: string;
|
|
23
|
+
}): Promise<ChatMessage[]>;
|
|
24
|
+
updateMessage(messageId: string, updates: Partial<ChatMessage>): Promise<void>;
|
|
25
|
+
deleteMessage(messageId: string): Promise<void>;
|
|
26
|
+
markRead(roomId: string, userId: string, messageId: string): Promise<void>;
|
|
27
|
+
getUnreadCounts(userId: string): Promise<UnreadCount[]>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Create room options
|
|
31
|
+
*/
|
|
32
|
+
export interface CreateRoomOptions {
|
|
33
|
+
type: RoomType;
|
|
34
|
+
name?: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
participants: Array<{
|
|
37
|
+
userId: string;
|
|
38
|
+
role?: ParticipantRole;
|
|
39
|
+
}>;
|
|
40
|
+
metadata?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Send message options
|
|
44
|
+
*/
|
|
45
|
+
export interface SendMessageOptions {
|
|
46
|
+
roomId: string;
|
|
47
|
+
senderId: string;
|
|
48
|
+
type?: ChatMessageType;
|
|
49
|
+
content: string;
|
|
50
|
+
mediaUrl?: string;
|
|
51
|
+
fileMetadata?: {
|
|
52
|
+
filename: string;
|
|
53
|
+
contentType: string;
|
|
54
|
+
size: number;
|
|
55
|
+
};
|
|
56
|
+
replyTo?: string;
|
|
57
|
+
metadata?: Record<string, unknown>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create a chat room manager
|
|
61
|
+
*/
|
|
62
|
+
export declare function createChatManager(store: ChatStore): {
|
|
63
|
+
/**
|
|
64
|
+
* Create a new chat room
|
|
65
|
+
*/
|
|
66
|
+
createRoom(options: CreateRoomOptions): Promise<ChatRoom>;
|
|
67
|
+
/**
|
|
68
|
+
* Create a direct (1-1) room between two users
|
|
69
|
+
*/
|
|
70
|
+
createDirectRoom(userId1: string, userId2: string): Promise<ChatRoom>;
|
|
71
|
+
/**
|
|
72
|
+
* Get a room by ID
|
|
73
|
+
*/
|
|
74
|
+
getRoom(roomId: string): Promise<ChatRoom | null>;
|
|
75
|
+
/**
|
|
76
|
+
* List rooms for a user
|
|
77
|
+
*/
|
|
78
|
+
listRooms(userId: string): Promise<ChatRoom[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Add a participant to a room
|
|
81
|
+
*/
|
|
82
|
+
addParticipant(roomId: string, userId: string, role?: ParticipantRole): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Remove a participant from a room
|
|
85
|
+
*/
|
|
86
|
+
removeParticipant(roomId: string, userId: string): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Send a message to a room
|
|
89
|
+
*/
|
|
90
|
+
sendMessage(options: SendMessageOptions): Promise<ChatMessage>;
|
|
91
|
+
/**
|
|
92
|
+
* Get messages from a room (paginated)
|
|
93
|
+
*/
|
|
94
|
+
getMessages(roomId: string, options?: {
|
|
95
|
+
limit?: number;
|
|
96
|
+
before?: string;
|
|
97
|
+
}): Promise<ChatMessage[]>;
|
|
98
|
+
/**
|
|
99
|
+
* Edit a message
|
|
100
|
+
*/
|
|
101
|
+
editMessage(messageId: string, senderId: string, newContent: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Delete a message (soft delete)
|
|
104
|
+
*/
|
|
105
|
+
deleteMessage(messageId: string, userId: string): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Mark messages as read up to a specific message
|
|
108
|
+
*/
|
|
109
|
+
markRead(roomId: string, userId: string, messageId: string): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Get unread counts for a user
|
|
112
|
+
*/
|
|
113
|
+
getUnreadCounts(userId: string): Promise<UnreadCount[]>;
|
|
114
|
+
/**
|
|
115
|
+
* Delete a room
|
|
116
|
+
*/
|
|
117
|
+
deleteRoom(roomId: string): Promise<void>;
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/chat/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,WAAW,EAEX,QAAQ,EACR,eAAe,EACf,eAAe,EACf,WAAW,EACZ,MAAM,YAAY,CAAC;AAEpB;;;GAGG;AACH,MAAM,WAAW,SAAS;IAExB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC9C,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IAClD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1C,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAGtD,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACxD,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC3D,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACpG,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE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D;;OAEG;8BAC6B,MAAM,WAAW,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAU3E;;OAEG;oBACmB,MAAM,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAIvD;;OAEG;sBACqB,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIpD;;OAEG;2BAEO,MAAM,UACN,MAAM,SACR,eAAe,GACpB,OAAO,CAAC,IAAI,CAAC;IAkBhB;;OAEG;8BAC6B,MAAM,UAAU,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYtE;;OAEG;yBACwB,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC;IA6BpE;;OAEG;wBAEO,MAAM,YACJ;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAC5C,OAAO,CAAC,WAAW,EAAE,CAAC;IAIzB;;OAEG;2BAC0B,MAAM,YAAY,MAAM,cAAc,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWzF;;OAEG;6BAC4B,MAAM,UAAU,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBrE;;OAEG;qBACoB,MAAM,UAAU,MAAM,aAAa,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhF;;OAEG;4BAC2B,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAI7D;;OAEG;uBACsB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;EAIlD"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VentureKit Chat Room Manager
|
|
3
|
+
*
|
|
4
|
+
* Manages chat rooms, participants, and messages.
|
|
5
|
+
* Storage backend is pluggable via the ChatStore interface.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create a chat room manager
|
|
9
|
+
*/
|
|
10
|
+
export function createChatManager(store) {
|
|
11
|
+
return {
|
|
12
|
+
/**
|
|
13
|
+
* Create a new chat room
|
|
14
|
+
*/
|
|
15
|
+
async createRoom(options) {
|
|
16
|
+
const now = Date.now();
|
|
17
|
+
const room = {
|
|
18
|
+
id: `room-${now}-${Math.random().toString(36).slice(2, 8)}`,
|
|
19
|
+
type: options.type,
|
|
20
|
+
name: options.name,
|
|
21
|
+
description: options.description,
|
|
22
|
+
participants: options.participants.map(p => ({
|
|
23
|
+
userId: p.userId,
|
|
24
|
+
role: p.role ?? 'member',
|
|
25
|
+
joinedAt: now,
|
|
26
|
+
})),
|
|
27
|
+
createdAt: now,
|
|
28
|
+
metadata: options.metadata,
|
|
29
|
+
};
|
|
30
|
+
// Direct rooms must have exactly 2 participants
|
|
31
|
+
if (room.type === 'direct' && room.participants.length !== 2) {
|
|
32
|
+
throw new Error('Direct rooms must have exactly 2 participants');
|
|
33
|
+
}
|
|
34
|
+
return store.createRoom(room);
|
|
35
|
+
},
|
|
36
|
+
/**
|
|
37
|
+
* Create a direct (1-1) room between two users
|
|
38
|
+
*/
|
|
39
|
+
async createDirectRoom(userId1, userId2) {
|
|
40
|
+
return this.createRoom({
|
|
41
|
+
type: 'direct',
|
|
42
|
+
participants: [
|
|
43
|
+
{ userId: userId1, role: 'member' },
|
|
44
|
+
{ userId: userId2, role: 'member' },
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
/**
|
|
49
|
+
* Get a room by ID
|
|
50
|
+
*/
|
|
51
|
+
async getRoom(roomId) {
|
|
52
|
+
return store.getRoom(roomId);
|
|
53
|
+
},
|
|
54
|
+
/**
|
|
55
|
+
* List rooms for a user
|
|
56
|
+
*/
|
|
57
|
+
async listRooms(userId) {
|
|
58
|
+
return store.listRoomsForUser(userId);
|
|
59
|
+
},
|
|
60
|
+
/**
|
|
61
|
+
* Add a participant to a room
|
|
62
|
+
*/
|
|
63
|
+
async addParticipant(roomId, userId, role = 'member') {
|
|
64
|
+
const room = await store.getRoom(roomId);
|
|
65
|
+
if (!room)
|
|
66
|
+
throw new Error(`Room '${roomId}' not found`);
|
|
67
|
+
if (room.type === 'direct')
|
|
68
|
+
throw new Error('Cannot add participants to direct rooms');
|
|
69
|
+
const exists = room.participants.some(p => p.userId === userId);
|
|
70
|
+
if (exists)
|
|
71
|
+
throw new Error(`User '${userId}' is already in room '${roomId}'`);
|
|
72
|
+
const participant = {
|
|
73
|
+
userId,
|
|
74
|
+
role,
|
|
75
|
+
joinedAt: Date.now(),
|
|
76
|
+
};
|
|
77
|
+
room.participants.push(participant);
|
|
78
|
+
await store.updateRoom(roomId, { participants: room.participants });
|
|
79
|
+
},
|
|
80
|
+
/**
|
|
81
|
+
* Remove a participant from a room
|
|
82
|
+
*/
|
|
83
|
+
async removeParticipant(roomId, userId) {
|
|
84
|
+
const room = await store.getRoom(roomId);
|
|
85
|
+
if (!room)
|
|
86
|
+
throw new Error(`Room '${roomId}' not found`);
|
|
87
|
+
if (room.type === 'direct')
|
|
88
|
+
throw new Error('Cannot remove participants from direct rooms');
|
|
89
|
+
const idx = room.participants.findIndex(p => p.userId === userId);
|
|
90
|
+
if (idx === -1)
|
|
91
|
+
throw new Error(`User '${userId}' is not in room '${roomId}'`);
|
|
92
|
+
room.participants.splice(idx, 1);
|
|
93
|
+
await store.updateRoom(roomId, { participants: room.participants });
|
|
94
|
+
},
|
|
95
|
+
/**
|
|
96
|
+
* Send a message to a room
|
|
97
|
+
*/
|
|
98
|
+
async sendMessage(options) {
|
|
99
|
+
const room = await store.getRoom(options.roomId);
|
|
100
|
+
if (!room)
|
|
101
|
+
throw new Error(`Room '${options.roomId}' not found`);
|
|
102
|
+
const isMember = room.participants.some(p => p.userId === options.senderId);
|
|
103
|
+
if (!isMember)
|
|
104
|
+
throw new Error(`User '${options.senderId}' is not in room '${options.roomId}'`);
|
|
105
|
+
const now = Date.now();
|
|
106
|
+
const message = {
|
|
107
|
+
id: `msg-${now}-${Math.random().toString(36).slice(2, 8)}`,
|
|
108
|
+
roomId: options.roomId,
|
|
109
|
+
senderId: options.senderId,
|
|
110
|
+
type: options.type ?? 'text',
|
|
111
|
+
content: options.content,
|
|
112
|
+
mediaUrl: options.mediaUrl,
|
|
113
|
+
fileMetadata: options.fileMetadata,
|
|
114
|
+
replyTo: options.replyTo,
|
|
115
|
+
createdAt: now,
|
|
116
|
+
metadata: options.metadata,
|
|
117
|
+
};
|
|
118
|
+
const saved = await store.sendMessage(message);
|
|
119
|
+
// Update room's lastMessageAt
|
|
120
|
+
await store.updateRoom(options.roomId, { lastMessageAt: now });
|
|
121
|
+
return saved;
|
|
122
|
+
},
|
|
123
|
+
/**
|
|
124
|
+
* Get messages from a room (paginated)
|
|
125
|
+
*/
|
|
126
|
+
async getMessages(roomId, options) {
|
|
127
|
+
return store.listMessages(roomId, options);
|
|
128
|
+
},
|
|
129
|
+
/**
|
|
130
|
+
* Edit a message
|
|
131
|
+
*/
|
|
132
|
+
async editMessage(messageId, senderId, newContent) {
|
|
133
|
+
const message = await store.getMessage(messageId);
|
|
134
|
+
if (!message)
|
|
135
|
+
throw new Error(`Message '${messageId}' not found`);
|
|
136
|
+
if (message.senderId !== senderId)
|
|
137
|
+
throw new Error('Only the sender can edit a message');
|
|
138
|
+
await store.updateMessage(messageId, {
|
|
139
|
+
content: newContent,
|
|
140
|
+
editedAt: Date.now(),
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
/**
|
|
144
|
+
* Delete a message (soft delete)
|
|
145
|
+
*/
|
|
146
|
+
async deleteMessage(messageId, userId) {
|
|
147
|
+
const message = await store.getMessage(messageId);
|
|
148
|
+
if (!message)
|
|
149
|
+
throw new Error(`Message '${messageId}' not found`);
|
|
150
|
+
// Allow sender or room admin to delete
|
|
151
|
+
const room = await store.getRoom(message.roomId);
|
|
152
|
+
const participant = room?.participants.find(p => p.userId === userId);
|
|
153
|
+
const isAdmin = participant?.role === 'admin' || participant?.role === 'owner';
|
|
154
|
+
const isSender = message.senderId === userId;
|
|
155
|
+
if (!isSender && !isAdmin) {
|
|
156
|
+
throw new Error('Only the sender or an admin can delete a message');
|
|
157
|
+
}
|
|
158
|
+
await store.updateMessage(messageId, { deletedAt: Date.now() });
|
|
159
|
+
},
|
|
160
|
+
/**
|
|
161
|
+
* Mark messages as read up to a specific message
|
|
162
|
+
*/
|
|
163
|
+
async markRead(roomId, userId, messageId) {
|
|
164
|
+
return store.markRead(roomId, userId, messageId);
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Get unread counts for a user
|
|
168
|
+
*/
|
|
169
|
+
async getUnreadCounts(userId) {
|
|
170
|
+
return store.getUnreadCounts(userId);
|
|
171
|
+
},
|
|
172
|
+
/**
|
|
173
|
+
* Delete a room
|
|
174
|
+
*/
|
|
175
|
+
async deleteRoom(roomId) {
|
|
176
|
+
return store.deleteRoom(roomId);
|
|
177
|
+
},
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/chat/manager.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6DH;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAgB;IAChD,OAAO;QACL;;WAEG;QACH,KAAK,CAAC,UAAU,CAAC,OAA0B;YACzC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACvB,MAAM,IAAI,GAAa;gBACrB,EAAE,EAAE,QAAQ,GAAG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;gBAC3D,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,IAAI,EAAE,OAAO,CAAC,IAAI;gBAClB,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,YAAY,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;oBAC3C,MAAM,EAAE,CAAC,CAAC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,WAAW,EAAE,IAAI,KAAK,OAAO,IAAI,WAAW,EAAE,IAAI,KAAK,OAAO,CAAC;YAC/E,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,KAAK,MAAM,CAAC;YAE7C,IAAI,CAAC,QAAQ,IAAI,CAAC,OAAO,EAAE,CAAC;gBAC1B,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;YACtE,CAAC;YAED,MAAM,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAClE,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,MAAc,EAAE,SAAiB;YAC9D,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;QACnD,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,eAAe,CAAC,MAAc;YAClC,OAAO,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;QAED;;WAEG;QACH,KAAK,CAAC,UAAU,CAAC,MAAc;YAC7B,OAAO,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAClC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VentureKit Chat Types
|
|
3
|
+
*
|
|
4
|
+
* Types for real-time 1-1 and group chat.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Chat room type
|
|
8
|
+
*/
|
|
9
|
+
export type RoomType = 'direct' | 'group' | 'channel';
|
|
10
|
+
/**
|
|
11
|
+
* Participant role in a room
|
|
12
|
+
*/
|
|
13
|
+
export type ParticipantRole = 'owner' | 'admin' | 'member' | 'guest';
|
|
14
|
+
/**
|
|
15
|
+
* Chat message type
|
|
16
|
+
*/
|
|
17
|
+
export type ChatMessageType = 'text' | 'image' | 'file' | 'system';
|
|
18
|
+
/**
|
|
19
|
+
* Chat room
|
|
20
|
+
*/
|
|
21
|
+
export interface ChatRoom {
|
|
22
|
+
/** Unique room ID */
|
|
23
|
+
id: string;
|
|
24
|
+
/** Room type */
|
|
25
|
+
type: RoomType;
|
|
26
|
+
/** Room name (for group/channel) */
|
|
27
|
+
name?: string;
|
|
28
|
+
/** Room description */
|
|
29
|
+
description?: string;
|
|
30
|
+
/** Room participants */
|
|
31
|
+
participants: Participant[];
|
|
32
|
+
/** Created timestamp */
|
|
33
|
+
createdAt: number;
|
|
34
|
+
/** Last message timestamp */
|
|
35
|
+
lastMessageAt?: number;
|
|
36
|
+
/** Custom metadata */
|
|
37
|
+
metadata?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Room participant
|
|
41
|
+
*/
|
|
42
|
+
export interface Participant {
|
|
43
|
+
/** User ID */
|
|
44
|
+
userId: string;
|
|
45
|
+
/** Role in the room */
|
|
46
|
+
role: ParticipantRole;
|
|
47
|
+
/** Joined timestamp */
|
|
48
|
+
joinedAt: number;
|
|
49
|
+
/** Last read message ID */
|
|
50
|
+
lastReadMessageId?: string;
|
|
51
|
+
/** Whether user has muted this room */
|
|
52
|
+
muted?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Chat message
|
|
56
|
+
*/
|
|
57
|
+
export interface ChatMessage {
|
|
58
|
+
/** Unique message ID */
|
|
59
|
+
id: string;
|
|
60
|
+
/** Room ID */
|
|
61
|
+
roomId: string;
|
|
62
|
+
/** Sender user ID */
|
|
63
|
+
senderId: string;
|
|
64
|
+
/** Message type */
|
|
65
|
+
type: ChatMessageType;
|
|
66
|
+
/** Text content */
|
|
67
|
+
content: string;
|
|
68
|
+
/** Media URL (for image/file) */
|
|
69
|
+
mediaUrl?: string;
|
|
70
|
+
/** File metadata */
|
|
71
|
+
fileMetadata?: {
|
|
72
|
+
filename: string;
|
|
73
|
+
contentType: string;
|
|
74
|
+
size: number;
|
|
75
|
+
};
|
|
76
|
+
/** Message this is replying to */
|
|
77
|
+
replyTo?: string;
|
|
78
|
+
/** Edit history */
|
|
79
|
+
editedAt?: number;
|
|
80
|
+
/** Deleted */
|
|
81
|
+
deletedAt?: number;
|
|
82
|
+
/** Read receipts (userId → timestamp) */
|
|
83
|
+
readBy?: Record<string, number>;
|
|
84
|
+
/** Created timestamp */
|
|
85
|
+
createdAt: number;
|
|
86
|
+
/** Custom metadata */
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Typing indicator event
|
|
91
|
+
*/
|
|
92
|
+
export interface TypingEvent {
|
|
93
|
+
roomId: string;
|
|
94
|
+
userId: string;
|
|
95
|
+
isTyping: boolean;
|
|
96
|
+
timestamp: number;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Presence status
|
|
100
|
+
*/
|
|
101
|
+
export type PresenceStatus = 'online' | 'away' | 'offline';
|
|
102
|
+
/**
|
|
103
|
+
* User presence
|
|
104
|
+
*/
|
|
105
|
+
export interface UserPresence {
|
|
106
|
+
userId: string;
|
|
107
|
+
status: PresenceStatus;
|
|
108
|
+
lastSeenAt: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Unread count per room
|
|
112
|
+
*/
|
|
113
|
+
export interface UnreadCount {
|
|
114
|
+
roomId: string;
|
|
115
|
+
count: number;
|
|
116
|
+
lastMessageAt?: number;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/chat/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,SAAS,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO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AAM,CAAC;QACpB,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mBAAmB;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/chat/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit-pro/chat
|
|
3
|
+
*
|
|
4
|
+
* Real-time chat for VentureKit — 1-1, group, and channel rooms with
|
|
5
|
+
* message history, participant management, presence, and read receipts.
|
|
6
|
+
*
|
|
7
|
+
* The transactional-messaging concerns (email, WhatsApp, SMS, push) that
|
|
8
|
+
* previously lived alongside this package have moved to
|
|
9
|
+
* `@venturekit/notify` (free tier, opt-in via `NotifyIntent` in
|
|
10
|
+
* `vk.config.ts`). Chat itself stayed in `pro/` because group chat is a
|
|
11
|
+
* commercial feature that needs the chat manager + storage backend
|
|
12
|
+
* (DynamoDB single-table layout in Phase 1, planned for Postgres in
|
|
13
|
+
* Phase 2).
|
|
14
|
+
*/
|
|
15
|
+
export type { RoomType, ParticipantRole, ChatMessageType, ChatRoom, Participant, ChatMessage, TypingEvent, PresenceStatus, UserPresence, UnreadCount, } from './chat/types.js';
|
|
16
|
+
export { createChatManager } from './chat/manager.js';
|
|
17
|
+
export type { ChatStore, CreateRoomOptions, SendMessageOptions, } from './chat/manager.js';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,YAAY,EACV,QAAQ,EACR,eAAe,EACf,eAAe,EACf,QAAQ,EACR,WAAW,EACX,WAAW,EACX,WAAW,EACX,cAAc,EACd,YAAY,EACZ,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @venturekit-pro/chat
|
|
3
|
+
*
|
|
4
|
+
* Real-time chat for VentureKit — 1-1, group, and channel rooms with
|
|
5
|
+
* message history, participant management, presence, and read receipts.
|
|
6
|
+
*
|
|
7
|
+
* The transactional-messaging concerns (email, WhatsApp, SMS, push) that
|
|
8
|
+
* previously lived alongside this package have moved to
|
|
9
|
+
* `@venturekit/notify` (free tier, opt-in via `NotifyIntent` in
|
|
10
|
+
* `vk.config.ts`). Chat itself stayed in `pro/` because group chat is a
|
|
11
|
+
* commercial feature that needs the chat manager + storage backend
|
|
12
|
+
* (DynamoDB single-table layout in Phase 1, planned for Postgres in
|
|
13
|
+
* Phase 2).
|
|
14
|
+
*/
|
|
15
|
+
// Chat manager
|
|
16
|
+
export { createChatManager } from './chat/manager.js';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgBH,eAAe;AACf,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@venturekit-pro/chat",
|
|
3
|
+
"version": "0.0.0-dev.20260507015349",
|
|
4
|
+
"description": "VentureKit Pro chat — real-time 1-1 / group / channel rooms with message history. Email, WhatsApp, SMS, and push notifications now live in @venturekit/notify.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/venturekit-dev/venturekit.private.git",
|
|
14
|
+
"directory": "packages/pro/chat"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"registry": "https://registry.npmjs.org",
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"license": "SEE LICENSE IN ../LICENSE",
|
|
21
|
+
"licenseHeader": "VentureKit Pro Commercial License — production use requires a valid VentureKit Pro license key. See https://venturekit.dev/pricing.",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"venturekit",
|
|
30
|
+
"saas",
|
|
31
|
+
"chat",
|
|
32
|
+
"messaging",
|
|
33
|
+
"rooms",
|
|
34
|
+
"groups"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@venturekit/core": "0.0.0-dev.20260507015349"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^25.6.0",
|
|
41
|
+
"typescript": "^5.3.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc",
|
|
45
|
+
"dev": "tsc --watch",
|
|
46
|
+
"clean": "rm -rf dist"
|
|
47
|
+
}
|
|
48
|
+
}
|