@doist/comms-sdk 0.1.0-alpha.1 → 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 (67) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/clients/add-comment-helper.js +18 -2
  3. package/dist/cjs/clients/base-client.js +11 -5
  4. package/dist/cjs/clients/channels-client.js +142 -14
  5. package/dist/cjs/clients/comments-client.js +99 -14
  6. package/dist/cjs/clients/conversation-messages-client.js +91 -9
  7. package/dist/cjs/clients/conversations-client.js +166 -15
  8. package/dist/cjs/clients/groups-client.js +98 -5
  9. package/dist/cjs/clients/inbox-client.js +102 -16
  10. package/dist/cjs/clients/reactions-client.js +40 -2
  11. package/dist/cjs/clients/search-client.js +50 -0
  12. package/dist/cjs/clients/threads-client.js +238 -24
  13. package/dist/cjs/clients/users-client.js +138 -11
  14. package/dist/cjs/clients/workspace-users-client.js +110 -10
  15. package/dist/cjs/clients/workspaces-client.js +89 -8
  16. package/dist/cjs/comms-api.js +1 -0
  17. package/dist/cjs/consts/endpoints.js +8 -3
  18. package/dist/cjs/testUtils/test-defaults.js +3 -1
  19. package/dist/cjs/types/api-version.js +8 -0
  20. package/dist/cjs/types/entities.js +119 -98
  21. package/dist/cjs/types/index.js +1 -0
  22. package/dist/cjs/types/requests.js +0 -1
  23. package/dist/cjs/utils/url-helpers.js +3 -1
  24. package/dist/esm/clients/add-comment-helper.js +18 -2
  25. package/dist/esm/clients/base-client.js +11 -5
  26. package/dist/esm/clients/channels-client.js +143 -15
  27. package/dist/esm/clients/comments-client.js +100 -15
  28. package/dist/esm/clients/conversation-messages-client.js +92 -10
  29. package/dist/esm/clients/conversations-client.js +167 -16
  30. package/dist/esm/clients/groups-client.js +98 -5
  31. package/dist/esm/clients/inbox-client.js +102 -16
  32. package/dist/esm/clients/reactions-client.js +40 -2
  33. package/dist/esm/clients/search-client.js +50 -0
  34. package/dist/esm/clients/threads-client.js +239 -25
  35. package/dist/esm/clients/users-client.js +138 -11
  36. package/dist/esm/clients/workspace-users-client.js +110 -10
  37. package/dist/esm/clients/workspaces-client.js +90 -9
  38. package/dist/esm/comms-api.js +1 -0
  39. package/dist/esm/consts/endpoints.js +8 -3
  40. package/dist/esm/testUtils/test-defaults.js +2 -0
  41. package/dist/esm/types/api-version.js +5 -0
  42. package/dist/esm/types/entities.js +111 -97
  43. package/dist/esm/types/index.js +1 -0
  44. package/dist/esm/types/requests.js +0 -1
  45. package/dist/esm/utils/url-helpers.js +3 -1
  46. package/dist/types/clients/add-comment-helper.d.ts +20 -1
  47. package/dist/types/clients/base-client.d.ts +10 -0
  48. package/dist/types/clients/channels-client.d.ts +126 -6
  49. package/dist/types/clients/comments-client.d.ts +77 -6
  50. package/dist/types/clients/conversation-messages-client.d.ts +79 -5
  51. package/dist/types/clients/conversations-client.d.ts +146 -3
  52. package/dist/types/clients/groups-client.d.ts +98 -5
  53. package/dist/types/clients/inbox-client.d.ts +463 -5
  54. package/dist/types/clients/reactions-client.d.ts +40 -2
  55. package/dist/types/clients/search-client.d.ts +50 -0
  56. package/dist/types/clients/threads-client.d.ts +204 -8
  57. package/dist/types/clients/users-client.d.ts +138 -11
  58. package/dist/types/clients/workspace-users-client.d.ts +110 -10
  59. package/dist/types/clients/workspaces-client.d.ts +82 -7
  60. package/dist/types/comms-api.d.ts +3 -0
  61. package/dist/types/consts/endpoints.d.ts +6 -1
  62. package/dist/types/testUtils/test-defaults.d.ts +1 -0
  63. package/dist/types/types/api-version.d.ts +6 -0
  64. package/dist/types/types/entities.d.ts +1654 -126
  65. package/dist/types/types/index.d.ts +1 -0
  66. package/dist/types/types/requests.d.ts +2 -21
  67. package/package.json +1 -1
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Comms SDK (TypeScript)
1
+ # Comms SDK TypeScript
2
2
 
