@doist/comms-sdk 0.0.1 → 0.2.0
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 +21 -0
- package/README.md +143 -45
- package/dist/cjs/authentication.js +211 -0
- package/dist/cjs/clients/add-comment-helper.js +70 -0
- package/dist/cjs/clients/base-client.js +25 -0
- package/dist/cjs/clients/channels-client.js +200 -0
- package/dist/cjs/clients/comments-client.js +159 -0
- package/dist/cjs/clients/conversation-messages-client.js +158 -0
- package/dist/cjs/clients/conversations-client.js +243 -0
- package/dist/cjs/clients/groups-client.js +164 -0
- package/dist/cjs/clients/inbox-client.js +171 -0
- package/dist/cjs/clients/reactions-client.js +97 -0
- package/dist/cjs/clients/search-client.js +138 -0
- package/dist/cjs/clients/threads-client.js +330 -0
- package/dist/cjs/clients/users-client.js +326 -0
- package/dist/cjs/clients/workspace-users-client.js +240 -0
- package/dist/cjs/clients/workspaces-client.js +166 -0
- package/dist/cjs/comms-api.js +66 -0
- package/dist/cjs/consts/endpoints.js +32 -0
- package/dist/cjs/index.js +48 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/testUtils/msw-handlers.js +51 -0
- package/dist/cjs/testUtils/msw-setup.js +21 -0
- package/dist/cjs/testUtils/obsidian-fetch-adapter.js +53 -0
- package/dist/cjs/testUtils/test-defaults.js +104 -0
- package/dist/cjs/transport/fetch-with-retry.js +136 -0
- package/dist/cjs/transport/http-client.js +56 -0
- package/dist/cjs/transport/http-dispatcher.js +143 -0
- package/dist/cjs/types/api-version.js +8 -0
- package/dist/cjs/types/entities.js +411 -0
- package/dist/cjs/types/enums.js +37 -0
- package/dist/cjs/types/errors.js +12 -0
- package/dist/cjs/types/http.js +4 -0
- package/dist/cjs/types/index.js +22 -0
- package/dist/cjs/types/requests.js +116 -0
- package/dist/cjs/utils/case-conversion.js +54 -0
- package/dist/cjs/utils/index.js +19 -0
- package/dist/cjs/utils/timestamp-conversion.js +49 -0
- package/dist/cjs/utils/url-helpers.js +131 -0
- package/dist/cjs/utils/uuidv7.js +174 -0
- package/dist/esm/authentication.js +203 -0
- package/dist/esm/clients/add-comment-helper.js +67 -0
- package/dist/esm/clients/base-client.js +21 -0
- package/dist/esm/clients/channels-client.js +196 -0
- package/dist/esm/clients/comments-client.js +155 -0
- package/dist/esm/clients/conversation-messages-client.js +154 -0
- package/dist/esm/clients/conversations-client.js +239 -0
- package/dist/esm/clients/groups-client.js +160 -0
- package/dist/esm/clients/inbox-client.js +167 -0
- package/dist/esm/clients/reactions-client.js +93 -0
- package/dist/esm/clients/search-client.js +134 -0
- package/dist/esm/clients/threads-client.js +326 -0
- package/dist/esm/clients/users-client.js +322 -0
- package/dist/esm/clients/workspace-users-client.js +236 -0
- package/dist/esm/clients/workspaces-client.js +162 -0
- package/dist/esm/comms-api.js +62 -0
- package/dist/esm/consts/endpoints.js +28 -0
- package/dist/esm/index.js +17 -0
- package/dist/esm/testUtils/msw-handlers.js +45 -0
- package/dist/esm/testUtils/msw-setup.js +18 -0
- package/dist/esm/testUtils/obsidian-fetch-adapter.js +50 -0
- package/dist/esm/testUtils/test-defaults.js +101 -0
- package/dist/esm/transport/fetch-with-retry.js +133 -0
- package/dist/esm/transport/http-client.js +51 -0
- package/dist/esm/transport/http-dispatcher.js +104 -0
- package/dist/esm/types/api-version.js +5 -0
- package/dist/esm/types/entities.js +408 -0
- package/dist/esm/types/enums.js +34 -0
- package/dist/esm/types/errors.js +8 -0
- package/dist/esm/types/http.js +1 -0
- package/dist/esm/types/index.js +6 -0
- package/dist/esm/types/requests.js +113 -0
- package/dist/esm/utils/case-conversion.js +47 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/timestamp-conversion.js +45 -0
- package/dist/esm/utils/url-helpers.js +112 -0
- package/dist/esm/utils/uuidv7.js +163 -0
- package/dist/types/authentication.d.ts +160 -0
- package/dist/types/clients/add-comment-helper.d.ts +29 -0
- package/dist/types/clients/base-client.d.ts +28 -0
- package/dist/types/clients/channels-client.d.ts +208 -0
- package/dist/types/clients/comments-client.d.ts +224 -0
- package/dist/types/clients/conversation-messages-client.d.ts +198 -0
- package/dist/types/clients/conversations-client.d.ts +346 -0
- package/dist/types/clients/groups-client.d.ts +148 -0
- package/dist/types/clients/inbox-client.d.ts +96 -0
- package/dist/types/clients/reactions-client.d.ts +57 -0
- package/dist/types/clients/search-client.d.ts +70 -0
- package/dist/types/clients/threads-client.d.ts +536 -0
- package/dist/types/clients/users-client.d.ts +250 -0
- package/dist/types/clients/workspace-users-client.d.ts +147 -0
- package/dist/types/clients/workspaces-client.d.ts +152 -0
- package/dist/types/comms-api.d.ts +62 -0
- package/dist/types/consts/endpoints.d.ts +24 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/testUtils/msw-handlers.d.ts +28 -0
- package/dist/types/testUtils/msw-setup.d.ts +1 -0
- package/dist/types/testUtils/obsidian-fetch-adapter.d.ts +29 -0
- package/dist/types/testUtils/test-defaults.d.ts +17 -0
- package/dist/types/transport/fetch-with-retry.d.ts +4 -0
- package/dist/types/transport/http-client.d.ts +13 -0
- package/dist/types/transport/http-dispatcher.d.ts +10 -0
- package/dist/types/types/api-version.d.ts +6 -0
- package/dist/types/types/entities.d.ts +1288 -0
- package/dist/types/types/enums.d.ts +55 -0
- package/dist/types/types/errors.d.ts +6 -0
- package/dist/types/types/http.d.ts +54 -0
- package/dist/types/types/index.d.ts +6 -0
- package/dist/types/types/requests.d.ts +366 -0
- package/dist/types/utils/case-conversion.d.ts +8 -0
- package/dist/types/utils/index.d.ts +3 -0
- package/dist/types/utils/timestamp-conversion.d.ts +13 -0
- package/dist/types/utils/url-helpers.d.ts +88 -0
- package/dist/types/utils/uuidv7.d.ts +40 -0
- package/package.json +91 -8
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConversationsClient = exports.ConversationListSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
6
|
+
const http_client_1 = require("../transport/http-client");
|
|
7
|
+
const entities_1 = require("../types/entities");
|
|
8
|
+
const uuidv7_1 = require("../utils/uuidv7");
|
|
9
|
+
const base_client_1 = require("./base-client");
|
|
10
|
+
exports.ConversationListSchema = zod_1.z.array(entities_1.ConversationSchema);
|
|
11
|
+
const GetUnreadResponseSchema = zod_1.z.object({
|
|
12
|
+
data: zod_1.z.array(entities_1.UnreadConversationSchema),
|
|
13
|
+
version: zod_1.z.number().int(),
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Client for `/api/v1/conversations/`. `getOrCreate` requires an `id` (the
|
|
17
|
+
* SDK auto-generates one for new conversations); the backend dedupes on
|
|
18
|
+
* `userIds`, so an existing conversation will be returned with its own
|
|
19
|
+
* already-assigned `id` and your generated one is silently dropped.
|
|
20
|
+
*/
|
|
21
|
+
class ConversationsClient extends base_client_1.BaseClient {
|
|
22
|
+
/**
|
|
23
|
+
* Gets all conversations for a workspace.
|
|
24
|
+
*
|
|
25
|
+
* @param args - The arguments for getting conversations.
|
|
26
|
+
* @param args.workspaceId - The workspace ID.
|
|
27
|
+
* @param args.archived - Optional flag to include archived conversations.
|
|
28
|
+
* @returns An array of conversation objects.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const conversations = await api.conversations.getConversations({ workspaceId: 123 })
|
|
33
|
+
* conversations.forEach(c => console.log(c.title))
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
getConversations(args) {
|
|
37
|
+
return (0, http_client_1.request)({
|
|
38
|
+
httpMethod: 'GET',
|
|
39
|
+
baseUri: this.getBaseUri(),
|
|
40
|
+
relativePath: `${endpoints_1.ENDPOINT_CONVERSATIONS}/get`,
|
|
41
|
+
apiToken: this.apiToken,
|
|
42
|
+
payload: args,
|
|
43
|
+
customFetch: this.customFetch,
|
|
44
|
+
}).then((response) => exports.ConversationListSchema.parse(response.data));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Gets a single conversation object by id.
|
|
48
|
+
*
|
|
49
|
+
* @param id - The conversation ID.
|
|
50
|
+
* @returns The conversation object.
|
|
51
|
+
*/
|
|
52
|
+
getConversation(id) {
|
|
53
|
+
return this.simple('GET', 'getone', { id }, entities_1.ConversationSchema);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Gets an existing 1:1 / group conversation with `userIds`, or creates a
|
|
57
|
+
* new one. `id` is auto-generated if not supplied — on dedupe, the
|
|
58
|
+
* backend returns the existing conversation's `id` instead.
|
|
59
|
+
*
|
|
60
|
+
* @param args - The arguments for getting or creating a conversation.
|
|
61
|
+
* @param args.workspaceId - The workspace ID.
|
|
62
|
+
* @param args.userIds - Array of user IDs to include in the conversation.
|
|
63
|
+
* @returns The conversation object (existing or newly created).
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const conversation = await api.conversations.getOrCreateConversation({
|
|
68
|
+
* workspaceId: 123,
|
|
69
|
+
* userIds: [101, 202, 303],
|
|
70
|
+
* })
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
getOrCreateConversation(args) {
|
|
74
|
+
return this.simple('GET', 'get_or_create', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.ConversationSchema);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Updates a conversation's title.
|
|
78
|
+
*
|
|
79
|
+
* @param args - The arguments for updating a conversation.
|
|
80
|
+
* @param args.id - The conversation ID.
|
|
81
|
+
* @param args.title - The new title for the conversation.
|
|
82
|
+
* @param args.archived - Optional flag to archive/unarchive the conversation.
|
|
83
|
+
* @returns The updated conversation object.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const conversation = await api.conversations.updateConversation({
|
|
88
|
+
* id: '7YpL3oZ4kZ9vP7Q1tR2sX42',
|
|
89
|
+
* title: 'New Title',
|
|
90
|
+
* })
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
updateConversation(args) {
|
|
94
|
+
const params = { id: args.id, title: args.title };
|
|
95
|
+
if (args.archived !== undefined)
|
|
96
|
+
params.archived = args.archived;
|
|
97
|
+
return this.simple('POST', 'update', params, entities_1.ConversationSchema);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Archives a conversation.
|
|
101
|
+
*
|
|
102
|
+
* @param id - The conversation ID.
|
|
103
|
+
* @returns The updated conversation object.
|
|
104
|
+
*/
|
|
105
|
+
archiveConversation(id) {
|
|
106
|
+
return this.simple('GET', 'archive', { id }, entities_1.ConversationSchema);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Unarchives a conversation.
|
|
110
|
+
*
|
|
111
|
+
* @param id - The conversation ID.
|
|
112
|
+
* @returns The updated conversation object.
|
|
113
|
+
*/
|
|
114
|
+
unarchiveConversation(id) {
|
|
115
|
+
return this.simple('GET', 'unarchive', { id }, entities_1.ConversationSchema);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Adds a user to a conversation.
|
|
119
|
+
*
|
|
120
|
+
* @param args - The arguments for adding a user.
|
|
121
|
+
* @param args.id - The conversation ID.
|
|
122
|
+
* @param args.userId - The user ID to add.
|
|
123
|
+
* @returns The updated conversation object.
|
|
124
|
+
*/
|
|
125
|
+
addUser(args) {
|
|
126
|
+
return this.simple('POST', 'add_user', { ...args }, entities_1.ConversationSchema);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Adds multiple users to a conversation.
|
|
130
|
+
*
|
|
131
|
+
* @param args - The arguments for adding users.
|
|
132
|
+
* @param args.id - The conversation ID.
|
|
133
|
+
* @param args.userIds - Array of user IDs to add.
|
|
134
|
+
* @returns The updated conversation object.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* await api.conversations.addUsers({ id: '7YpL3oZ4kZ9vP7Q1tR2sX42', userIds: [101, 202] })
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
addUsers(args) {
|
|
142
|
+
return this.simple('POST', 'add_users', { ...args }, entities_1.ConversationSchema);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Removes a user from a conversation.
|
|
146
|
+
*
|
|
147
|
+
* @param args - The arguments for removing a user.
|
|
148
|
+
* @param args.id - The conversation ID.
|
|
149
|
+
* @param args.userId - The user ID to remove.
|
|
150
|
+
* @returns The updated conversation object.
|
|
151
|
+
*/
|
|
152
|
+
removeUser(args) {
|
|
153
|
+
return this.simple('POST', 'remove_user', { ...args }, entities_1.ConversationSchema);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Removes multiple users from a conversation.
|
|
157
|
+
*
|
|
158
|
+
* @param args - The arguments for removing users.
|
|
159
|
+
* @param args.id - The conversation ID.
|
|
160
|
+
* @param args.userIds - Array of user IDs to remove.
|
|
161
|
+
* @returns The updated conversation object.
|
|
162
|
+
*/
|
|
163
|
+
removeUsers(args) {
|
|
164
|
+
return this.simple('POST', 'remove_users', { ...args }, entities_1.ConversationSchema);
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Marks a conversation as read.
|
|
168
|
+
*
|
|
169
|
+
* @param args - The arguments for marking as read.
|
|
170
|
+
* @param args.id - The conversation ID.
|
|
171
|
+
* @param args.objIndex - Optional index of the message to mark as last read.
|
|
172
|
+
* @param args.messageId - Optional message ID to mark as last read.
|
|
173
|
+
*/
|
|
174
|
+
markRead(args) {
|
|
175
|
+
return this.simple('POST', 'mark_read', { ...args }, entities_1.StatusOkSchema);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Marks a conversation as unread.
|
|
179
|
+
*
|
|
180
|
+
* @param args - The arguments for marking as unread.
|
|
181
|
+
* @param args.id - The conversation ID.
|
|
182
|
+
* @param args.objIndex - Optional index of the message to mark as last unread.
|
|
183
|
+
* @param args.messageId - Optional message ID to mark as last unread.
|
|
184
|
+
*/
|
|
185
|
+
markUnread(args) {
|
|
186
|
+
return this.simple('POST', 'mark_unread', { ...args }, entities_1.StatusOkSchema);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Returns unread conversations for a workspace, paired with the unread
|
|
190
|
+
* version counter.
|
|
191
|
+
*
|
|
192
|
+
* @param workspaceId - The workspace ID.
|
|
193
|
+
* @returns Object containing the array of unread conversation references and a version counter.
|
|
194
|
+
*/
|
|
195
|
+
getUnread(workspaceId) {
|
|
196
|
+
return this.simple('GET', 'get_unread', { workspaceId }, GetUnreadResponseSchema);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Clears all unread conversations for a workspace.
|
|
200
|
+
*
|
|
201
|
+
* @param workspaceId - The workspace ID.
|
|
202
|
+
*/
|
|
203
|
+
clearUnread(workspaceId) {
|
|
204
|
+
return this.simple('GET', 'clear_unread', { workspaceId }, entities_1.StatusOkSchema);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Mutes a conversation for a specified number of minutes.
|
|
208
|
+
* The user will receive no notifications from this conversation during that period.
|
|
209
|
+
*
|
|
210
|
+
* @param args - The arguments for muting a conversation.
|
|
211
|
+
* @param args.id - The conversation ID.
|
|
212
|
+
* @param args.minutes - Number of minutes to mute the conversation.
|
|
213
|
+
* @returns The updated conversation object.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* const conversation = await api.conversations.muteConversation({ id: '7YpL3oZ4kZ9vP7Q1tR2sX42', minutes: 30 })
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
muteConversation(args) {
|
|
221
|
+
return this.simple('GET', 'mute', { ...args }, entities_1.ConversationSchema);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Unmutes a conversation.
|
|
225
|
+
*
|
|
226
|
+
* @param id - The conversation ID.
|
|
227
|
+
* @returns The updated conversation object.
|
|
228
|
+
*/
|
|
229
|
+
unmuteConversation(id) {
|
|
230
|
+
return this.simple('GET', 'unmute', { id }, entities_1.ConversationSchema);
|
|
231
|
+
}
|
|
232
|
+
simple(httpMethod, suffix, params, schema) {
|
|
233
|
+
return (0, http_client_1.request)({
|
|
234
|
+
httpMethod,
|
|
235
|
+
baseUri: this.getBaseUri(),
|
|
236
|
+
relativePath: `${endpoints_1.ENDPOINT_CONVERSATIONS}/${suffix}`,
|
|
237
|
+
apiToken: this.apiToken,
|
|
238
|
+
payload: params,
|
|
239
|
+
customFetch: this.customFetch,
|
|
240
|
+
}).then((response) => schema.parse(response.data));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.ConversationsClient = ConversationsClient;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GroupsClient = exports.GroupListSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
6
|
+
const http_client_1 = require("../transport/http-client");
|
|
7
|
+
const entities_1 = require("../types/entities");
|
|
8
|
+
const uuidv7_1 = require("../utils/uuidv7");
|
|
9
|
+
const base_client_1 = require("./base-client");
|
|
10
|
+
exports.GroupListSchema = zod_1.z.array(entities_1.GroupSchema);
|
|
11
|
+
/**
|
|
12
|
+
* Client for `/api/v1/groups/`. The broadcast markers `EVERYONE` /
|
|
13
|
+
* `EVERYONE_IN_THREAD` are NOT addressable through these endpoints — they
|
|
14
|
+
* only appear as members of `direct_group_mentions` / `groups` lists on
|
|
15
|
+
* thread/comment writes.
|
|
16
|
+
*
|
|
17
|
+
* `getone` / `update` / `remove` and the member-management ops all require
|
|
18
|
+
* `workspace_id` alongside the group `id`.
|
|
19
|
+
*/
|
|
20
|
+
class GroupsClient extends base_client_1.BaseClient {
|
|
21
|
+
/**
|
|
22
|
+
* Gets all groups for a given workspace.
|
|
23
|
+
*
|
|
24
|
+
* @param workspaceId - The workspace ID.
|
|
25
|
+
* @returns An array of group objects.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const groups = await api.groups.getGroups(123)
|
|
30
|
+
* groups.forEach(g => console.log(g.name))
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
getGroups(workspaceId) {
|
|
34
|
+
return (0, http_client_1.request)({
|
|
35
|
+
httpMethod: 'GET',
|
|
36
|
+
baseUri: this.getBaseUri(),
|
|
37
|
+
relativePath: `${endpoints_1.ENDPOINT_GROUPS}/get`,
|
|
38
|
+
apiToken: this.apiToken,
|
|
39
|
+
payload: { workspaceId },
|
|
40
|
+
customFetch: this.customFetch,
|
|
41
|
+
}).then((response) => exports.GroupListSchema.parse(response.data));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets a single group object by id. Requires `workspaceId`.
|
|
45
|
+
*
|
|
46
|
+
* @param args - The arguments for getting a group.
|
|
47
|
+
* @param args.id - The group ID.
|
|
48
|
+
* @param args.workspaceId - The workspace ID.
|
|
49
|
+
* @returns The group object.
|
|
50
|
+
*/
|
|
51
|
+
getGroup(args) {
|
|
52
|
+
return this.simple('GET', 'getone', { ...args }, entities_1.GroupSchema);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a new group. `id` is auto-generated if not supplied.
|
|
56
|
+
*
|
|
57
|
+
* @param args - The arguments for creating a group.
|
|
58
|
+
* @param args.workspaceId - The workspace ID.
|
|
59
|
+
* @param args.name - The group name.
|
|
60
|
+
* @param args.id - Optional caller-supplied group ID (for optimistic-UI workflows).
|
|
61
|
+
* @param args.description - Optional group description.
|
|
62
|
+
* @param args.userIds - Optional array of user IDs to add to the group.
|
|
63
|
+
* @returns The created group object.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const group = await api.groups.createGroup({
|
|
68
|
+
* workspaceId: 123,
|
|
69
|
+
* name: 'Engineering Team',
|
|
70
|
+
* userIds: [1, 2, 3],
|
|
71
|
+
* })
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
createGroup(args) {
|
|
75
|
+
return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.GroupSchema);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Updates a group's properties. Requires `workspaceId`.
|
|
79
|
+
*
|
|
80
|
+
* @param args - The arguments for updating a group.
|
|
81
|
+
* @param args.id - The group ID.
|
|
82
|
+
* @param args.workspaceId - The workspace ID.
|
|
83
|
+
* @param args.name - Optional new group name.
|
|
84
|
+
* @param args.description - Optional new group description.
|
|
85
|
+
* @returns The updated group object.
|
|
86
|
+
*/
|
|
87
|
+
updateGroup(args) {
|
|
88
|
+
return this.simple('POST', 'update', { ...args }, entities_1.GroupSchema);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Permanently deletes a group. Requires `workspaceId`.
|
|
92
|
+
*
|
|
93
|
+
* @param args - The arguments for deleting a group.
|
|
94
|
+
* @param args.id - The group ID.
|
|
95
|
+
* @param args.workspaceId - The workspace ID.
|
|
96
|
+
*/
|
|
97
|
+
deleteGroup(args) {
|
|
98
|
+
return this.simple('POST', 'remove', { ...args }, entities_1.StatusOkSchema);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Adds a user to a group.
|
|
102
|
+
*
|
|
103
|
+
* @param args - The arguments for adding a user.
|
|
104
|
+
* @param args.id - The group ID.
|
|
105
|
+
* @param args.workspaceId - The workspace ID.
|
|
106
|
+
* @param args.userId - The user ID to add.
|
|
107
|
+
*/
|
|
108
|
+
addUser(args) {
|
|
109
|
+
return this.simple('POST', 'add_user', { ...args }, entities_1.StatusOkSchema);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Adds multiple users to a group.
|
|
113
|
+
*
|
|
114
|
+
* @param args - The arguments for adding users.
|
|
115
|
+
* @param args.id - The group ID.
|
|
116
|
+
* @param args.workspaceId - The workspace ID.
|
|
117
|
+
* @param args.userIds - Array of user IDs to add.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* await api.groups.addUsers({
|
|
122
|
+
* id: '7YpL3oZ4kZ9vP7Q1tR2sX45',
|
|
123
|
+
* workspaceId: 123,
|
|
124
|
+
* userIds: [101, 202, 303],
|
|
125
|
+
* })
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
addUsers(args) {
|
|
129
|
+
return this.simple('POST', 'add_users', { ...args }, entities_1.StatusOkSchema);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Removes a user from a group.
|
|
133
|
+
*
|
|
134
|
+
* @param args - The arguments for removing a user.
|
|
135
|
+
* @param args.id - The group ID.
|
|
136
|
+
* @param args.workspaceId - The workspace ID.
|
|
137
|
+
* @param args.userId - The user ID to remove.
|
|
138
|
+
*/
|
|
139
|
+
removeUser(args) {
|
|
140
|
+
return this.simple('POST', 'remove_user', { ...args }, entities_1.StatusOkSchema);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Removes multiple users from a group.
|
|
144
|
+
*
|
|
145
|
+
* @param args - The arguments for removing users.
|
|
146
|
+
* @param args.id - The group ID.
|
|
147
|
+
* @param args.workspaceId - The workspace ID.
|
|
148
|
+
* @param args.userIds - Array of user IDs to remove.
|
|
149
|
+
*/
|
|
150
|
+
removeUsers(args) {
|
|
151
|
+
return this.simple('POST', 'remove_users', { ...args }, entities_1.StatusOkSchema);
|
|
152
|
+
}
|
|
153
|
+
simple(httpMethod, suffix, params, schema) {
|
|
154
|
+
return (0, http_client_1.request)({
|
|
155
|
+
httpMethod,
|
|
156
|
+
baseUri: this.getBaseUri(),
|
|
157
|
+
relativePath: `${endpoints_1.ENDPOINT_GROUPS}/${suffix}`,
|
|
158
|
+
apiToken: this.apiToken,
|
|
159
|
+
payload: params,
|
|
160
|
+
customFetch: this.customFetch,
|
|
161
|
+
}).then((response) => schema.parse(response.data));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.GroupsClient = GroupsClient;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InboxClient = void 0;
|
|
4
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
5
|
+
const http_client_1 = require("../transport/http-client");
|
|
6
|
+
const entities_1 = require("../types/entities");
|
|
7
|
+
const base_client_1 = require("./base-client");
|
|
8
|
+
/** Client for `/api/v1/inbox/`. */
|
|
9
|
+
class InboxClient extends base_client_1.BaseClient {
|
|
10
|
+
/**
|
|
11
|
+
* Gets inbox items (threads).
|
|
12
|
+
*
|
|
13
|
+
* @param args - The arguments for getting inbox.
|
|
14
|
+
* @param args.workspaceId - The workspace ID.
|
|
15
|
+
* @param args.newerThan - Optional date to get items newer than.
|
|
16
|
+
* @param args.olderThan - Optional date to get items older than.
|
|
17
|
+
* @param args.limit - Optional limit on number of items returned.
|
|
18
|
+
* @param args.cursor - Optional cursor for pagination.
|
|
19
|
+
* @param args.archiveFilter - Optional filter: 'active' (default), 'archived', or 'all'.
|
|
20
|
+
* @returns Inbox threads.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const inbox = await api.inbox.getInbox({
|
|
25
|
+
* workspaceId: 123,
|
|
26
|
+
* newerThan: new Date('2024-01-01'),
|
|
27
|
+
* })
|
|
28
|
+
*
|
|
29
|
+
* // Include archived (done) items alongside active ones
|
|
30
|
+
* const allInbox = await api.inbox.getInbox({
|
|
31
|
+
* workspaceId: 123,
|
|
32
|
+
* archiveFilter: 'all',
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
getInbox(args) {
|
|
37
|
+
const params = { workspace_id: args.workspaceId };
|
|
38
|
+
if (args.newerThan)
|
|
39
|
+
params.newer_than_ts = Math.floor(args.newerThan.getTime() / 1000);
|
|
40
|
+
if (args.olderThan)
|
|
41
|
+
params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
|
|
42
|
+
if (args.limit)
|
|
43
|
+
params.limit = args.limit;
|
|
44
|
+
if (args.cursor)
|
|
45
|
+
params.cursor = args.cursor;
|
|
46
|
+
if (args.archiveFilter)
|
|
47
|
+
params.archive_filter = args.archiveFilter;
|
|
48
|
+
return (0, http_client_1.request)({
|
|
49
|
+
httpMethod: 'GET',
|
|
50
|
+
baseUri: this.getBaseUri(),
|
|
51
|
+
relativePath: `${endpoints_1.ENDPOINT_INBOX}/get`,
|
|
52
|
+
apiToken: this.apiToken,
|
|
53
|
+
payload: params,
|
|
54
|
+
customFetch: this.customFetch,
|
|
55
|
+
}).then((response) => response.data.map((thread) => entities_1.InboxThreadSchema.parse(thread)));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Gets unread count for inbox.
|
|
59
|
+
*
|
|
60
|
+
* @param workspaceId - The workspace ID.
|
|
61
|
+
* @returns The unread count.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const count = await api.inbox.getCount(123)
|
|
66
|
+
* console.log(`Unread items: ${count}`)
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
getCount(workspaceId) {
|
|
70
|
+
return (0, http_client_1.request)({
|
|
71
|
+
httpMethod: 'GET',
|
|
72
|
+
baseUri: this.getBaseUri(),
|
|
73
|
+
relativePath: `${endpoints_1.ENDPOINT_INBOX}/get_count`,
|
|
74
|
+
apiToken: this.apiToken,
|
|
75
|
+
payload: { workspace_id: workspaceId },
|
|
76
|
+
customFetch: this.customFetch,
|
|
77
|
+
}).then((response) => response.data.data);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Archives a thread in the inbox.
|
|
81
|
+
*
|
|
82
|
+
* @param id - The thread ID.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* await api.inbox.archiveThread('7YpL3oZ4kZ9vP7Q1tR2sX3z')
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
archiveThread(id) {
|
|
90
|
+
return (0, http_client_1.request)({
|
|
91
|
+
httpMethod: 'POST',
|
|
92
|
+
baseUri: this.getBaseUri(),
|
|
93
|
+
relativePath: `${endpoints_1.ENDPOINT_INBOX}/archive`,
|
|
94
|
+
apiToken: this.apiToken,
|
|
95
|
+
payload: { id },
|
|
96
|
+
customFetch: this.customFetch,
|
|
97
|
+
}).then(() => undefined);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Unarchives a thread in the inbox.
|
|
101
|
+
*
|
|
102
|
+
* @param id - The thread ID.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* await api.inbox.unarchiveThread('7YpL3oZ4kZ9vP7Q1tR2sX3z')
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
unarchiveThread(id) {
|
|
110
|
+
return (0, http_client_1.request)({
|
|
111
|
+
httpMethod: 'POST',
|
|
112
|
+
baseUri: this.getBaseUri(),
|
|
113
|
+
relativePath: `${endpoints_1.ENDPOINT_INBOX}/unarchive`,
|
|
114
|
+
apiToken: this.apiToken,
|
|
115
|
+
payload: { id },
|
|
116
|
+
customFetch: this.customFetch,
|
|
117
|
+
}).then(() => undefined);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Marks all inbox items as read in a workspace.
|
|
121
|
+
*
|
|
122
|
+
* @param workspaceId - The workspace ID.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* await api.inbox.markAllRead(123)
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
markAllRead(workspaceId) {
|
|
130
|
+
return (0, http_client_1.request)({
|
|
131
|
+
httpMethod: 'POST',
|
|
132
|
+
baseUri: this.getBaseUri(),
|
|
133
|
+
relativePath: `${endpoints_1.ENDPOINT_INBOX}/mark_all_read`,
|
|
134
|
+
apiToken: this.apiToken,
|
|
135
|
+
payload: { workspace_id: workspaceId },
|
|
136
|
+
customFetch: this.customFetch,
|
|
137
|
+
}).then(() => undefined);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Archives all inbox items in a workspace.
|
|
141
|
+
*
|
|
142
|
+
* @param args - The arguments for archiving all.
|
|
143
|
+
* @param args.workspaceId - The workspace ID.
|
|
144
|
+
* @param args.channelIds - Optional array of channel IDs to filter by.
|
|
145
|
+
* @param args.olderThan - Optional date to filter items older than.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* await api.inbox.archiveAll({
|
|
150
|
+
* workspaceId: 123,
|
|
151
|
+
* olderThan: new Date('2024-01-01'),
|
|
152
|
+
* })
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
archiveAll(args) {
|
|
156
|
+
const params = { workspace_id: args.workspaceId };
|
|
157
|
+
if (args.channelIds)
|
|
158
|
+
params.channel_ids = args.channelIds;
|
|
159
|
+
if (args.olderThan)
|
|
160
|
+
params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
|
|
161
|
+
return (0, http_client_1.request)({
|
|
162
|
+
httpMethod: 'POST',
|
|
163
|
+
baseUri: this.getBaseUri(),
|
|
164
|
+
relativePath: `${endpoints_1.ENDPOINT_INBOX}/archive_all`,
|
|
165
|
+
apiToken: this.apiToken,
|
|
166
|
+
payload: params,
|
|
167
|
+
customFetch: this.customFetch,
|
|
168
|
+
}).then(() => undefined);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
exports.InboxClient = InboxClient;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReactionsClient = void 0;
|
|
4
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
5
|
+
const http_client_1 = require("../transport/http-client");
|
|
6
|
+
const base_client_1 = require("./base-client");
|
|
7
|
+
function reactionTarget(args) {
|
|
8
|
+
if (args.threadId)
|
|
9
|
+
return { threadId: args.threadId };
|
|
10
|
+
if (args.commentId)
|
|
11
|
+
return { commentId: args.commentId };
|
|
12
|
+
if (args.messageId)
|
|
13
|
+
return { messageId: args.messageId };
|
|
14
|
+
throw new Error('Must provide one of: threadId, commentId, or messageId');
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Client for interacting with Comms reaction endpoints.
|
|
18
|
+
*/
|
|
19
|
+
class ReactionsClient extends base_client_1.BaseClient {
|
|
20
|
+
/**
|
|
21
|
+
* Adds an emoji reaction to a thread, comment, or conversation message.
|
|
22
|
+
*
|
|
23
|
+
* @param args - The arguments for adding a reaction.
|
|
24
|
+
* @param args.threadId - Optional thread ID.
|
|
25
|
+
* @param args.commentId - Optional comment ID.
|
|
26
|
+
* @param args.messageId - Optional message ID (for conversation messages).
|
|
27
|
+
* @param args.reaction - The reaction emoji to add.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* await api.reactions.add({ threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z', reaction: '👍' })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
add(args) {
|
|
35
|
+
return (0, http_client_1.request)({
|
|
36
|
+
httpMethod: 'POST',
|
|
37
|
+
baseUri: this.getBaseUri(),
|
|
38
|
+
relativePath: `${endpoints_1.ENDPOINT_REACTIONS}/add`,
|
|
39
|
+
apiToken: this.apiToken,
|
|
40
|
+
payload: { ...reactionTarget(args), reaction: args.reaction },
|
|
41
|
+
customFetch: this.customFetch,
|
|
42
|
+
}).then(() => undefined);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gets reactions for a thread, comment, or conversation message.
|
|
46
|
+
*
|
|
47
|
+
* Returns an object with emoji reactions as keys and arrays of user IDs as
|
|
48
|
+
* values, or null if no reactions.
|
|
49
|
+
*
|
|
50
|
+
* @param args - The arguments for getting reactions.
|
|
51
|
+
* @param args.threadId - Optional thread ID.
|
|
52
|
+
* @param args.commentId - Optional comment ID.
|
|
53
|
+
* @param args.messageId - Optional message ID (for conversation messages).
|
|
54
|
+
* @returns A reaction object with emoji reactions as keys and arrays of user IDs as values, or null if no reactions.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const reactions = await api.reactions.get({ threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z' })
|
|
59
|
+
* // Returns: { "👍": [101, 202, 303], "❤️": [101, 202] }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
get(args) {
|
|
63
|
+
return (0, http_client_1.request)({
|
|
64
|
+
httpMethod: 'GET',
|
|
65
|
+
baseUri: this.getBaseUri(),
|
|
66
|
+
relativePath: `${endpoints_1.ENDPOINT_REACTIONS}/get`,
|
|
67
|
+
apiToken: this.apiToken,
|
|
68
|
+
payload: reactionTarget(args),
|
|
69
|
+
customFetch: this.customFetch,
|
|
70
|
+
}).then((response) => response.data);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Removes an emoji reaction from a thread, comment, or conversation message.
|
|
74
|
+
*
|
|
75
|
+
* @param args - The arguments for removing a reaction.
|
|
76
|
+
* @param args.threadId - Optional thread ID.
|
|
77
|
+
* @param args.commentId - Optional comment ID.
|
|
78
|
+
* @param args.messageId - Optional message ID (for conversation messages).
|
|
79
|
+
* @param args.reaction - The reaction emoji to remove.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* await api.reactions.remove({ threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z', reaction: '👍' })
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
remove(args) {
|
|
87
|
+
return (0, http_client_1.request)({
|
|
88
|
+
httpMethod: 'POST',
|
|
89
|
+
baseUri: this.getBaseUri(),
|
|
90
|
+
relativePath: `${endpoints_1.ENDPOINT_REACTIONS}/remove`,
|
|
91
|
+
apiToken: this.apiToken,
|
|
92
|
+
payload: { ...reactionTarget(args), reaction: args.reaction },
|
|
93
|
+
customFetch: this.customFetch,
|
|
94
|
+
}).then(() => undefined);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.ReactionsClient = ReactionsClient;
|