@doist/comms-sdk 0.2.0 → 0.2.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 (33) hide show
  1. package/dist/cjs/clients/add-comment-helper.js +1 -2
  2. package/dist/cjs/clients/base-client.js +8 -0
  3. package/dist/cjs/clients/channels-client.js +19 -8
  4. package/dist/cjs/clients/comments-client.js +24 -5
  5. package/dist/cjs/clients/conversation-messages-client.js +15 -4
  6. package/dist/cjs/clients/conversations-client.js +23 -12
  7. package/dist/cjs/clients/inbox-client.js +15 -2
  8. package/dist/cjs/clients/threads-client.js +27 -8
  9. package/dist/cjs/clients/workspaces-client.js +9 -1
  10. package/dist/cjs/types/entities.js +119 -98
  11. package/dist/cjs/utils/url-helpers.js +3 -1
  12. package/dist/esm/clients/add-comment-helper.js +1 -2
  13. package/dist/esm/clients/base-client.js +8 -0
  14. package/dist/esm/clients/channels-client.js +20 -9
  15. package/dist/esm/clients/comments-client.js +25 -6
  16. package/dist/esm/clients/conversation-messages-client.js +16 -5
  17. package/dist/esm/clients/conversations-client.js +24 -13
  18. package/dist/esm/clients/inbox-client.js +15 -2
  19. package/dist/esm/clients/threads-client.js +28 -9
  20. package/dist/esm/clients/workspaces-client.js +10 -2
  21. package/dist/esm/types/entities.js +111 -97
  22. package/dist/esm/utils/url-helpers.js +3 -1
  23. package/dist/types/clients/add-comment-helper.d.ts +3 -1
  24. package/dist/types/clients/base-client.d.ts +6 -0
  25. package/dist/types/clients/channels-client.d.ts +3 -0
  26. package/dist/types/clients/comments-client.d.ts +4 -0
  27. package/dist/types/clients/conversation-messages-client.d.ts +3 -0
  28. package/dist/types/clients/conversations-client.d.ts +3 -0
  29. package/dist/types/clients/inbox-client.d.ts +382 -0
  30. package/dist/types/clients/threads-client.d.ts +4 -0
  31. package/dist/types/clients/workspaces-client.d.ts +2 -0
  32. package/dist/types/types/entities.d.ts +1654 -126
  33. package/package.json +1 -1
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addCommentRequest = addCommentRequest;
4
4
  const endpoints_1 = require("../consts/endpoints");
5
5
  const http_client_1 = require("../transport/http-client");
6
- const entities_1 = require("../types/entities");
7
6
  const enums_1 = require("../types/enums");
8
7
  const uuidv7_1 = require("../utils/uuidv7");
9
8
  const SENTINEL_GROUP_IDS = new Set(Object.values(enums_1.NOTIFY_AUDIENCE_GROUP_IDS));
@@ -66,5 +65,5 @@ function addCommentRequest(context, params, options) {
66
65
  apiToken: context.apiToken,
67
66
  payload,
68
67
  customFetch: context.customFetch,
69
- }).then((response) => entities_1.CommentSchema.parse(response.data));
68
+ }).then((response) => context.schema.parse(response.data));
70
69
  }
@@ -21,5 +21,13 @@ class BaseClient {
21
21
  getBaseUri() {
22
22
  return (0, endpoints_1.getCommsBaseUri)(this.defaultVersion, this.baseUrl);
23
23
  }
24
+ /**
25
+ * Base URL for entity web links, or `undefined` to use getFullCommsURL's
26
+ * default web app. Trailing-slash normalization happens in
27
+ * `getFullCommsURL`, so the configured value is returned verbatim.
28
+ */
29
+ getLinkBaseUrl() {
30
+ return this.baseUrl;
31
+ }
24
32
  }
25
33
  exports.BaseClient = BaseClient;
@@ -14,6 +14,17 @@ exports.ChannelListSchema = zod_1.z.array(entities_1.ChannelSchema);
14
14
  * to keep an optimistic-UI ID stable through the round-trip.
15
15
  */