3
3
  The official TypeScript SDK for the Comms REST API.
4
4
 
@@ -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));
@@ -36,6 +35,23 @@ function applyNotifyAudience(params) {
36
35
  const { notifyAudience: _stripped, groups, ...rest } = params;
37
36
  return { ...rest, groups: [...(groups ?? []), sentinel] };
38
37
  }
38
+ /**
39
+ * Internal helper that powers `comments.createComment`,
40
+ * `threads.closeThread`, and `threads.reopenThread`.
41
+ *
42
+ * Normalizes the `notifyAudience` flag into a sentinel `groups` entry,
43
+ * rejects sentinel IDs passed via `groups` / `directGroupMentions`, mints a
44
+ * UUIDv7 `id` when the caller omits one, and posts to `/comments/add`. When
45
+ * `threadAction` is set (`'close'` / `'reopen'`), it is forwarded on the
46
+ * wire so the same request both adds the comment and transitions the
47
+ * parent thread.
48
+ *
49
+ * @param context - Per-call client context (base URI, API token, optional `customFetch`).
50
+ * @param params - The comment payload (`{@link CreateCommentArgs}`).
51
+ * @param options - Optional configuration.
52
+ * @param options.threadAction - When set, also transitions the parent thread (`'close'` or `'reopen'`).
53
+ * @returns The parsed {@link Comment} returned by the API.
54
+ */
39
55
  function addCommentRequest(context, params, options) {
40
56
  const normalized = applyNotifyAudience(params);
41
57
  const withId = { ...normalized, id: (0, uuidv7_1.resolveCreateId)(normalized.id) };
@@ -49,5 +65,5 @@ function addCommentRequest(context, params, options) {
49
65
  apiToken: context.apiToken,
50
66
  payload,
51
67
  customFetch: context.customFetch,
52
- }).then((response) => entities_1.CommentSchema.parse(response.data));
68
+ }).then((response) => context.schema.parse(response.data));
53
69
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseClient = void 0;
4
4
  const endpoints_1 = require("../consts/endpoints");
5
+ const api_version_1 = require("../types/api-version");
5
6
  /**
6
7
  * Base class for every Comms API client. Centralizes URL handling and
7
8
  * config so individual clients stay focused on their endpoints.
@@ -10,6 +11,7 @@ class BaseClient {
10
11
  constructor(config) {
11
12
  this.apiToken = config.apiToken;
12
13
  this.baseUrl = config.baseUrl;
14
+ this.defaultVersion = config.version || api_version_1.DEFAULT_API_VERSION;
13
15
  this.customFetch = config.customFetch;
14
16
  }
15
17
  /**
@@ -17,11 +19,15 @@ class BaseClient {
17
19
  * slash so relative paths resolve cleanly through `URL`.
18
20
  */
19
21
  getBaseUri() {
20
- if (this.baseUrl) {
21
- const normalizedBaseUrl = this.baseUrl.endsWith('/') ? this.baseUrl : `${this.baseUrl}/`;
22
- return `${normalizedBaseUrl}api/v1/`;
23
- }
24
- return (0, endpoints_1.getCommsBaseUri)();
22
+ return (0, endpoints_1.getCommsBaseUri)(this.defaultVersion, this.baseUrl);
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;
25
31
  }
26
32
  }
27
33
  exports.BaseClient = BaseClient;
@@ -14,7 +14,31 @@ 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
- /** Lists channels in a workspace. */
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
+ }
28
+ /**
29
+ * Gets all channels for a given workspace.
30
+ *
31
+ * @param args - The arguments for getting channels.
32
+ * @param args.workspaceId - The workspace ID.
33
+ * @param args.archived - Optional flag to include archived channels.
34
+ * @returns An array of channel objects.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const channels = await api.channels.getChannels({ workspaceId: 123 })
39
+ * channels.forEach(ch => console.log(ch.name))
40
+ * ```
41
+ */
18
42
  getChannels(args) {
19
43
  return (0, http_client_1.request)({
20
44
  httpMethod: 'GET',
@@ -23,51 +47,155 @@ class ChannelsClient extends base_client_1.BaseClient {
23
47
  apiToken: this.apiToken,
24
48
  payload: args,
25
49
  customFetch: this.customFetch,
26
- }).then((response) => exports.ChannelListSchema.parse(response.data));
50
+ }).then((response) => this.channelListSchema.parse(response.data));
27
51
  }
