@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,138 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SearchClient = 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
+ /**
9
+ * Client for interacting with Comms search endpoints.
10
+ */
11
+ class SearchClient extends base_client_1.BaseClient {
12
+ /**
13
+ * Searches across all threads and conversations in a workspace.
14
+ *
15
+ * @param args - The arguments for searching.
16
+ * @param args.query - The search query string. Optional when `mentionSelf: true` is set; required otherwise.
17
+ * @param args.workspaceId - The workspace ID to search in.
18
+ * @param args.channelIds - Optional array of channel IDs to filter by.
19
+ * @param args.authorIds - Optional array of author user IDs to filter by.
20
+ * @param args.mentionSelf - Optional flag to filter by mentions of the current user. When true, `query` may be omitted.
21
+ * @param args.dateFrom - Optional start date for filtering (YYYY-MM-DD).
22
+ * @param args.dateTo - Optional end date for filtering (YYYY-MM-DD).
23
+ * @param args.limit - Optional limit on number of results returned.
24
+ * @param args.cursor - Optional cursor for pagination.
25
+ * @returns Search results with pagination.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const results = await api.search.search({
30
+ * query: 'important meeting',
31
+ * workspaceId: 123,
32
+ * })
33
+ * ```
34
+ */
35
+ search(args) {
36
+ const params = { workspace_id: args.workspaceId };
37
+ if (args.query !== undefined)
38
+ params.query = args.query;
39
+ if (args.channelIds)
40
+ params.channel_ids = args.channelIds;
41
+ if (args.authorIds)
42
+ params.author_ids = args.authorIds;
43
+ if (args.mentionSelf !== undefined)
44
+ params.mention_self = args.mentionSelf;
45
+ if (args.dateFrom)
46
+ params.date_from = args.dateFrom;
47
+ if (args.dateTo)
48
+ params.date_to = args.dateTo;
49
+ if (args.limit)
50
+ params.limit = args.limit;
51
+ if (args.cursor)
52
+ params.cursor = args.cursor;
53
+ return (0, http_client_1.request)({
54
+ httpMethod: 'GET',
55
+ baseUri: this.getBaseUri(),
56
+ relativePath: endpoints_1.ENDPOINT_SEARCH,
57
+ apiToken: this.apiToken,
58
+ payload: params,
59
+ customFetch: this.customFetch,
60
+ }).then((response) => ({
61
+ ...response.data,
62
+ items: response.data.items.map((result) => entities_1.SearchResultSchema.parse(result)),
63
+ }));
64
+ }
65
+ /**
66
+ * Searches within comments of a specific thread.
67
+ *
68
+ * @param args - The arguments for searching within a thread.
69
+ * @param args.query - The search query string.
70
+ * @param args.threadId - The thread ID to search in.
71
+ * @param args.limit - Optional limit on number of results returned.
72
+ * @param args.cursor - Optional cursor for pagination.
73
+ * @returns Comment IDs that match the search query.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const results = await api.search.searchThread({
78
+ * query: 'deadline',
79
+ * threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
80
+ * })
81
+ * ```
82
+ */
83
+ searchThread(args) {
84
+ const params = {
85
+ query: args.query,
86
+ thread_id: args.threadId,
87
+ };
88
+ if (args.limit)
89
+ params.limit = args.limit;
90
+ if (args.cursor)
91
+ params.cursor = args.cursor;
92
+ return (0, http_client_1.request)({
93
+ httpMethod: 'GET',
94
+ baseUri: this.getBaseUri(),
95
+ relativePath: `${endpoints_1.ENDPOINT_SEARCH}/thread`,
96
+ apiToken: this.apiToken,
97
+ payload: params,
98
+ customFetch: this.customFetch,
99
+ }).then((response) => response.data);
100
+ }
101
+ /**
102
+ * Searches within messages of a specific conversation.
103
+ *
104
+ * @param args - The arguments for searching within a conversation.
105
+ * @param args.query - The search query string.
106
+ * @param args.conversationId - The conversation ID to search in.
107
+ * @param args.limit - Optional limit on number of results returned.
108
+ * @param args.cursor - Optional cursor for pagination.
109
+ * @returns Message IDs that match the search query.
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * const results = await api.search.searchConversation({
114
+ * query: 'budget',
115
+ * conversationId: '7YpL3oZ4kZ9vP7Q1tR2sX42',
116
+ * })
117
+ * ```
118
+ */
119
+ searchConversation(args) {
120
+ const params = {
121
+ query: args.query,
122
+ conversation_id: args.conversationId,
123
+ };
124
+ if (args.limit)
125
+ params.limit = args.limit;
126
+ if (args.cursor)
127
+ params.cursor = args.cursor;
128
+ return (0, http_client_1.request)({
129
+ httpMethod: 'GET',
130
+ baseUri: this.getBaseUri(),
131
+ relativePath: `${endpoints_1.ENDPOINT_SEARCH}/conversation`,
132
+ apiToken: this.apiToken,
133
+ payload: params,
134
+ customFetch: this.customFetch,
135
+ }).then((response) => response.data);
136
+ }
137
+ }
138
+ exports.SearchClient = SearchClient;
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThreadsClient = exports.ThreadListSchema = 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 add_comment_helper_1 = require("./add-comment-helper");
10
+ const base_client_1 = require("./base-client");
11
+ exports.ThreadListSchema = zod_1.z.array(entities_1.ThreadSchema);
12
+ const GetUnreadResponseSchema = zod_1.z.object({
13
+ data: zod_1.z.array(entities_1.UnreadThreadSchema),
14
+ version: zod_1.z.number().int(),
15
+ inboxUnread: zod_1.z.number().int().nullable().optional(),
16
+ });
17
+ /**
18
+ * Client for `/api/v1/threads/`. The SDK auto-generates the thread `id` on
19
+ * `createThread` when the caller doesn't supply one.
20
+ */
21
+ class ThreadsClient extends base_client_1.BaseClient {
22
+ /**
23
+ * Gets threads. At least one of `channelId` / `workspaceId` is required.
24
+ * `newerThan` / `olderThan` (`Date`) are converted to the
25
+ * `newer_than_ts` / `older_than_ts` epoch-second params on the wire.
26
+ *
27
+ * @param args - The arguments for getting threads.
28
+ * @param args.workspaceId - The workspace ID.
29
+ * @param args.channelId - Optional channel ID to narrow to a single channel.
30
+ * @param args.archived - Optional flag to include archived threads.
31
+ * @param args.newerThan - Optional date to get threads newer than.
32
+ * @param args.olderThan - Optional date to get threads older than.
33
+ * @param args.limit - Optional limit on number of threads returned.
34
+ * @returns An array of thread objects.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const threads = await api.threads.getThreads({
39
+ * workspaceId: 123,
40
+ * channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44',
41
+ * })
42
+ * threads.forEach(t => console.log(t.title))
43
+ * ```
44
+ */
45
+ getThreads(args) {
46
+ const params = { workspaceId: args.workspaceId };
47
+ if (args.channelId != null)
48
+ params.channelId = args.channelId;
49
+ if (args.archived != null)
50
+ params.archived = args.archived;
51
+ if (args.limit != null)
52
+ params.limit = args.limit;
53
+ if (args.newerThan)
54
+ params.newer_than_ts = Math.floor(args.newerThan.getTime() / 1000);
55
+ if (args.olderThan)
56
+ params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
57
+ return (0, http_client_1.request)({
58
+ httpMethod: 'GET',
59
+ baseUri: this.getBaseUri(),
60
+ relativePath: `${endpoints_1.ENDPOINT_THREADS}/get`,
61
+ apiToken: this.apiToken,
62
+ payload: params,
63
+ customFetch: this.customFetch,
64
+ }).then((response) => exports.ThreadListSchema.parse(response.data));
65
+ }
66
+ /**
67
+ * Gets a single thread object by id.
68
+ *
69
+ * @param id - The thread ID.
70
+ * @returns The thread object.
71
+ */
72
+ getThread(id) {
73
+ return this.simple('GET', 'getone', { id }, entities_1.ThreadSchema);
74
+ }
75
+ /**
76
+ * Creates a new thread in a channel. `id` is auto-generated if not supplied.
77
+ *
78
+ * @param args - The arguments for creating a thread.
79
+ * @param args.channelId - The channel ID.
80
+ * @param args.title - Optional thread title.
81
+ * @param args.content - The thread content.
82
+ * @param args.recipients - Optional array of user IDs to notify.
83
+ * @param args.groups - Optional array of custom group IDs to notify.
84
+ * @returns The created thread object.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * const thread = await api.threads.createThread({
89
+ * channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44',
90
+ * title: 'New Feature Discussion',
91
+ * content: 'Let\'s discuss the new feature...',
92
+ * })
93
+ * ```
94
+ */
95
+ createThread(args) {
96
+ return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.ThreadSchema);
97
+ }
98
+ /**
99
+ * Partial update of an existing thread.
100
+ *
101
+ * @param args - The arguments for updating a thread.
102
+ * @param args.id - The thread ID.
103
+ * @param args.title - Optional new thread title.
104
+ * @param args.content - Optional new thread content.
105
+ * @returns The updated thread object.
106
+ */
107
+ updateThread(args) {
108
+ return this.simple('POST', 'update', { ...args }, entities_1.ThreadSchema);
109
+ }
110
+ /**
111
+ * Permanently deletes a thread.
112
+ *
113
+ * @param id - The thread ID.
114
+ */
115
+ deleteThread(id) {
116
+ return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
117
+ }
118
+ /**
119
+ * Saves a thread (formerly "star").
120
+ *
121
+ * @param id - The thread ID.
122
+ */
123
+ saveThread(id) {
124
+ return this.simple('GET', 'save', { id }, entities_1.StatusOkSchema);
125
+ }
126
+ /**
127
+ * Unsaves a thread (formerly "unstar").
128
+ *
129
+ * @param id - The thread ID.
130
+ */
131
+ unsaveThread(id) {
132
+ return this.simple('GET', 'unsave', { id }, entities_1.StatusOkSchema);
133
+ }
134
+ /**
135
+ * Pins a thread.
136
+ *
137
+ * @param id - The thread ID.
138
+ */
139
+ pinThread(id) {
140
+ return this.simple('GET', 'pin', { id }, entities_1.StatusOkSchema);
141
+ }
142
+ /**
143
+ * Unpins a thread.
144
+ *
145
+ * @param id - The thread ID.
146
+ */
147
+ unpinThread(id) {
148
+ return this.simple('GET', 'unpin', { id }, entities_1.StatusOkSchema);
149
+ }
150
+ /**
151
+ * Moves a thread to another channel.
152
+ *
153
+ * @param args - The arguments for moving a thread.
154
+ * @param args.id - The thread ID.
155
+ * @param args.toChannel - The target channel ID.
156
+ * @returns The updated thread object.
157
+ */
158
+ moveToChannel(args) {
159
+ return this.simple('GET', 'move_to_channel', { ...args }, entities_1.ThreadSchema);
160
+ }
161
+ /**
162
+ * Marks a thread as read.
163
+ *
164
+ * @param args - The arguments for marking a thread as read.
165
+ * @param args.id - The thread ID.
166
+ * @param args.objIndex - The index of the last known read message.
167
+ */
168
+ markRead(args) {
169
+ return this.simple('POST', 'mark_read', { ...args }, entities_1.StatusOkSchema);
170
+ }
171
+ /**
172
+ * Marks a thread as unread.
173
+ *
174
+ * @param args - The arguments for marking a thread as unread.
175
+ * @param args.id - The thread ID.
176
+ * @param args.objIndex - The index of the last unread message. Use -1 to mark the whole thread as unread.
177
+ */
178
+ markUnread(args) {
179
+ return this.simple('POST', 'mark_unread', { ...args }, entities_1.StatusOkSchema);
180
+ }
181
+ /**
182
+ * Marks a thread as unread for others. Useful to notify others about thread changes.
183
+ *
184
+ * @param args - The arguments for marking a thread as unread for others.
185
+ * @param args.id - The thread ID.
186
+ * @param args.objIndex - The index of the last unread message. Use -1 to mark the whole thread as unread.
187
+ */
188
+ markUnreadForOthers(args) {
189
+ return this.simple('POST', 'mark_unread_for_others', { ...args }, entities_1.StatusOkSchema);
190
+ }
191
+ /**
192
+ * Marks every thread in a workspace or channel as read. Exactly one of
193
+ * `workspaceId` / `channelId` should be set.
194
+ *
195
+ * @param args - Either workspaceId or channelId (one is required).
196
+ * @param args.workspaceId - The workspace ID.
197
+ * @param args.channelId - The channel ID.
198
+ *
199
+ * @example
200
+ * ```typescript
201
+ * // Mark all in workspace
202
+ * await api.threads.markAllRead({ workspaceId: 123 })
203
+ *
204
+ * // Mark all in channel
205
+ * await api.threads.markAllRead({ channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44' })
206
+ * ```
207
+ */
208
+ markAllRead(args) {
209
+ if (!args.workspaceId && !args.channelId) {
210
+ throw new Error('Either workspaceId or channelId is required');
211
+ }
212
+ return this.simple('POST', 'mark_all_read', { ...args }, entities_1.StatusOkSchema);
213
+ }
214
+ /**
215
+ * Clears unread threads in a workspace.
216
+ *
217
+ * @param workspaceId - The workspace ID.
218
+ */
219
+ clearUnread(workspaceId) {
220
+ return this.simple('GET', 'clear_unread', { workspaceId }, entities_1.StatusOkSchema);
221
+ }
222
+ /**
223
+ * Returns unread threads for a workspace, paired with the unread version
224
+ * counter and (optionally) the inbox unread count.
225
+ *
226
+ * @param workspaceId - The workspace ID.
227
+ * @returns Object containing the array of unread thread references, a version counter, and optionally the inbox unread count.
228
+ */
229
+ getUnread(workspaceId) {
230
+ return this.simple('GET', 'get_unread', { workspaceId }, GetUnreadResponseSchema);
231
+ }
232
+ /**
233
+ * Mutes a thread for a specified number of minutes.
234
+ * When muted, you will not get notified in your inbox about new comments.
235
+ *
236
+ * @param args - The arguments for muting a thread.
237
+ * @param args.id - The thread ID.
238
+ * @param args.minutes - Number of minutes to mute the thread.
239
+ * @returns The updated thread object.
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const thread = await api.threads.muteThread({ id: '7YpL3oZ4kZ9vP7Q1tR2sX3z', minutes: 30 })
244
+ * ```
245
+ */
246
+ muteThread(args) {
247
+ return this.simple('GET', 'mute', { ...args }, entities_1.ThreadSchema);
248
+ }
249
+ /**
250
+ * Unmutes a thread.
251
+ * You will start to see notifications in your inbox again when new comments are added.
252
+ *
253
+ * @param id - The thread ID.
254
+ * @returns The updated thread object.
255
+ */
256
+ unmuteThread(id) {
257
+ return this.simple('GET', 'unmute', { id }, entities_1.ThreadSchema);
258
+ }
259
+ /**
260
+ * Closes a thread by adding a comment with a close action.
261
+ *
262
+ * @param args - The arguments for closing a thread.
263
+ * @param args.id - The thread ID.
264
+ * @param args.content - The comment content.
265
+ * @param args.attachments - Optional array of {@link Attachment} objects.
266
+ * @param args.actions - Optional array of action objects.
267
+ * @param args.recipients - Optional array of user IDs to notify directly.
268
+ * @param args.groups - Optional array of custom group IDs to notify.
269
+ * @param args.directMentions - Optional array of user IDs that were @-mentioned in
270
+ * `content`.
271
+ * @param args.notifyAudience - Optional broader audience to notify in addition to
272
+ * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
273
+ * `'thread'` notifies everyone who has interacted with the thread.
274
+ * @returns The created comment object.
275
+ *
276
+ * @example
277
+ * ```typescript
278
+ * const comment = await api.threads.closeThread({
279
+ * id: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
280
+ * content: 'Closing this thread — resolved.',
281
+ * })
282
+ * ```
283
+ */
284
+ closeThread(args) {
285
+ return this.addCommentWithAction(args, 'close');
286
+ }
287
+ /**
288
+ * Reopens a thread by adding a comment with a reopen action.
289
+ *
290
+ * @param args - The arguments for reopening a thread.
291
+ * @param args.id - The thread ID.
292
+ * @param args.content - The comment content.
293
+ * @param args.attachments - Optional array of {@link Attachment} objects.
294
+ * @param args.actions - Optional array of action objects.
295
+ * @param args.recipients - Optional array of user IDs to notify directly.
296
+ * @param args.groups - Optional array of custom group IDs to notify.
297
+ * @param args.directMentions - Optional array of user IDs that were @-mentioned in
298
+ * `content`.
299
+ * @param args.notifyAudience - Optional broader audience to notify in addition to
300
+ * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
301
+ * `'thread'` notifies everyone who has interacted with the thread.
302
+ * @returns The created comment object.
303
+ *
304
+ * @example
305
+ * ```typescript
306
+ * const comment = await api.threads.reopenThread({
307
+ * id: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
308
+ * content: 'Reopening — need further discussion.',
309
+ * })
310
+ * ```
311
+ */
312
+ reopenThread(args) {
313
+ return this.addCommentWithAction(args, 'reopen');
314
+ }
315
+ addCommentWithAction(args, threadAction) {
316
+ const { id, ...rest } = args;
317
+ return (0, add_comment_helper_1.addCommentRequest)({ baseUri: this.getBaseUri(), apiToken: this.apiToken, customFetch: this.customFetch }, { threadId: id, ...rest }, { threadAction });
318
+ }
319
+ simple(httpMethod, suffix, params, schema) {
320
+ return (0, http_client_1.request)({
321
+ httpMethod,
322
+ baseUri: this.getBaseUri(),
323
+ relativePath: `${endpoints_1.ENDPOINT_THREADS}/${suffix}`,
324
+ apiToken: this.apiToken,
325
+ payload: params,
326
+ customFetch: this.customFetch,
327
+ }).then((response) => schema.parse(response.data));
328
+ }
329
+ }
330
+ exports.ThreadsClient = ThreadsClient;