16
16
  class ChannelsClient extends base_client_1.BaseClient {
17
+ constructor() {
18
+ super(...arguments);
19
+ this.linkBaseUrl = this.getLinkBaseUrl();
20
+ // Reuse the shared singletons when no custom base is configured.
21
+ this.channelSchema = this.linkBaseUrl
22
+ ? (0, entities_1.createChannelSchema)(this.linkBaseUrl)
23
+ : entities_1.ChannelSchema;
24
+ this.channelListSchema = this.linkBaseUrl
25
+ ? zod_1.z.array(this.channelSchema)
26
+ : exports.ChannelListSchema;
27
+ }
17
28
  /**
18
29
  * Gets all channels for a given workspace.
19
30
  *
@@ -36,7 +47,7 @@ class ChannelsClient extends base_client_1.BaseClient {
36
47
  apiToken: this.apiToken,
37
48
  payload: args,
38
49
  customFetch: this.customFetch,
39
- }).then((response) => exports.ChannelListSchema.parse(response.data));
50
+ }).then((response) => this.channelListSchema.parse(response.data));
40
51
  }
41
52
  /**
42
53
  * Gets a single channel object by id.
@@ -45,7 +56,7 @@ class ChannelsClient extends base_client_1.BaseClient {
45
56
  * @returns The channel object.
46
57
  */
47
58
  getChannel(id) {
48
- return this.simple('GET', 'getone', { id }, entities_1.ChannelSchema);
59
+ return this.simple('GET', 'getone', { id }, this.channelSchema);
49
60
  }
50
61
  /**
51
62
  * Creates a new channel. `id` is auto-generated if not supplied — pass your
@@ -70,7 +81,7 @@ class ChannelsClient extends base_client_1.BaseClient {
70
81
  * ```
71
82
  */
72
83
  createChannel(args) {
73
- return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.ChannelSchema);
84
+ return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, this.channelSchema);
74
85
  }
75
86
  /**
76
87
  * Partial update of an existing channel.
@@ -84,7 +95,7 @@ class ChannelsClient extends base_client_1.BaseClient {
84
95
  * @returns The updated channel object.
85
96
  */
86
97
  updateChannel(args) {
87
- return this.simple('POST', 'update', { ...args }, entities_1.ChannelSchema);
98
+ return this.simple('POST', 'update', { ...args }, this.channelSchema);
88
99
  }
89
100
  /**
90
101
  * Updates the channel's view filter (`only_open` / `all` / `only_closed`).
@@ -149,7 +160,7 @@ class ChannelsClient extends base_client_1.BaseClient {
149
160
  * ```
150
161
  */
151
162
  addUser(args) {
152
- return this.simple('POST', 'add_user', { ...args }, entities_1.ChannelSchema);
163
+ return this.simple('POST', 'add_user', { ...args }, this.channelSchema);
153
164
  }
154
165
  /**
155
166
  * Adds multiple users to a channel.
@@ -164,7 +175,7 @@ class ChannelsClient extends base_client_1.BaseClient {
164
175
  * ```
165
176
  */
166
177
  addUsers(args) {
167
- return this.simple('POST', 'add_users', { ...args }, entities_1.ChannelSchema);
178
+ return this.simple('POST', 'add_users', { ...args }, this.channelSchema);
168
179
  }
169
180
  /**
170
181
  * Removes a user from a channel.
@@ -174,7 +185,7 @@ class ChannelsClient extends base_client_1.BaseClient {
174
185
  * @param args.userId - The user ID to remove.
175
186
  */
176
187
  removeUser(args) {
177
- return this.simple('POST', 'remove_user', { ...args }, entities_1.ChannelSchema);
188
+ return this.simple('POST', 'remove_user', { ...args }, this.channelSchema);
178
189
  }
179
190
  /**
180
191
  * Removes multiple users from a channel.
@@ -184,7 +195,7 @@ class ChannelsClient extends base_client_1.BaseClient {
184
195
  * @param args.userIds - Array of user IDs to remove.
185
196
  */
186
197
  removeUsers(args) {
187
- return this.simple('POST', 'remove_users', { ...args }, entities_1.ChannelSchema);
198
+ return this.simple('POST', 'remove_users', { ...args }, this.channelSchema);
188
199
  }