28
- /** Fetches a single channel by ID. */
52
+ /**
53
+ * Gets a single channel object by id.
54
+ *
55
+ * @param id - The channel ID.
56
+ * @returns The channel object.
57
+ */
29
58
  getChannel(id) {
30
- return this.simple('GET', 'getone', { id }, entities_1.ChannelSchema);
59
+ return this.simple('GET', 'getone', { id }, this.channelSchema);
31
60
  }
32
- /** Creates a new channel. `id` is auto-generated if not supplied. */
61
+ /**
62
+ * Creates a new channel. `id` is auto-generated if not supplied — pass your
63
+ * own `id` to keep an optimistic-UI ID stable through the round-trip.
64
+ *
65
+ * @param args - The arguments for creating a channel.
66
+ * @param args.workspaceId - The workspace ID.
67
+ * @param args.name - The channel name.
68
+ * @param args.description - Optional channel description.
69
+ * @param args.color - Optional channel color.
70
+ * @param args.userIds - Optional array of user IDs to add to the channel.
71
+ * @param args.public - Optional flag to make the channel public.
72
+ * @returns The created channel object.
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const channel = await api.channels.createChannel({
77
+ * workspaceId: 123,
78
+ * name: 'Engineering',
79
+ * description: 'Engineering team channel',
80
+ * })
81
+ * ```
82
+ */
33
83
  createChannel(args) {
34
- 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);
35
85
  }
36
- /** Partial update of an existing channel. */
86
+ /**
87
+ * Partial update of an existing channel.
88
+ *
89
+ * @param args - The arguments for updating a channel.
90
+ * @param args.id - The channel ID.
91
+ * @param args.name - Optional new channel name.
92
+ * @param args.description - Optional new channel description.
93
+ * @param args.color - Optional new channel color.
94
+ * @param args.public - Optional flag to change channel visibility.
95
+ * @returns The updated channel object.
96
+ */
37
97
  updateChannel(args) {
38
- return this.simple('POST', 'update', { ...args }, entities_1.ChannelSchema);
98
+ return this.simple('POST', 'update', { ...args }, this.channelSchema);
39
99
  }
40
- /** Updates the channel's view filter (`only_open` / `all` / `only_closed`). */
100
+ /**
101
+ * Updates the channel's view filter (`only_open` / `all` / `only_closed`).
102
+ *
103
+ * @param args - The arguments for updating the channel filter.
104
+ * @param args.id - The channel ID.
105
+ * @param args.filterClosed - The new filter value.
106
+ */
41
107
  updateFilters(args) {
42
108
  return this.simple('POST', 'update_filters', { ...args }, entities_1.StatusOkSchema);
43
109
  }
44
- /** Permanently deletes a channel. */
110
+ /**
111
+ * Permanently deletes a channel.
112
+ *
113
+ * @param id - The channel ID.
114
+ */
45
115
  deleteChannel(id) {
46
116
  return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
47
117
  }
118
+ /**
119
+ * Archives a channel.
120
+ *
121
+ * @param id - The channel ID.
122
+ */
48
123
  archiveChannel(id) {
49
124
  return this.simple('POST', 'archive', { id }, entities_1.StatusOkSchema);
50
125
  }
126
+ /**
127
+ * Unarchives a channel.
128
+ *
129
+ * @param id - The channel ID.
130
+ */
51
131
  unarchiveChannel(id) {
52
132
  return this.simple('POST', 'unarchive', { id }, entities_1.StatusOkSchema);
53
133
  }
134
+ /**
135
+ * Favorites a channel.
136
+ *
137
+ * @param id - The channel ID.
138
+ */
54
139
  favoriteChannel(id) {
55
140
  return this.simple('POST', 'favorite', { id }, entities_1.StatusOkSchema);
56
141
  }
142
+ /**
143
+ * Unfavorites a channel.
144
+ *
145
+ * @param id - The channel ID.
146
+ */
57
147
  unfavoriteChannel(id) {
58
148
  return this.simple('POST', 'unfavorite', { id }, entities_1.StatusOkSchema);
59
149
  }
