@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,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChannelsClient = exports.ChannelListSchema = 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 base_client_1 = require("./base-client");
10
+ exports.ChannelListSchema = zod_1.z.array(entities_1.ChannelSchema);
11
+ /**
12
+ * Client for `/api/v1/channels/`. The SDK auto-generates an `id` on
13
+ * `createChannel` when the caller doesn't supply one — pass your own `id`
14
+ * to keep an optimistic-UI ID stable through the round-trip.
15
+ */
16
+ class ChannelsClient extends base_client_1.BaseClient {
17
+ /**
18
+ * Gets all channels for a given workspace.
19
+ *
20
+ * @param args - The arguments for getting channels.
21
+ * @param args.workspaceId - The workspace ID.
22
+ * @param args.archived - Optional flag to include archived channels.
23
+ * @returns An array of channel objects.
24
+ *
25
+ * @example
26
+ * ```typescript
27
+ * const channels = await api.channels.getChannels({ workspaceId: 123 })
28
+ * channels.forEach(ch => console.log(ch.name))
29
+ * ```
30
+ */
31
+ getChannels(args) {
32
+ return (0, http_client_1.request)({
33
+ httpMethod: 'GET',
34
+ baseUri: this.getBaseUri(),
35
+ relativePath: `${endpoints_1.ENDPOINT_CHANNELS}/get`,
36
+ apiToken: this.apiToken,
37
+ payload: args,
38
+ customFetch: this.customFetch,
39
+ }).then((response) => exports.ChannelListSchema.parse(response.data));
40
+ }
41
+ /**
42
+ * Gets a single channel object by id.
43
+ *
44
+ * @param id - The channel ID.
45
+ * @returns The channel object.
46
+ */
47
+ getChannel(id) {
48
+ return this.simple('GET', 'getone', { id }, entities_1.ChannelSchema);
49
+ }
50
+ /**
51
+ * Creates a new channel. `id` is auto-generated if not supplied — pass your
52
+ * own `id` to keep an optimistic-UI ID stable through the round-trip.
53
+ *
54
+ * @param args - The arguments for creating a channel.
55
+ * @param args.workspaceId - The workspace ID.
56
+ * @param args.name - The channel name.
57
+ * @param args.description - Optional channel description.
58
+ * @param args.color - Optional channel color.
59
+ * @param args.userIds - Optional array of user IDs to add to the channel.
60
+ * @param args.public - Optional flag to make the channel public.
61
+ * @returns The created channel object.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const channel = await api.channels.createChannel({
66
+ * workspaceId: 123,
67
+ * name: 'Engineering',
68
+ * description: 'Engineering team channel',
69
+ * })
70
+ * ```
71
+ */
72
+ createChannel(args) {
73
+ return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.ChannelSchema);
74
+ }
75
+ /**
76
+ * Partial update of an existing channel.
77
+ *
78
+ * @param args - The arguments for updating a channel.
79
+ * @param args.id - The channel ID.
80
+ * @param args.name - Optional new channel name.
81
+ * @param args.description - Optional new channel description.
82
+ * @param args.color - Optional new channel color.
83
+ * @param args.public - Optional flag to change channel visibility.
84
+ * @returns The updated channel object.
85
+ */
86
+ updateChannel(args) {
87
+ return this.simple('POST', 'update', { ...args }, entities_1.ChannelSchema);
88
+ }
89
+ /**
90
+ * Updates the channel's view filter (`only_open` / `all` / `only_closed`).
91
+ *
92
+ * @param args - The arguments for updating the channel filter.
93
+ * @param args.id - The channel ID.
94
+ * @param args.filterClosed - The new filter value.
95
+ */
96
+ updateFilters(args) {
97
+ return this.simple('POST', 'update_filters', { ...args }, entities_1.StatusOkSchema);
98
+ }
99
+ /**
100
+ * Permanently deletes a channel.
101
+ *
102
+ * @param id - The channel ID.
103
+ */
104
+ deleteChannel(id) {
105
+ return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
106
+ }
107
+ /**
108
+ * Archives a channel.
109
+ *
110
+ * @param id - The channel ID.
111
+ */
112
+ archiveChannel(id) {
113
+ return this.simple('POST', 'archive', { id }, entities_1.StatusOkSchema);
114
+ }
115
+ /**
116
+ * Unarchives a channel.
117
+ *
118
+ * @param id - The channel ID.
119
+ */
120
+ unarchiveChannel(id) {
121
+ return this.simple('POST', 'unarchive', { id }, entities_1.StatusOkSchema);
122
+ }
123
+ /**
124
+ * Favorites a channel.
125
+ *
126
+ * @param id - The channel ID.
127
+ */
128
+ favoriteChannel(id) {
129
+ return this.simple('POST', 'favorite', { id }, entities_1.StatusOkSchema);
130
+ }
131
+ /**
132
+ * Unfavorites a channel.
133
+ *
134
+ * @param id - The channel ID.
135
+ */
136
+ unfavoriteChannel(id) {
137
+ return this.simple('POST', 'unfavorite', { id }, entities_1.StatusOkSchema);
138
+ }
139
+ /**
140
+ * Adds a user to a channel.
141
+ *
142
+ * @param args - The arguments for adding a user.
143
+ * @param args.id - The channel ID.
144
+ * @param args.userId - The user ID to add.
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * await api.channels.addUser({ id: '7YpL3oZ4kZ9vP7Q1tR2sX44', userId: 101 })
149
+ * ```
150
+ */
151
+ addUser(args) {
152
+ return this.simple('POST', 'add_user', { ...args }, entities_1.ChannelSchema);
153
+ }
154
+ /**
155
+ * Adds multiple users to a channel.
156
+ *
157
+ * @param args - The arguments for adding users.
158
+ * @param args.id - The channel ID.
159
+ * @param args.userIds - Array of user IDs to add.
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * await api.channels.addUsers({ id: '7YpL3oZ4kZ9vP7Q1tR2sX44', userIds: [101, 202] })
164
+ * ```
165
+ */
166
+ addUsers(args) {
167
+ return this.simple('POST', 'add_users', { ...args }, entities_1.ChannelSchema);
168
+ }
169
+ /**
170
+ * Removes a user from a channel.
171
+ *
172
+ * @param args - The arguments for removing a user.
173
+ * @param args.id - The channel ID.
174
+ * @param args.userId - The user ID to remove.
175
+ */
176
+ removeUser(args) {
177
+ return this.simple('POST', 'remove_user', { ...args }, entities_1.ChannelSchema);
178
+ }
179
+ /**
180
+ * Removes multiple users from a channel.
181
+ *
182
+ * @param args - The arguments for removing users.
183
+ * @param args.id - The channel ID.
184
+ * @param args.userIds - Array of user IDs to remove.
185
+ */
186
+ removeUsers(args) {
187
+ return this.simple('POST', 'remove_users', { ...args }, entities_1.ChannelSchema);
188
+ }
189
+ simple(httpMethod, suffix, params, schema) {
190
+ return (0, http_client_1.request)({
191
+ httpMethod,
192
+ baseUri: this.getBaseUri(),
193
+ relativePath: `${endpoints_1.ENDPOINT_CHANNELS}/${suffix}`,
194
+ apiToken: this.apiToken,
195
+ payload: params,
196
+ customFetch: this.customFetch,
197
+ }).then((response) => schema.parse(response.data));
198
+ }
199
+ }
200
+ exports.ChannelsClient = ChannelsClient;
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommentsClient = exports.CommentListSchema = 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 add_comment_helper_1 = require("./add-comment-helper");
9
+ const base_client_1 = require("./base-client");
10
+ exports.CommentListSchema = zod_1.z.array(entities_1.CommentSchema);
11
+ /**
12
+ * Client for `/api/v1/comments/`. The SDK auto-generates the comment `id`
13
+ * on `createComment` when the caller doesn't supply one.
14
+ */
15
+ class CommentsClient extends base_client_1.BaseClient {
16
+ /**
17
+ * Gets all comments for a thread. `newerThan` / `olderThan` (`Date`) are
18
+ * converted to `newer_than_ts` / `older_than_ts` epoch seconds on the
19
+ * wire.
20
+ *
21
+ * @param args - The arguments for getting comments.
22
+ * @param args.threadId - The thread ID.
23
+ * @param args.newerThan - Optional date to get comments newer than.
24
+ * @param args.olderThan - Optional date to get comments older than.
25
+ * @param args.limit - Optional limit on number of comments returned.
26
+ * @returns An array of comment objects.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const comments = await api.comments.getComments({
31
+ * threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
32
+ * newerThan: new Date('2024-01-01'),
33
+ * })
34
+ * comments.forEach(c => console.log(c.content))
35
+ * ```
36
+ */
37
+ getComments(args) {
38
+ const params = { threadId: args.threadId };
39
+ if (args.newerThan)
40
+ params.newerThanTs = Math.floor(args.newerThan.getTime() / 1000);
41
+ if (args.olderThan)
42
+ params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
43
+ if (args.limit)
44
+ params.limit = args.limit;
45
+ return (0, http_client_1.request)({
46
+ httpMethod: 'GET',
47
+ baseUri: this.getBaseUri(),
48
+ relativePath: `${endpoints_1.ENDPOINT_COMMENTS}/get`,
49
+ apiToken: this.apiToken,
50
+ payload: params,
51
+ customFetch: this.customFetch,
52
+ }).then((response) => exports.CommentListSchema.parse(response.data));
53
+ }
54
+ /**
55
+ * Gets a single comment object by id. The API wraps it in `{comment: ...}`.
56
+ *
57
+ * @param id - The comment ID.
58
+ * @returns The comment object.
59
+ */
60
+ getComment(id) {
61
+ const wrappedSchema = zod_1.z.object({ comment: entities_1.CommentSchema }).transform((data) => data.comment);
62
+ return (0, http_client_1.request)({
63
+ httpMethod: 'GET',
64
+ baseUri: this.getBaseUri(),
65
+ relativePath: `${endpoints_1.ENDPOINT_COMMENTS}/getone`,
66
+ apiToken: this.apiToken,
67
+ payload: { id },
68
+ customFetch: this.customFetch,
69
+ }).then((response) => wrappedSchema.parse(response.data));
70
+ }
71
+ /**
72
+ * Creates a new comment on a thread. `id` is auto-generated if not supplied.
73
+ *
74
+ * @param args - The arguments for creating a comment.
75
+ * @param args.threadId - The thread ID.
76
+ * @param args.content - The comment content.
77
+ * @param args.recipients - Optional array of user IDs to notify directly.
78
+ * @param args.groups - Optional array of custom group IDs to notify.
79
+ * @param args.directMentions - Optional array of user IDs that were @-mentioned in
80
+ * `content`.
81
+ * @param args.notifyAudience - Optional broader audience to notify in addition to
82
+ * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
83
+ * `'thread'` notifies everyone who has interacted with the thread.
84
+ * @param args.attachments - Optional array of {@link Attachment} objects.
85
+ * @returns The created comment object.
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * // Notify everyone who has interacted with the thread, plus two extra users.
90
+ * const comment = await api.comments.createComment({
91
+ * threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
92
+ * content: 'Great idea! Let\'s proceed.',
93
+ * notifyAudience: 'thread',
94
+ * recipients: [101, 202],
95
+ * })
96
+ * ```
97
+ */
98
+ createComment(args) {
99
+ return (0, add_comment_helper_1.addCommentRequest)({ baseUri: this.getBaseUri(), apiToken: this.apiToken, customFetch: this.customFetch }, args);
100
+ }
101
+ /**
102
+ * Updates a comment's properties.
103
+ *
104
+ * @param args - The arguments for updating a comment.
105
+ * @param args.id - The comment ID.
106
+ * @param args.content - The new comment content.
107
+ * @returns The updated comment object.
108
+ */
109
+ updateComment(args) {
110
+ return (0, http_client_1.request)({
111
+ httpMethod: 'POST',
112
+ baseUri: this.getBaseUri(),
113
+ relativePath: `${endpoints_1.ENDPOINT_COMMENTS}/update`,
114
+ apiToken: this.apiToken,
115
+ payload: { ...args },
116
+ customFetch: this.customFetch,
117
+ }).then((response) => entities_1.CommentSchema.parse(response.data));
118
+ }
119
+ /**
120
+ * Permanently deletes a comment.
121
+ *
122
+ * @param id - The comment ID.
123
+ */
124
+ deleteComment(id) {
125
+ return (0, http_client_1.request)({
126
+ httpMethod: 'POST',
127
+ baseUri: this.getBaseUri(),
128
+ relativePath: `${endpoints_1.ENDPOINT_COMMENTS}/remove`,
129
+ apiToken: this.apiToken,
130
+ payload: { id },
131
+ customFetch: this.customFetch,
132
+ }).then((response) => entities_1.StatusOkSchema.parse(response.data));
133
+ }
134
+ /**
135
+ * Marks the user's read position in a thread. Used to track where the user has read up to,
136
+ * so clients can scroll to this position and show a visual indicator (blue line).
137
+ * Comment IDs are strings.
138
+ *
139
+ * @param args - The arguments for marking read position.
140
+ * @param args.threadId - The thread ID.
141
+ * @param args.commentId - The comment ID to mark as the last read position.
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * await api.comments.markPosition({ threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z', commentId: '7YpL3oZ4kZ9vP7Q1tR2sX41' })
146
+ * ```
147
+ */
148
+ markPosition(args) {
149
+ return (0, http_client_1.request)({
150
+ httpMethod: 'POST',
151
+ baseUri: this.getBaseUri(),
152
+ relativePath: `${endpoints_1.ENDPOINT_COMMENTS}/mark_position`,
153
+ apiToken: this.apiToken,
154
+ payload: { threadId: args.threadId, commentId: args.commentId },
155
+ customFetch: this.customFetch,
156
+ }).then((response) => entities_1.StatusOkSchema.parse(response.data));
157
+ }
158
+ }
159
+ exports.CommentsClient = CommentsClient;
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConversationMessagesClient = exports.ConversationMessageListSchema = 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 base_client_1 = require("./base-client");
10
+ exports.ConversationMessageListSchema = zod_1.z.array(entities_1.ConversationMessageSchema);
11
+ /**
12
+ * Client for `/api/v1/conversation_messages/`. The SDK auto-generates the
13
+ * message `id` on `createMessage` when the caller doesn't supply one.
14
+ */
15
+ class ConversationMessagesClient extends base_client_1.BaseClient {
16
+ /**
17
+ * Gets all messages in a conversation.
18
+ *
19
+ * @param args - The arguments for getting messages.
20
+ * @param args.conversationId - The conversation ID.
21
+ * @param args.newerThan - Optional date to get messages newer than.
22
+ * @param args.olderThan - Optional date to get messages older than.
23
+ * @param args.limit - Optional limit on number of messages returned.
24
+ * @param args.cursor - Optional cursor for pagination.
25
+ * @returns An array of message objects.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const messages = await api.conversationMessages.getMessages({
30
+ * conversationId: '7YpL3oZ4kZ9vP7Q1tR2sX42',
31
+ * newerThan: new Date('2024-01-01'),
32
+ * })
33
+ * ```
34
+ */
35
+ getMessages(args) {
36
+ const params = { conversationId: args.conversationId };
37
+ if (args.newerThan)
38
+ params.newerThanTs = Math.floor(args.newerThan.getTime() / 1000);
39
+ if (args.olderThan)
40
+ params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
41
+ if (args.limit)
42
+ params.limit = args.limit;
43
+ if (args.cursor)
44
+ params.cursor = args.cursor;
45
+ return (0, http_client_1.request)({
46
+ httpMethod: 'GET',
47
+ baseUri: this.getBaseUri(),
48
+ relativePath: `${endpoints_1.ENDPOINT_CONVERSATION_MESSAGES}/get`,
49
+ apiToken: this.apiToken,
50
+ payload: params,
51
+ customFetch: this.customFetch,
52
+ }).then((response) => exports.ConversationMessageListSchema.parse(response.data));
53
+ }
54
+ /**
55
+ * Gets a single conversation message by id.
56
+ *
57
+ * @param id - The message ID.
58
+ * @returns The conversation message object.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const message = await api.conversationMessages.getMessage('7YpL3oZ4kZ9vP7Q1tR2sX43')
63
+ * ```
64
+ */
65
+ getMessage(id) {
66
+ return this.simple('GET', 'getone', { id }, entities_1.ConversationMessageSchema);
67
+ }
68
+ /**
69
+ * Creates a new message in a conversation. `id` is auto-generated if not
70
+ * supplied.
71
+ *
72
+ * @param args - The arguments for creating a message.
73
+ * @param args.conversationId - The conversation ID.
74
+ * @param args.content - The message content.
75
+ * @param args.attachments - Optional array of {@link Attachment} objects.
76
+ * @param args.actions - Optional array of action objects.
77
+ * @returns The created message object.
78
+ *
79
+ * @example
80
+ * ```typescript
81
+ * const message = await api.conversationMessages.createMessage({
82
+ * conversationId: '7YpL3oZ4kZ9vP7Q1tR2sX42',
83
+ * content: 'Thanks for the update!',
84
+ * })
85
+ * ```
86
+ */
87
+ createMessage(args) {
88
+ const params = {
89
+ conversationId: args.conversationId,
90
+ content: args.content,
91
+ id: (0, uuidv7_1.resolveCreateId)(args.id),
92
+ };
93
+ if (args.attachments)
94
+ params.attachments = args.attachments;
95
+ if (args.actions)
96
+ params.actions = args.actions;
97
+ if (args.directMentions)
98
+ params.directMentions = args.directMentions;
99
+ if (args.directGroupMentions)
100
+ params.directGroupMentions = args.directGroupMentions;
101
+ if (args.notify !== undefined)
102
+ params.notify = args.notify;
103
+ return this.simple('POST', 'add', params, entities_1.ConversationMessageSchema);
104
+ }
105
+ /**
106
+ * Updates a conversation message.
107
+ *
108
+ * @param args - The arguments for updating a message.
109
+ * @param args.id - The message ID.
110
+ * @param args.content - The new message content.
111
+ * @param args.attachments - Optional array of {@link Attachment} objects.
112
+ * @returns The updated message object.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const message = await api.conversationMessages.updateMessage({
117
+ * id: '7YpL3oZ4kZ9vP7Q1tR2sX43',
118
+ * content: 'Updated message content',
119
+ * })
120
+ * ```
121
+ */
122
+ updateMessage(args) {
123
+ const params = { id: args.id, content: args.content };
124
+ if (args.attachments)
125
+ params.attachments = args.attachments;
126
+ if (args.actions)
127
+ params.actions = args.actions;
128
+ if (args.directMentions)
129
+ params.directMentions = args.directMentions;
130
+ if (args.directGroupMentions)
131
+ params.directGroupMentions = args.directGroupMentions;
132
+ return this.simple('POST', 'update', params, entities_1.ConversationMessageSchema);
133
+ }
134
+ /**
135
+ * Permanently deletes a conversation message.
136
+ *
137
+ * @param id - The message ID.
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * await api.conversationMessages.deleteMessage('7YpL3oZ4kZ9vP7Q1tR2sX43')
142
+ * ```
143
+ */
144
+ deleteMessage(id) {
145
+ return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
146
+ }
147
+ simple(httpMethod, suffix, params, schema) {
148
+ return (0, http_client_1.request)({
149
+ httpMethod,
150
+ baseUri: this.getBaseUri(),
151
+ relativePath: `${endpoints_1.ENDPOINT_CONVERSATION_MESSAGES}/${suffix}`,
152
+ apiToken: this.apiToken,
153
+ payload: params,
154
+ customFetch: this.customFetch,
155
+ }).then((response) => schema.parse(response.data));
156
+ }
157
+ }
158
+ exports.ConversationMessagesClient = ConversationMessagesClient;