189
200
  simple(httpMethod, suffix, params, schema) {
190
201
  return (0, http_client_1.request)({
@@ -13,6 +13,21 @@ exports.CommentListSchema = zod_1.z.array(entities_1.CommentSchema);
13
13
  * on `createComment` when the caller doesn't supply one.
14
14
  */
15
15
  class CommentsClient extends base_client_1.BaseClient {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.linkBaseUrl = this.getLinkBaseUrl();
19
+ // Reuse the shared singletons when no custom base is configured.
20
+ this.commentSchema = this.linkBaseUrl
21
+ ? (0, entities_1.createCommentSchema)(this.linkBaseUrl)
22
+ : entities_1.CommentSchema;
23
+ this.commentListSchema = this.linkBaseUrl
24
+ ? zod_1.z.array(this.commentSchema)
25
+ : exports.CommentListSchema;
26
+ // `getone` wraps the comment in `{ comment: ... }`; built once per client.
27
+ this.wrappedCommentSchema = zod_1.z
28
+ .object({ comment: this.commentSchema })
29
+ .transform((data) => data.comment);
30
+ }
16
31
  /**
17
32
  * Gets all comments for a thread. `newerThan` / `olderThan` (`Date`) are
18
33
  * converted to `newer_than_ts` / `older_than_ts` epoch seconds on the
@@ -49,7 +64,7 @@ class CommentsClient extends base_client_1.BaseClient {
49
64
  apiToken: this.apiToken,
50
65
  payload: params,
51
66
  customFetch: this.customFetch,
52
- }).then((response) => exports.CommentListSchema.parse(response.data));
67
+ }).then((response) => this.commentListSchema.parse(response.data));
53
68
  }
54
69
  /**
55
70
  * Gets a single comment object by id. The API wraps it in `{comment: ...}`.
@@ -58,7 +73,6 @@ class CommentsClient extends base_client_1.BaseClient {
58
73
  * @returns The comment object.
59
74
  */
60
75
  getComment(id) {
61
- const wrappedSchema = zod_1.z.object({ comment: entities_1.CommentSchema }).transform((data) => data.comment);
62
76
  return (0, http_client_1.request)({
63
77
  httpMethod: 'GET',
64
78
  baseUri: this.getBaseUri(),
@@ -66,7 +80,7 @@ class CommentsClient extends base_client_1.BaseClient {
66
80
  apiToken: this.apiToken,
67
81
  payload: { id },
68
82
  customFetch: this.customFetch,
69
- }).then((response) => wrappedSchema.parse(response.data));
83
+ }).then((response) => this.wrappedCommentSchema.parse(response.data));
70
84
  }
71
85
  /**
72
86
  * Creates a new comment on a thread. `id` is auto-generated if not supplied.
@@ -96,7 +110,12 @@ class CommentsClient extends base_client_1.BaseClient {
96
110
  * ```
97
111
  */
98
112
  createComment(args) {
99
- return (0, add_comment_helper_1.addCommentRequest)({ baseUri: this.getBaseUri(), apiToken: this.apiToken, customFetch: this.customFetch }, args);
113
+ return (0, add_comment_helper_1.addCommentRequest)({
114
+ baseUri: this.getBaseUri(),
115
+ apiToken: this.apiToken,
116
+ customFetch: this.customFetch,
117
+ schema: this.commentSchema,
118
+ }, args);
100
119
  }
101
120
  /**
102
121
  * Updates a comment's properties.
@@ -114,7 +133,7 @@ class CommentsClient extends base_client_1.BaseClient {
114
133
  apiToken: this.apiToken,
115
134
  payload: { ...args },
116
135
  customFetch: this.customFetch,
117
- }).then((response) => entities_1.CommentSchema.parse(response.data));
136
+ }).then((response) => this.commentSchema.parse(response.data));
118
137
  }
119
138
  /**
120
139
  * Permanently deletes a comment.
@@ -13,6 +13,17 @@ exports.ConversationMessageListSchema = zod_1.z.array(entities_1.ConversationMes
13
13
  * message `id` on `createMessage` when the caller doesn't supply one.
14
14
  */
15
15
  class ConversationMessagesClient extends base_client_1.BaseClient {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.linkBaseUrl = this.getLinkBaseUrl();
19
+ // Reuse the shared singletons when no custom base is configured.
20
+ this.messageSchema = this.linkBaseUrl
21
+ ? (0, entities_1.createConversationMessageSchema)(this.linkBaseUrl)
22
+ : entities_1.ConversationMessageSchema;
23
+ this.messageListSchema = this.linkBaseUrl
24
+ ? zod_1.z.array(this.messageSchema)
25
+ : exports.ConversationMessageListSchema;
26
+ }
16
27
  /**
17
28
  * Gets all messages in a conversation.
18
29
  *
@@ -49,7 +60,7 @@ class ConversationMessagesClient extends base_client_1.BaseClient {
49
60
  apiToken: this.apiToken,
50
61
  payload: params,
51
62
  customFetch: this.customFetch,
52
- }).then((response) => exports.ConversationMessageListSchema.parse(response.data));
63
+ }).then((response) => this.messageListSchema.parse(response.data));
53
64
  }
54
65
  /**
55
66
  * Gets a single conversation message by id.
@@ -63,7 +74,7 @@ class ConversationMessagesClient extends base_client_1.BaseClient {
63
74
  * ```
64
75
  */
65
76
  getMessage(id) {
66
- return this.simple('GET', 'getone', { id }, entities_1.ConversationMessageSchema);
77
+ return this.simple('GET', 'getone', { id }, this.messageSchema);
67
78
  }
68
79
  /**
69
80
  * Creates a new message in a conversation. `id` is auto-generated if not
@@ -100,7 +111,7 @@ class ConversationMessagesClient extends base_client_1.BaseClient {
100
111
  params.directGroupMentions = args.directGroupMentions;
101
112
  if (args.notify !== undefined)
102
113
  params.notify = args.notify;
103
- return this.simple('POST', 'add', params, entities_1.ConversationMessageSchema);
114
+ return this.simple('POST', 'add', params, this.messageSchema);
104
115
  }
105
116
  /**
106
117
  * Updates a conversation message.
@@ -129,7 +140,7 @@ class ConversationMessagesClient extends base_client_1.BaseClient {
129
140
  params.directMentions = args.directMentions;
130
141
  if (args.directGroupMentions)
131
142
  params.directGroupMentions = args.directGroupMentions;
132
- return this.simple('POST', 'update', params, entities_1.ConversationMessageSchema);
143
+ return this.simple('POST', 'update', params, this.messageSchema);
133
144
  }
134
145
  /**
135
146
  * Permanently deletes a conversation message.
@@ -19,6 +19,17 @@ const GetUnreadResponseSchema = zod_1.z.object({
19
19
  * already-assigned `id` and your generated one is silently dropped.
20
20
  */
21
21
  class ConversationsClient extends base_client_1.BaseClient {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.linkBaseUrl = this.getLinkBaseUrl();
25
+ // Reuse the shared singletons when no custom base is configured.
26
+ this.conversationSchema = this.linkBaseUrl
27
+ ? (0, entities_1.createConversationSchema)(this.linkBaseUrl)
28
+ : entities_1.ConversationSchema;
29
+ this.conversationListSchema = this.linkBaseUrl
30
+ ? zod_1.z.array(this.conversationSchema)
31
+ : exports.ConversationListSchema;
32
+ }
22
33
  /**
23
34
  * Gets all conversations for a workspace.
24
35
  *
@@ -41,7 +52,7 @@ class ConversationsClient extends base_client_1.BaseClient {
41
52
  apiToken: this.apiToken,
42
53
  payload: args,
43
54
  customFetch: this.customFetch,
44
- }).then((response) => exports.ConversationListSchema.parse(response.data));
55
+ }).then((response) => this.conversationListSchema.parse(response.data));
45
56
  }
46
57
  /**
47
58
  * Gets a single conversation object by id.
@@ -50,7 +61,7 @@ class ConversationsClient extends base_client_1.BaseClient {
50
61
  * @returns The conversation object.
51
62
  */
52
63
  getConversation(id) {
53
- return this.simple('GET', 'getone', { id }, entities_1.ConversationSchema);
64
+ return this.simple('GET', 'getone', { id }, this.conversationSchema);
54
65
  }
55
66
  /**
56
67
  * Gets an existing 1:1 / group conversation with `userIds`, or creates a
@@ -71,7 +82,7 @@ class ConversationsClient extends base_client_1.BaseClient {
71
82
  * ```
72
83
  */
73
84
  getOrCreateConversation(args) {
74
- return this.simple('GET', 'get_or_create', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.ConversationSchema);
85
+ return this.simple('GET', 'get_or_create', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, this.conversationSchema);
75
86
  }
76
87
  /**
77
88
  * Updates a conversation's title.
@@ -94,7 +105,7 @@ class ConversationsClient extends base_client_1.BaseClient {
94
105
  const params = { id: args.id, title: args.title };
95
106
  if (args.archived !== undefined)
96
107
  params.archived = args.archived;
97
- return this.simple('POST', 'update', params, entities_1.ConversationSchema);
108
+ return this.simple('POST', 'update', params, this.conversationSchema);
98
109
  }
99
110
  /**
100
111
  * Archives a conversation.
@@ -103,7 +114,7 @@ class ConversationsClient extends base_client_1.BaseClient {
103
114
  * @returns The updated conversation object.
104
115
  */
105
116
  archiveConversation(id) {
106
- return this.simple('GET', 'archive', { id }, entities_1.ConversationSchema);
117
+ return this.simple('GET', 'archive', { id }, this.conversationSchema);
107
118
  }
108
119
  /**
109
120
  * Unarchives a conversation.
@@ -112,7 +123,7 @@ class ConversationsClient extends base_client_1.BaseClient {
112
123
  * @returns The updated conversation object.
113
124
  */
114
125
  unarchiveConversation(id) {
115
- return this.simple('GET', 'unarchive', { id }, entities_1.ConversationSchema);
126
+ return this.simple('GET', 'unarchive', { id }, this.conversationSchema);
116
127
  }
117
128
  /**
118
129
  * Adds a user to a conversation.
@@ -123,7 +134,7 @@ class ConversationsClient extends base_client_1.BaseClient {
123
134
  * @returns The updated conversation object.
124
135
  */
125
136
  addUser(args) {
126
- return this.simple('POST', 'add_user', { ...args }, entities_1.ConversationSchema);
137
+ return this.simple('POST', 'add_user', { ...args }, this.conversationSchema);
127
138
  }
128
139
  /**
129
140
  * Adds multiple users to a conversation.
@@ -139,7 +150,7 @@ class ConversationsClient extends base_client_1.BaseClient {
139
150
  * ```
140
151
  */
141
152
  addUsers(args) {
142
- return this.simple('POST', 'add_users', { ...args }, entities_1.ConversationSchema);
153
+ return this.simple('POST', 'add_users', { ...args }, this.conversationSchema);
143
154
  }
144
155
  /**
145
156
  * Removes a user from a conversation.
@@ -150,7 +161,7 @@ class ConversationsClient extends base_client_1.BaseClient {
150
161
  * @returns The updated conversation object.
151
162
  */
152
163
  removeUser(args) {
153
- return this.simple('POST', 'remove_user', { ...args }, entities_1.ConversationSchema);
164
+ return this.simple('POST', 'remove_user', { ...args }, this.conversationSchema);
154
165
  }
155
166
  /**
156
167
  * Removes multiple users from a conversation.
@@ -161,7 +172,7 @@ class ConversationsClient extends base_client_1.BaseClient {
161
172
  * @returns The updated conversation object.
162
173
  */
163
174
  removeUsers(args) {
164
- return this.simple('POST', 'remove_users', { ...args }, entities_1.ConversationSchema);
175
+ return this.simple('POST', 'remove_users', { ...args }, this.conversationSchema);
165
176
  }
166
177
  /**
167
178
  * Marks a conversation as read.
@@ -218,7 +229,7 @@ class ConversationsClient extends base_client_1.BaseClient {
218
229
  * ```
219
230
  */
220
231
  muteConversation(args) {
221
- return this.simple('GET', 'mute', { ...args }, entities_1.ConversationSchema);
232
+ return this.simple('GET', 'mute', { ...args }, this.conversationSchema);
222
233
  }
223
234
  /**
224
235
  * Unmutes a conversation.
@@ -227,7 +238,7 @@ class ConversationsClient extends base_client_1.BaseClient {
227
238
  * @returns The updated conversation object.
228
239
  */
229
240
  unmuteConversation(id) {
230
- return this.simple('GET', 'unmute', { id }, entities_1.ConversationSchema);
241
+ return this.simple('GET', 'unmute', { id }, this.conversationSchema);
231
242
  }
232
243
  simple(httpMethod, suffix, params, schema) {
233
244
  return (0, http_client_1.request)({
@@ -1,12 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InboxClient = void 0;
3
+ exports.InboxClient = exports.InboxThreadListSchema = void 0;
4
+ const zod_1 = require("zod");
4
5
  const endpoints_1 = require("../consts/endpoints");
5
6
  const http_client_1 = require("../transport/http-client");
6
7
  const entities_1 = require("../types/entities");
7
8
  const base_client_1 = require("./base-client");
9
+ exports.InboxThreadListSchema = zod_1.z.array(entities_1.InboxThreadSchema);
8
10
  /** Client for `/api/v1/inbox/`. */
9
11
  class InboxClient extends base_client_1.BaseClient {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.linkBaseUrl = this.getLinkBaseUrl();
15
+ // Reuse the shared singletons when no custom base is configured.
16
+ this.inboxThreadSchema = this.linkBaseUrl
17
+ ? (0, entities_1.createInboxThreadSchema)(this.linkBaseUrl)
18
+ : entities_1.InboxThreadSchema;
19
+ this.inboxThreadListSchema = this.linkBaseUrl
20
+ ? zod_1.z.array(this.inboxThreadSchema)
21
+ : exports.InboxThreadListSchema;
22
+ }
10
23
  /**
11
24
  * Gets inbox items (threads).
12
25
  *
@@ -52,7 +65,7 @@ class InboxClient extends base_client_1.BaseClient {
52
65
  apiToken: this.apiToken,
53
66
  payload: params,
54
67
  customFetch: this.customFetch,
55
- }).then((response) => response.data.map((thread) => entities_1.InboxThreadSchema.parse(thread)));
68
+ }).then((response) => this.inboxThreadListSchema.parse(response.data));
56
69
  }
57
70
  /**
58
71
  * Gets unread count for inbox.
@@ -19,6 +19,20 @@ const GetUnreadResponseSchema = zod_1.z.object({
19
19
  * `createThread` when the caller doesn't supply one.
20
20
  */
21
21
  class ThreadsClient extends base_client_1.BaseClient {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.linkBaseUrl = this.getLinkBaseUrl();
25
+ // Reuse the shared singletons when no custom base is configured.
26
+ this.threadSchema = this.linkBaseUrl
27
+ ? (0, entities_1.createThreadSchema)(this.linkBaseUrl)
28
+ : entities_1.ThreadSchema;
29
+ this.threadListSchema = this.linkBaseUrl
30
+ ? zod_1.z.array(this.threadSchema)
31
+ : exports.ThreadListSchema;
32
+ this.commentSchema = this.linkBaseUrl
33
+ ? (0, entities_1.createCommentSchema)(this.linkBaseUrl)
34
+ : entities_1.CommentSchema;
35
+ }
22
36
  /**
23
37
  * Gets threads. At least one of `channelId` / `workspaceId` is required.
24
38
  * `newerThan` / `olderThan` (`Date`) are converted to the
@@ -61,7 +75,7 @@ class ThreadsClient extends base_client_1.BaseClient {
61
75
  apiToken: this.apiToken,
62
76
  payload: params,
63
77
  customFetch: this.customFetch,
64
- }).then((response) => exports.ThreadListSchema.parse(response.data));
78
+ }).then((response) => this.threadListSchema.parse(response.data));
65
79
  }
66
80
  /**
67
81
  * Gets a single thread object by id.
@@ -70,7 +84,7 @@ class ThreadsClient extends base_client_1.BaseClient {
70
84
  * @returns The thread object.
71
85
  */
72
86
  getThread(id) {
73
- return this.simple('GET', 'getone', { id }, entities_1.ThreadSchema);
87
+ return this.simple('GET', 'getone', { id }, this.threadSchema);
74
88
  }
75
89
  /**
76
90
  * Creates a new thread in a channel. `id` is auto-generated if not supplied.
@@ -93,7 +107,7 @@ class ThreadsClient extends base_client_1.BaseClient {
93
107
  * ```
94
108
  */
95
109
  createThread(args) {
96
- return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.ThreadSchema);
110
+ return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, this.threadSchema);
97
111
  }
98
112
  /**
99
113
  * Partial update of an existing thread.
@@ -105,7 +119,7 @@ class ThreadsClient extends base_client_1.BaseClient {
105
119
  * @returns The updated thread object.
106
120
  */
107
121
  updateThread(args) {
108
- return this.simple('POST', 'update', { ...args }, entities_1.ThreadSchema);
122
+ return this.simple('POST', 'update', { ...args }, this.threadSchema);
109
123
  }
110
124
  /**
111
125
  * Permanently deletes a thread.
@@ -156,7 +170,7 @@ class ThreadsClient extends base_client_1.BaseClient {
156
170
  * @returns The updated thread object.
157
171
  */
158
172
  moveToChannel(args) {
159
- return this.simple('GET', 'move_to_channel', { ...args }, entities_1.ThreadSchema);
173
+ return this.simple('GET', 'move_to_channel', { ...args }, this.threadSchema);
160
174
  }
161
175
  /**
162
176
  * Marks a thread as read.
@@ -244,7 +258,7 @@ class ThreadsClient extends base_client_1.BaseClient {
244
258
  * ```
245
259
  */
246
260
  muteThread(args) {
247
- return this.simple('GET', 'mute', { ...args }, entities_1.ThreadSchema);
261
+ return this.simple('GET', 'mute', { ...args }, this.threadSchema);
248
262
  }
249
263
  /**
250
264
  * Unmutes a thread.
@@ -254,7 +268,7 @@ class ThreadsClient extends base_client_1.BaseClient {
254
268
  * @returns The updated thread object.
255
269
  */
256
270
  unmuteThread(id) {
257
- return this.simple('GET', 'unmute', { id }, entities_1.ThreadSchema);
271
+ return this.simple('GET', 'unmute', { id }, this.threadSchema);
258
272
  }
259
273
  /**
260
274
  * Closes a thread by adding a comment with a close action.
@@ -314,7 +328,12 @@ class ThreadsClient extends base_client_1.BaseClient {
314
328
  }
315
329
  addCommentWithAction(args, threadAction) {
316
330
  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 });
331
+ return (0, add_comment_helper_1.addCommentRequest)({
332
+ baseUri: this.getBaseUri(),
333
+ apiToken: this.apiToken,
334
+ customFetch: this.customFetch,
335
+ schema: this.commentSchema,
336
+ }, { threadId: id, ...rest }, { threadAction });
318
337
  }
319
338
  simple(httpMethod, suffix, params, schema) {
320
339
  return (0, http_client_1.request)({
@@ -12,6 +12,14 @@ exports.ChannelListSchema = zod_1.z.array(entities_1.ChannelSchema);
12
12
  * currently rejects any `color` other than `1` on add/update.
13
13
  */
14
14
  class WorkspacesClient extends base_client_1.BaseClient {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.linkBaseUrl = this.getLinkBaseUrl();
18
+ // Reuse the shared singleton when no custom base is configured.
19
+ this.channelListSchema = this.linkBaseUrl
20
+ ? zod_1.z.array((0, entities_1.createChannelSchema)(this.linkBaseUrl))
21
+ : exports.ChannelListSchema;
22
+ }
15
23
  /**
16
24
  * Gets all the user's workspaces.
17
25
  *
@@ -160,7 +168,7 @@ class WorkspacesClient extends base_client_1.BaseClient {
160
168
  apiToken: this.apiToken,
161
169
  payload: { id },
162
170
  customFetch: this.customFetch,
163
- }).then((response) => exports.ChannelListSchema.parse(response.data));
171
+ }).then((response) => this.channelListSchema.parse(response.data));
164
172
  }
165
173
  }
166
174
  exports.WorkspacesClient = WorkspacesClient;