150
+ /**
151
+ * Adds a user to a channel.
152
+ *
153
+ * @param args - The arguments for adding a user.
154
+ * @param args.id - The channel ID.
155
+ * @param args.userId - The user ID to add.
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * await api.channels.addUser({ id: '7YpL3oZ4kZ9vP7Q1tR2sX44', userId: 101 })
160
+ * ```
161
+ */
60
162
  addUser(args) {
61
- return this.simple('POST', 'add_user', { ...args }, entities_1.ChannelSchema);
163
+ return this.simple('POST', 'add_user', { ...args }, this.channelSchema);
62
164
  }
165
+ /**
166
+ * Adds multiple users to a channel.
167
+ *
168
+ * @param args - The arguments for adding users.
169
+ * @param args.id - The channel ID.
170
+ * @param args.userIds - Array of user IDs to add.
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * await api.channels.addUsers({ id: '7YpL3oZ4kZ9vP7Q1tR2sX44', userIds: [101, 202] })
175
+ * ```
176
+ */
63
177
  addUsers(args) {
64
- return this.simple('POST', 'add_users', { ...args }, entities_1.ChannelSchema);
178
+ return this.simple('POST', 'add_users', { ...args }, this.channelSchema);
65
179
  }
180
+ /**
181
+ * Removes a user from a channel.
182
+ *
183
+ * @param args - The arguments for removing a user.
184
+ * @param args.id - The channel ID.
185
+ * @param args.userId - The user ID to remove.
186
+ */
66
187
  removeUser(args) {
67
- return this.simple('POST', 'remove_user', { ...args }, entities_1.ChannelSchema);
188
+ return this.simple('POST', 'remove_user', { ...args }, this.channelSchema);
68
189
  }
190
+ /**
191
+ * Removes multiple users from a channel.
192
+ *
193
+ * @param args - The arguments for removing users.
194
+ * @param args.id - The channel ID.
195
+ * @param args.userIds - Array of user IDs to remove.
196
+ */
69
197
  removeUsers(args) {
70
- return this.simple('POST', 'remove_users', { ...args }, entities_1.ChannelSchema);
198
+ return this.simple('POST', 'remove_users', { ...args }, this.channelSchema);
71
199
  }
