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