@doist/comms-sdk 2.0.2 → 3.0.1

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 (49) hide show
  1. package/dist/esm/transport/fetch-with-retry.js +44 -2
  2. package/dist/esm/types/errors.js +2 -2
  3. package/dist/esm/utils/url-helpers.js +104 -16
  4. package/dist/types/types/errors.d.ts +1 -1
  5. package/dist/types/utils/url-helpers.d.ts +41 -0
  6. package/package.json +5 -10
  7. package/dist/cjs/authentication.js +0 -256
  8. package/dist/cjs/clients/add-comment-helper.js +0 -43
  9. package/dist/cjs/clients/attachments-client.js +0 -71
  10. package/dist/cjs/clients/base-client.js +0 -33
  11. package/dist/cjs/clients/channels-client.js +0 -211
  12. package/dist/cjs/clients/comments-client.js +0 -175
  13. package/dist/cjs/clients/conversation-messages-client.js +0 -169
  14. package/dist/cjs/clients/conversations-client.js +0 -283
  15. package/dist/cjs/clients/groups-client.js +0 -172
  16. package/dist/cjs/clients/hooks-client.js +0 -52
  17. package/dist/cjs/clients/inbox-client.js +0 -184
  18. package/dist/cjs/clients/notify-audience.js +0 -45
  19. package/dist/cjs/clients/reactions-client.js +0 -97
  20. package/dist/cjs/clients/search-client.js +0 -138
  21. package/dist/cjs/clients/threads-client.js +0 -364
  22. package/dist/cjs/clients/users-client.js +0 -326
  23. package/dist/cjs/clients/workspace-users-client.js +0 -252
  24. package/dist/cjs/clients/workspaces-client.js +0 -174
  25. package/dist/cjs/comms-api.js +0 -70
  26. package/dist/cjs/consts/endpoints.js +0 -34
  27. package/dist/cjs/index.js +0 -53
  28. package/dist/cjs/migration.js +0 -96
  29. package/dist/cjs/package.json +0 -1
  30. package/dist/cjs/testUtils/msw-handlers.js +0 -51
  31. package/dist/cjs/testUtils/msw-setup.js +0 -35
  32. package/dist/cjs/testUtils/obsidian-fetch-adapter.js +0 -53
  33. package/dist/cjs/testUtils/test-defaults.js +0 -106
  34. package/dist/cjs/transport/fetch-with-retry.js +0 -146
  35. package/dist/cjs/transport/http-client.js +0 -56
  36. package/dist/cjs/transport/http-dispatcher.js +0 -190
  37. package/dist/cjs/types/api-version.js +0 -8
  38. package/dist/cjs/types/entities.js +0 -496
  39. package/dist/cjs/types/enums.js +0 -37
  40. package/dist/cjs/types/errors.js +0 -12
  41. package/dist/cjs/types/http.js +0 -4
  42. package/dist/cjs/types/index.js +0 -22
  43. package/dist/cjs/types/requests.js +0 -183
  44. package/dist/cjs/utils/case-conversion.js +0 -54
  45. package/dist/cjs/utils/index.js +0 -19
  46. package/dist/cjs/utils/multipart-upload.js +0 -202
  47. package/dist/cjs/utils/timestamp-conversion.js +0 -58
  48. package/dist/cjs/utils/url-helpers.js +0 -133
  49. package/dist/cjs/utils/uuidv7.js +0 -182
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyNotifyAudience = applyNotifyAudience;
4
- const enums_1 = require("../types/enums");
5
- const SENTINEL_GROUP_IDS = new Set(Object.values(enums_1.NOTIFY_AUDIENCE_GROUP_IDS));
6
- function isNotifyAudience(value) {
7
- return typeof value === 'string' && enums_1.NOTIFY_AUDIENCES.includes(value);
8
- }
9
- function collectMarkerOffenses(field, values) {
10
- if (!values)
11
- return null;
12
- const offending = values.filter((id) => SENTINEL_GROUP_IDS.has(id));
13
- return offending.length > 0 ? { field, offending } : null;
14
- }
15
- /**
16
- * Normalizes a `notifyAudience` flag into a sentinel `groups` entry
17
- * (`EVERYONE` / `EVERYONE_IN_THREAD`) and rejects callers who put those
18
- * reserved markers directly into `groups` / `directGroupMentions`.
19
- *
20
- * When `notifyAudience` is set it is stripped and its sentinel is appended to
21
- * `groups`; the backend only understands the marker in `groups`. When it is
22
- * unset the params are returned unchanged, preserving any explicit
23
- * `groups` / `directGroupMentions` (including a `null`) on the wire.
24
- */
25
- function applyNotifyAudience(params) {
26
- const offenses = [
27
- collectMarkerOffenses('groups', params.groups ?? undefined),
28
- collectMarkerOffenses('directGroupMentions', params.directGroupMentions ?? undefined),
29
- ].filter((o) => o !== null);
30
- if (offenses.length > 0) {
31
- const details = offenses
32
- .map(({ field, offending }) => `\`${field}\` contains ${offending.join(', ')}`)
33
- .join('; ');
34
- throw new Error(`Reserved broadcast marker IDs found: ${details}. Pass these via \`notifyAudience\` (e.g. \`notifyAudience: 'channel'\` for EVERYONE) instead of populating \`groups\` / \`directGroupMentions\` directly.`);
35
- }
36
- if (params.notifyAudience == null) {
37
- return params;
38
- }
39
- if (!isNotifyAudience(params.notifyAudience)) {
40
- throw new Error(`Invalid \`notifyAudience\` value "${String(params.notifyAudience)}". Expected one of: ${enums_1.NOTIFY_AUDIENCES.join(', ')}.`);
41
- }
42
- const sentinel = enums_1.NOTIFY_AUDIENCE_GROUP_IDS[params.notifyAudience];
43
- const { notifyAudience: _stripped, groups, ...rest } = params;
44
- return { ...rest, groups: [...(groups ?? []), sentinel] };
45
- }
@@ -1,97 +0,0 @@
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;
@@ -1,138 +0,0 @@
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;
@@ -1,364 +0,0 @@
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
- const notify_audience_1 = require("./notify-audience");
12
- exports.ThreadListSchema = zod_1.z.array(entities_1.ThreadSchema);
13
- const GetUnreadResponseSchema = zod_1.z.object({
14
- data: zod_1.z.array(entities_1.UnreadThreadSchema),
15
- version: zod_1.z.number().int(),
16
- inboxUnread: zod_1.z.number().int().nullable().optional(),
17
- });
18
- /**
19
- * Client for `/api/v1/threads/`. The SDK auto-generates the thread `id` on
20
- * `createThread` when the caller doesn't supply one.
21
- */
22
- class ThreadsClient extends base_client_1.BaseClient {
23
- constructor() {
24
- super(...arguments);
25
- this.linkBaseUrl = this.getLinkBaseUrl();
26
- // Reuse the shared singletons when no custom base is configured.
27
- this.threadSchema = this.linkBaseUrl
28
- ? (0, entities_1.createThreadSchema)(this.linkBaseUrl)
29
- : entities_1.ThreadSchema;
30
- this.threadListSchema = this.linkBaseUrl
31
- ? zod_1.z.array(this.threadSchema)
32
- : exports.ThreadListSchema;
33
- this.commentSchema = this.linkBaseUrl
34
- ? (0, entities_1.createCommentSchema)(this.linkBaseUrl)
35
- : entities_1.CommentSchema;
36
- }
37
- /**
38
- * Gets threads. At least one of `channelId` / `workspaceId` is required.
39
- * `newerThan` / `olderThan` (`Date`) are converted to the
40
- * `newer_than_ts` / `older_than_ts` epoch-second params on the wire.
41
- *
42
- * @param args - The arguments for getting threads.
43
- * @param args.workspaceId - The workspace ID.
44
- * @param args.channelId - Optional channel ID to narrow to a single channel.
45
- * @param args.archived - Optional flag to include archived threads.
46
- * @param args.newerThan - Optional date to get threads newer than.
47
- * @param args.olderThan - Optional date to get threads older than.
48
- * @param args.limit - Optional limit on number of threads returned.
49
- * @returns An array of thread objects.
50
- *
51
- * @example
52
- * ```typescript
53
- * const threads = await api.threads.getThreads({
54
- * workspaceId: 123,
55
- * channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44',
56
- * })
57
- * threads.forEach(t => console.log(t.title))
58
- * ```
59
- */
60
- getThreads(args) {
61
- const params = { workspaceId: args.workspaceId };
62
- if (args.channelId != null)
63
- params.channelId = args.channelId;
64
- if (args.archived != null)
65
- params.archived = args.archived;
66
- if (args.limit != null)
67
- params.limit = args.limit;
68
- if (args.newerThan)
69
- params.newer_than_ts = Math.floor(args.newerThan.getTime() / 1000);
70
- if (args.olderThan)
71
- params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
72
- return (0, http_client_1.request)({
73
- httpMethod: 'GET',
74
- baseUri: this.getBaseUri(),
75
- relativePath: `${endpoints_1.ENDPOINT_THREADS}/get`,
76
- apiToken: this.apiToken,
77
- payload: params,
78
- customFetch: this.customFetch,
79
- }).then((response) => this.threadListSchema.parse(response.data));
80
- }
81
- /**
82
- * Gets a single thread object by id.
83
- *
84
- * @param id - The thread ID.
85
- * @returns The thread object.
86
- */
87
- getThread(id) {
88
- return this.simple('GET', 'getone', { id }, this.threadSchema);
89
- }
90
- /**
91
- * Creates a new thread in a channel. `id` is auto-generated if not supplied.
92
- *
93
- * @param args - The arguments for creating a thread.
94
- * @param args.channelId - The channel ID.
95
- * @param args.title - Optional thread title.
96
- * @param args.content - The thread content.
97
- * @param args.recipients - Optional array of user IDs to notify.
98
- * @param args.groups - Optional array of custom group IDs to notify.
99
- * @param args.notifyAudience - Optional broader audience to notify in addition to
100
- * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
101
- * `'thread'` notifies everyone who has interacted with the thread — but a
102
- * brand-new thread has no interactions yet, so the backend discards
103
- * `'thread'` at create time. It is only meaningful on replies (`createComment`).
104
- * @param args.attachments - Optional array of {@link Attachment}s (from `attachments.upload`).
105
- * @returns The created thread object.
106
- *
107
- * @example
108
- * ```typescript
109
- * const thread = await api.threads.createThread({
110
- * channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44',
111
- * title: 'New Feature Discussion',
112
- * content: 'Let\'s discuss the new feature...',
113
- * notifyAudience: 'channel', // tag "Everyone in channel"
114
- * })
115
- * ```
116
- */
117
- createThread(args) {
118
- const normalized = (0, notify_audience_1.applyNotifyAudience)(args);
119
- return this.simple('POST', 'add', {
120
- ...normalized,
121
- id: (0, uuidv7_1.resolveCreateId)(normalized.id),
122
- channelId: (0, uuidv7_1.resolveReferenceId)(normalized.channelId, 'channelId'),
123
- }, this.threadSchema);
124
- }
125
- /**
126
- * Partial update of an existing thread.
127
- *
128
- * @param args - The arguments for updating a thread.
129
- * @param args.id - The thread ID.
130
- * @param args.title - Optional new thread title.
131
- * @param args.content - Optional new thread content.
132
- * @returns The updated thread object.
133
- */
134
- updateThread(args) {
135
- return this.simple('POST', 'update', { ...args }, this.threadSchema);
136
- }
137
- /**
138
- * Permanently deletes a thread.
139
- *
140
- * @param id - The thread ID.
141
- */
142
- deleteThread(id) {
143
- return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
144
- }
145
- /**
146
- * Saves a thread (formerly "star").
147
- *
148
- * @param id - The thread ID.
149
- */
150
- saveThread(id) {
151
- return this.simple('GET', 'save', { id }, entities_1.StatusOkSchema);
152
- }
153
- /**
154
- * Unsaves a thread (formerly "unstar").
155
- *
156
- * @param id - The thread ID.
157
- */
158
- unsaveThread(id) {
159
- return this.simple('GET', 'unsave', { id }, entities_1.StatusOkSchema);
160
- }
161
- /**
162
- * Pins a thread.
163
- *
164
- * @param id - The thread ID.
165
- */
166
- pinThread(id) {
167
- return this.simple('GET', 'pin', { id }, entities_1.StatusOkSchema);
168
- }
169
- /**
170
- * Unpins a thread.
171
- *
172
- * @param id - The thread ID.
173
- */
174
- unpinThread(id) {
175
- return this.simple('GET', 'unpin', { id }, entities_1.StatusOkSchema);
176
- }
177
- /**
178
- * Moves a thread to another channel.
179
- *
180
- * @param args - The arguments for moving a thread.
181
- * @param args.id - The thread ID.
182
- * @param args.toChannel - The target channel ID.
183
- * @returns The updated thread object.
184
- */
185
- moveToChannel(args) {
186
- return this.simple('GET', 'move_to_channel', { ...args }, this.threadSchema);
187
- }
188
- /**
189
- * Marks a thread as read.
190
- *
191
- * @param args - The arguments for marking a thread as read.
192
- * @param args.id - The thread ID.
193
- * @param args.objIndex - The index of the last known read message.
194
- */
195
- markRead(args) {
196
- const { id, ...rest } = args;
197
- return this.simple('POST', 'mark_read', { threadId: id, ...rest }, entities_1.StatusOkSchema);
198
- }
199
- /**
200
- * Marks a thread as unread.
201
- *
202
- * @param args - The arguments for marking a thread as unread.
203
- * @param args.id - The thread ID.
204
- * @param args.objIndex - The index of the last unread message. Use -1 to mark the whole thread as unread.
205
- */
206
- markUnread(args) {
207
- const { id, ...rest } = args;
208
- return this.simple('POST', 'mark_unread', { threadId: id, ...rest }, entities_1.StatusOkSchema);
209
- }
210
- /**
211
- * Marks a thread as unread for others. Useful to notify others about thread changes.
212
- *
213
- * @param args - The arguments for marking a thread as unread for others.
214
- * @param args.id - The thread ID.
215
- * @param args.objIndex - The index of the last unread message. Use -1 to mark the whole thread as unread.
216
- */
217
- markUnreadForOthers(args) {
218
- return this.simple('POST', 'mark_unread_for_others', { ...args }, entities_1.StatusOkSchema);
219
- }
220
- /**
221
- * Marks every thread in a workspace or channel as read. Exactly one of
222
- * `workspaceId` / `channelId` should be set.
223
- *
224
- * @param args - Either workspaceId or channelId (one is required).
225
- * @param args.workspaceId - The workspace ID.
226
- * @param args.channelId - The channel ID.
227
- *
228
- * @example
229
- * ```typescript
230
- * // Mark all in workspace
231
- * await api.threads.markAllRead({ workspaceId: 123 })
232
- *
233
- * // Mark all in channel
234
- * await api.threads.markAllRead({ channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44' })
235
- * ```
236
- */
237
- markAllRead(args) {
238
- if (!args.workspaceId && !args.channelId) {
239
- throw new Error('Either workspaceId or channelId is required');
240
- }
241
- return this.simple('POST', 'mark_all_read', { ...args }, entities_1.StatusOkSchema);
242
- }
243
- /**
244
- * Clears unread threads in a workspace.
245
- *
246
- * @param workspaceId - The workspace ID.
247
- */
248
- clearUnread(workspaceId) {
249
- return this.simple('GET', 'clear_unread', { workspaceId }, entities_1.StatusOkSchema);
250
- }
251
- /**
252
- * Returns unread threads for a workspace, paired with the unread version
253
- * counter and (optionally) the inbox unread count.
254
- *
255
- * @param workspaceId - The workspace ID.
256
- * @returns Object containing the array of unread thread references, a version counter, and optionally the inbox unread count.
257
- */
258
- getUnread(workspaceId) {
259
- return this.simple('GET', 'get_unread', { workspaceId }, GetUnreadResponseSchema);
260
- }
261
- /**
262
- * Mutes a thread for a specified number of minutes.
263
- * When muted, you will not get notified in your inbox about new comments.
264
- *
265
- * @param args - The arguments for muting a thread.
266
- * @param args.id - The thread ID.
267
- * @param args.minutes - Number of minutes to mute the thread.
268
- * @returns The updated thread object.
269
- *
270
- * @example
271
- * ```typescript
272
- * const thread = await api.threads.muteThread({ id: '7YpL3oZ4kZ9vP7Q1tR2sX3z', minutes: 30 })
273
- * ```
274
- */
275
- muteThread(args) {
276
- return this.simple('GET', 'mute', { ...args }, this.threadSchema);
277
- }
278
- /**
279
- * Unmutes a thread.
280
- * You will start to see notifications in your inbox again when new comments are added.
281
- *
282
- * @param id - The thread ID.
283
- * @returns The updated thread object.
284
- */
285
- unmuteThread(id) {
286
- return this.simple('GET', 'unmute', { id }, this.threadSchema);
287
- }
288
- /**
289
- * Closes a thread by adding a comment with a close action.
290
- *
291
- * @param args - The arguments for closing a thread.
292
- * @param args.id - The thread ID.
293
- * @param args.content - The comment content.
294
- * @param args.attachments - Optional array of {@link Attachment} objects.
295
- * @param args.actions - Optional array of action objects.
296
- * @param args.recipients - Optional array of user IDs to notify directly.
297
- * @param args.groups - Optional array of custom group IDs to notify.
298
- * @param args.directMentions - Optional array of user IDs that were @-mentioned in
299
- * `content`.
300
- * @param args.notifyAudience - Optional broader audience to notify in addition to
301
- * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
302
- * `'thread'` notifies everyone who has interacted with the thread.
303
- * @returns The created comment object.
304
- *
305
- * @example
306
- * ```typescript
307
- * const comment = await api.threads.closeThread({
308
- * id: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
309
- * content: 'Closing this thread — resolved.',
310
- * })
311
- * ```
312
- */
313
- closeThread(args) {
314
- return this.addCommentWithAction(args, 'close');
315
- }
316
- /**
317
- * Reopens a thread by adding a comment with a reopen action.
318
- *
319
- * @param args - The arguments for reopening a thread.
320
- * @param args.id - The thread ID.
321
- * @param args.content - The comment content.
322
- * @param args.attachments - Optional array of {@link Attachment} objects.
323
- * @param args.actions - Optional array of action objects.
324
- * @param args.recipients - Optional array of user IDs to notify directly.
325
- * @param args.groups - Optional array of custom group IDs to notify.
326
- * @param args.directMentions - Optional array of user IDs that were @-mentioned in
327
- * `content`.
328
- * @param args.notifyAudience - Optional broader audience to notify in addition to
329
- * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
330
- * `'thread'` notifies everyone who has interacted with the thread.
331
- * @returns The created comment object.
332
- *
333
- * @example
334
- * ```typescript
335
- * const comment = await api.threads.reopenThread({
336
- * id: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
337
- * content: 'Reopening — need further discussion.',
338
- * })
339
- * ```
340
- */
341
- reopenThread(args) {
342
- return this.addCommentWithAction(args, 'reopen');
343
- }
344
- addCommentWithAction(args, threadAction) {
345
- const { id, ...rest } = args;
346
- return (0, add_comment_helper_1.addCommentRequest)({
347
- baseUri: this.getBaseUri(),
348
- apiToken: this.apiToken,
349
- customFetch: this.customFetch,
350
- schema: this.commentSchema,
351
- }, { threadId: (0, uuidv7_1.resolveReferenceId)(id, 'id'), ...rest }, { threadAction });
352
- }
353
- simple(httpMethod, suffix, params, schema) {
354
- return (0, http_client_1.request)({
355
- httpMethod,
356
- baseUri: this.getBaseUri(),
357
- relativePath: `${endpoints_1.ENDPOINT_THREADS}/${suffix}`,
358
- apiToken: this.apiToken,
359
- payload: params,
360
- customFetch: this.customFetch,
361
- }).then((response) => schema.parse(response.data));
362
- }
363
- }
364
- exports.ThreadsClient = ThreadsClient;