72
200
  simple(httpMethod, suffix, params, schema) {
73
201
  return (0, http_client_1.request)({
@@ -13,16 +13,46 @@ 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
- * Lists comments in a thread. `newerThan` / `olderThan` (`Date`) are
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
19
34
  * wire.
35
+ *
36
+ * @param args - The arguments for getting comments.
37
+ * @param args.threadId - The thread ID.
38
+ * @param args.newerThan - Optional date to get comments newer than.
39
+ * @param args.olderThan - Optional date to get comments older than.
40
+ * @param args.limit - Optional limit on number of comments returned.
41
+ * @returns An array of comment objects.
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * const comments = await api.comments.getComments({
46
+ * threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
47
+ * newerThan: new Date('2024-01-01'),
48
+ * })
49
+ * comments.forEach(c => console.log(c.content))
50
+ * ```
20
51
  */
21
52
  getComments(args) {
22
53
  const params = { threadId: args.threadId };
23
- const newerThan = args.newerThan ?? args.from;
24
- if (newerThan)
25
- params.newerThanTs = Math.floor(newerThan.getTime() / 1000);
54
+ if (args.newerThan)
55
+ params.newerThanTs = Math.floor(args.newerThan.getTime() / 1000);
26
56
  if (args.olderThan)
27
57
  params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
28
58
  if (args.limit)
@@ -34,11 +64,15 @@ class CommentsClient extends base_client_1.BaseClient {
34
64
  apiToken: this.apiToken,
35
65
  payload: params,
36
66
  customFetch: this.customFetch,
37
- }).then((response) => exports.CommentListSchema.parse(response.data));
67
+ }).then((response) => this.commentListSchema.parse(response.data));
38
68
  }
39
- /** Fetches a single comment by ID. The API wraps it in `{comment: ...}`. */
69
+ /**
70
+ * Gets a single comment object by id. The API wraps it in `{comment: ...}`.
71
+ *
72
+ * @param id - The comment ID.
73
+ * @returns The comment object.
74
+ */
40
75
  getComment(id) {
41
- const wrappedSchema = zod_1.z.object({ comment: entities_1.CommentSchema }).transform((data) => data.comment);
42
76
  return (0, http_client_1.request)({
43
77
  httpMethod: 'GET',
44
78
  baseUri: this.getBaseUri(),
@@ -46,15 +80,51 @@ class CommentsClient extends base_client_1.BaseClient {
46
80
  apiToken: this.apiToken,
47
81
  payload: { id },
48
82
  customFetch: this.customFetch,
49
- }).then((response) => wrappedSchema.parse(response.data));
83
+ }).then((response) => this.wrappedCommentSchema.parse(response.data));
50
84
  }
51
85
  /**
52
- * Creates a new comment. `id` is auto-generated if not supplied.
86
+ * Creates a new comment on a thread. `id` is auto-generated if not supplied.
87
+ *
88
+ * @param args - The arguments for creating a comment.
89
+ * @param args.threadId - The thread ID.
90
+ * @param args.content - The comment content.
91
+ * @param args.recipients - Optional array of user IDs to notify directly.
92
+ * @param args.groups - Optional array of custom group IDs to notify.
93
+ * @param args.directMentions - Optional array of user IDs that were @-mentioned in
94
+ * `content`.
95
+ * @param args.notifyAudience - Optional broader audience to notify in addition to
96
+ * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
97
+ * `'thread'` notifies everyone who has interacted with the thread.
98
+ * @param args.attachments - Optional array of {@link Attachment} objects.
99
+ * @returns The created comment object.
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * // Notify everyone who has interacted with the thread, plus two extra users.
104
+ * const comment = await api.comments.createComment({
105
+ * threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
106
+ * content: 'Great idea! Let\'s proceed.',
107
+ * notifyAudience: 'thread',
108
+ * recipients: [101, 202],
109
+ * })
110
+ * ```
53
111
  */
54
112
  createComment(args) {
55
- 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);
56
119
  }
57
- /** Updates a comment. */
120
+ /**
121
+ * Updates a comment's properties.
122
+ *
123
+ * @param args - The arguments for updating a comment.
124
+ * @param args.id - The comment ID.
125
+ * @param args.content - The new comment content.
126
+ * @returns The updated comment object.
127
+ */
58
128
  updateComment(args) {
59
129
  return (0, http_client_1.request)({
60
130
  httpMethod: 'POST',
@@ -63,9 +133,13 @@ class CommentsClient extends base_client_1.BaseClient {
63
133
  apiToken: this.apiToken,
64
134
  payload: { ...args },
65
135
  customFetch: this.customFetch,
66
- }).then((response) => entities_1.CommentSchema.parse(response.data));
136
+ }).then((response) => this.commentSchema.parse(response.data));
67
137
  }
68
- /** Permanently deletes a comment. */
138
+ /**
139
+ * Permanently deletes a comment.
140
+ *
141
+ * @param id - The comment ID.
142
+ */
69
143
  deleteComment(id) {
70
144
  return (0, http_client_1.request)({
71
145
  httpMethod: 'POST',
@@ -77,7 +151,18 @@ class CommentsClient extends base_client_1.BaseClient {
77
151
  }).then((response) => entities_1.StatusOkSchema.parse(response.data));
78
152
  }
79
153
  /**
80
- * Marks the user's read position in a thread. Comment IDs are strings.
154
+ * Marks the user's read position in a thread. Used to track where the user has read up to,
155
+ * so clients can scroll to this position and show a visual indicator (blue line).
156
+ * Comment IDs are strings.
157
+ *
158
+ * @param args - The arguments for marking read position.
159
+ * @param args.threadId - The thread ID.
160
+ * @param args.commentId - The comment ID to mark as the last read position.
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * await api.comments.markPosition({ threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z', commentId: '7YpL3oZ4kZ9vP7Q1tR2sX41' })
165
+ * ```
81
166
  */
82
167
  markPosition(args) {
83
168
  return (0, http_client_1.request)({
@@ -13,7 +13,36 @@ 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
- /** Lists messages in a conversation. */
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
+ }
27
+ /**
28
+ * Gets all messages in a conversation.
29
+ *
30
+ * @param args - The arguments for getting messages.
31
+ * @param args.conversationId - The conversation ID.
32
+ * @param args.newerThan - Optional date to get messages newer than.
33
+ * @param args.olderThan - Optional date to get messages older than.
34
+ * @param args.limit - Optional limit on number of messages returned.
35
+ * @param args.cursor - Optional cursor for pagination.
36
+ * @returns An array of message objects.
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * const messages = await api.conversationMessages.getMessages({
41
+ * conversationId: '7YpL3oZ4kZ9vP7Q1tR2sX42',
42
+ * newerThan: new Date('2024-01-01'),
43
+ * })
44
+ * ```
45
+ */
17
46
  getMessages(args) {
18
47
  const params = { conversationId: args.conversationId };
19
48
  if (args.newerThan)
@@ -31,13 +60,41 @@ class ConversationMessagesClient extends base_client_1.BaseClient {
31
60
  apiToken: this.apiToken,
32
61
  payload: params,
33
62
  customFetch: this.customFetch,
34
- }).then((response) => exports.ConversationMessageListSchema.parse(response.data));
63
+ }).then((response) => this.messageListSchema.parse(response.data));
35
64
  }
36
- /** Fetches a single message by ID. */
65
+ /**
66
+ * Gets a single conversation message by id.
67
+ *
68
+ * @param id - The message ID.
69
+ * @returns The conversation message object.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const message = await api.conversationMessages.getMessage('7YpL3oZ4kZ9vP7Q1tR2sX43')
74
+ * ```
75
+ */
37
76
  getMessage(id) {
38
- return this.simple('GET', 'getone', { id }, entities_1.ConversationMessageSchema);
77
+ return this.simple('GET', 'getone', { id }, this.messageSchema);
39
78
  }
40
- /** Creates a new message. `id` is auto-generated if not supplied. */
79
+ /**
80
+ * Creates a new message in a conversation. `id` is auto-generated if not
81
+ * supplied.
82
+ *
83
+ * @param args - The arguments for creating a message.
84
+ * @param args.conversationId - The conversation ID.
85
+ * @param args.content - The message content.
86
+ * @param args.attachments - Optional array of {@link Attachment} objects.
87
+ * @param args.actions - Optional array of action objects.
88
+ * @returns The created message object.
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const message = await api.conversationMessages.createMessage({
93
+ * conversationId: '7YpL3oZ4kZ9vP7Q1tR2sX42',
94
+ * content: 'Thanks for the update!',
95
+ * })
96
+ * ```
97
+ */
41
98
  createMessage(args) {
42
99
  const params = {
43
100
  conversationId: args.conversationId,
@@ -54,9 +111,25 @@ class ConversationMessagesClient extends base_client_1.BaseClient {
54
111
  params.directGroupMentions = args.directGroupMentions;
55
112
  if (args.notify !== undefined)
56
113
  params.notify = args.notify;
57
- return this.simple('POST', 'add', params, entities_1.ConversationMessageSchema);
114
+ return this.simple('POST', 'add', params, this.messageSchema);
58
115
  }
59
- /** Updates a message. */
116
+ /**
117
+ * Updates a conversation message.
118
+ *
119
+ * @param args - The arguments for updating a message.
120
+ * @param args.id - The message ID.
121
+ * @param args.content - The new message content.
122
+ * @param args.attachments - Optional array of {@link Attachment} objects.
123
+ * @returns The updated message object.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const message = await api.conversationMessages.updateMessage({
128
+ * id: '7YpL3oZ4kZ9vP7Q1tR2sX43',
129
+ * content: 'Updated message content',
130
+ * })
131
+ * ```
132
+ */
60
133
  updateMessage(args) {
61
134
  const params = { id: args.id, content: args.content };
62
135
  if (args.attachments)
@@ -67,9 +140,18 @@ class ConversationMessagesClient extends base_client_1.BaseClient {
67
140
  params.directMentions = args.directMentions;
68
141
  if (args.directGroupMentions)
69
142
  params.directGroupMentions = args.directGroupMentions;
70
- return this.simple('POST', 'update', params, entities_1.ConversationMessageSchema);
143
+ return this.simple('POST', 'update', params, this.messageSchema);
71
144
  }
72
- /** Permanently deletes a message. */
145
+ /**
146
+ * Permanently deletes a conversation message.
147
+ *
148
+ * @param id - The message ID.
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * await api.conversationMessages.deleteMessage('7YpL3oZ4kZ9vP7Q1tR2sX43')
153
+ * ```
154
+ */
73
155
  deleteMessage(id) {
74
156
  return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
75
157
  }