@doist/comms-sdk 0.1.0-alpha.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 (62) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/clients/add-comment-helper.js +17 -0
  3. package/dist/cjs/clients/base-client.js +3 -5
  4. package/dist/cjs/clients/channels-client.js +123 -6
  5. package/dist/cjs/clients/comments-client.js +75 -9
  6. package/dist/cjs/clients/conversation-messages-client.js +76 -5
  7. package/dist/cjs/clients/conversations-client.js +143 -3
  8. package/dist/cjs/clients/groups-client.js +98 -5
  9. package/dist/cjs/clients/inbox-client.js +87 -14
  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 +211 -16
  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 +80 -7
  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/index.js +1 -0
  21. package/dist/cjs/types/requests.js +0 -1
  22. package/dist/esm/clients/add-comment-helper.js +17 -0
  23. package/dist/esm/clients/base-client.js +3 -5
  24. package/dist/esm/clients/channels-client.js +123 -6
  25. package/dist/esm/clients/comments-client.js +75 -9
  26. package/dist/esm/clients/conversation-messages-client.js +76 -5
  27. package/dist/esm/clients/conversations-client.js +143 -3
  28. package/dist/esm/clients/groups-client.js +98 -5
  29. package/dist/esm/clients/inbox-client.js +87 -14
  30. package/dist/esm/clients/reactions-client.js +40 -2
  31. package/dist/esm/clients/search-client.js +50 -0
  32. package/dist/esm/clients/threads-client.js +211 -16
  33. package/dist/esm/clients/users-client.js +138 -11
  34. package/dist/esm/clients/workspace-users-client.js +110 -10
  35. package/dist/esm/clients/workspaces-client.js +80 -7
  36. package/dist/esm/comms-api.js +1 -0
  37. package/dist/esm/consts/endpoints.js +8 -3
  38. package/dist/esm/testUtils/test-defaults.js +2 -0
  39. package/dist/esm/types/api-version.js +5 -0
  40. package/dist/esm/types/index.js +1 -0
  41. package/dist/esm/types/requests.js +0 -1
  42. package/dist/types/clients/add-comment-helper.d.ts +17 -0
  43. package/dist/types/clients/base-client.d.ts +4 -0
  44. package/dist/types/clients/channels-client.d.ts +123 -6
  45. package/dist/types/clients/comments-client.d.ts +73 -6
  46. package/dist/types/clients/conversation-messages-client.d.ts +76 -5
  47. package/dist/types/clients/conversations-client.d.ts +143 -3
  48. package/dist/types/clients/groups-client.d.ts +98 -5
  49. package/dist/types/clients/inbox-client.d.ts +81 -5
  50. package/dist/types/clients/reactions-client.d.ts +40 -2
  51. package/dist/types/clients/search-client.d.ts +50 -0
  52. package/dist/types/clients/threads-client.d.ts +200 -8
  53. package/dist/types/clients/users-client.d.ts +138 -11
  54. package/dist/types/clients/workspace-users-client.d.ts +110 -10
  55. package/dist/types/clients/workspaces-client.d.ts +80 -7
  56. package/dist/types/comms-api.d.ts +3 -0
  57. package/dist/types/consts/endpoints.d.ts +6 -1
  58. package/dist/types/testUtils/test-defaults.d.ts +1 -0
  59. package/dist/types/types/api-version.d.ts +6 -0
  60. package/dist/types/types/index.d.ts +1 -0
  61. package/dist/types/types/requests.d.ts +2 -21
  62. package/package.json +1 -1
@@ -18,7 +18,18 @@ exports.GroupListSchema = zod_1.z.array(entities_1.GroupSchema);
18
18
  * `workspace_id` alongside the group `id`.
19
19
  */
20
20
  class GroupsClient extends base_client_1.BaseClient {
21
- /** Lists groups in a workspace. */
21
+ /**
22
+ * Gets all groups for a given workspace.
23
+ *
24
+ * @param workspaceId - The workspace ID.
25
+ * @returns An array of group objects.
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const groups = await api.groups.getGroups(123)
30
+ * groups.forEach(g => console.log(g.name))
31
+ * ```
32
+ */
22
33
  getGroups(workspaceId) {
23
34
  return (0, http_client_1.request)({
24
35
  httpMethod: 'GET',
@@ -29,31 +40,113 @@ class GroupsClient extends base_client_1.BaseClient {
29
40
  customFetch: this.customFetch,
30
41
  }).then((response) => exports.GroupListSchema.parse(response.data));
31
42
  }
32
- /** Fetches a single group by ID (requires `workspaceId`). */
43
+ /**
44
+ * Gets a single group object by id. Requires `workspaceId`.
45
+ *
46
+ * @param args - The arguments for getting a group.
47
+ * @param args.id - The group ID.
48
+ * @param args.workspaceId - The workspace ID.
49
+ * @returns The group object.
50
+ */
33
51
  getGroup(args) {
34
52
  return this.simple('GET', 'getone', { ...args }, entities_1.GroupSchema);
35
53
  }
36
- /** Creates a new group. `id` is auto-generated if not supplied. */
54
+ /**
55
+ * Creates a new group. `id` is auto-generated if not supplied.
56
+ *
57
+ * @param args - The arguments for creating a group.
58
+ * @param args.workspaceId - The workspace ID.
59
+ * @param args.name - The group name.
60
+ * @param args.id - Optional caller-supplied group ID (for optimistic-UI workflows).
61
+ * @param args.description - Optional group description.
62
+ * @param args.userIds - Optional array of user IDs to add to the group.
63
+ * @returns The created group object.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const group = await api.groups.createGroup({
68
+ * workspaceId: 123,
69
+ * name: 'Engineering Team',
70
+ * userIds: [1, 2, 3],
71
+ * })
72
+ * ```
73
+ */
37
74
  createGroup(args) {
38
75
  return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.GroupSchema);
39
76
  }
40
- /** Updates a group. Requires `workspaceId`. */
77
+ /**
78
+ * Updates a group's properties. Requires `workspaceId`.
79
+ *
80
+ * @param args - The arguments for updating a group.
81
+ * @param args.id - The group ID.
82
+ * @param args.workspaceId - The workspace ID.
83
+ * @param args.name - Optional new group name.
84
+ * @param args.description - Optional new group description.
85
+ * @returns The updated group object.
86
+ */
41
87
  updateGroup(args) {
42
88
  return this.simple('POST', 'update', { ...args }, entities_1.GroupSchema);
43
89
  }
44
- /** Permanently deletes a group. Requires `workspaceId`. */
90
+ /**
91
+ * Permanently deletes a group. Requires `workspaceId`.
92
+ *
93
+ * @param args - The arguments for deleting a group.
94
+ * @param args.id - The group ID.
95
+ * @param args.workspaceId - The workspace ID.
96
+ */
45
97
  deleteGroup(args) {
46
98
  return this.simple('POST', 'remove', { ...args }, entities_1.StatusOkSchema);
47
99
  }
100
+ /**
101
+ * Adds a user to a group.
102
+ *
103
+ * @param args - The arguments for adding a user.
104
+ * @param args.id - The group ID.
105
+ * @param args.workspaceId - The workspace ID.
106
+ * @param args.userId - The user ID to add.
107
+ */
48
108
  addUser(args) {
49
109
  return this.simple('POST', 'add_user', { ...args }, entities_1.StatusOkSchema);
50
110
  }
111
+ /**
112
+ * Adds multiple users to a group.
113
+ *
114
+ * @param args - The arguments for adding users.
115
+ * @param args.id - The group ID.
116
+ * @param args.workspaceId - The workspace ID.
117
+ * @param args.userIds - Array of user IDs to add.
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * await api.groups.addUsers({
122
+ * id: '7YpL3oZ4kZ9vP7Q1tR2sX45',
123
+ * workspaceId: 123,
124
+ * userIds: [101, 202, 303],
125
+ * })
126
+ * ```
127
+ */
51
128
  addUsers(args) {
52
129
  return this.simple('POST', 'add_users', { ...args }, entities_1.StatusOkSchema);
53
130
  }
131
+ /**
132
+ * Removes a user from a group.
133
+ *
134
+ * @param args - The arguments for removing a user.
135
+ * @param args.id - The group ID.
136
+ * @param args.workspaceId - The workspace ID.
137
+ * @param args.userId - The user ID to remove.
138
+ */
54
139
  removeUser(args) {
55
140
  return this.simple('POST', 'remove_user', { ...args }, entities_1.StatusOkSchema);
56
141
  }
142
+ /**
143
+ * Removes multiple users from a group.
144
+ *
145
+ * @param args - The arguments for removing users.
146
+ * @param args.id - The group ID.
147
+ * @param args.workspaceId - The workspace ID.
148
+ * @param args.userIds - Array of user IDs to remove.
149
+ */
57
150
  removeUsers(args) {
58
151
  return this.simple('POST', 'remove_users', { ...args }, entities_1.StatusOkSchema);
59
152
  }
@@ -9,15 +9,36 @@ const base_client_1 = require("./base-client");
9
9
  class InboxClient extends base_client_1.BaseClient {
10
10
  /**
11
11
  * Gets inbox items (threads).
12
+ *
13
+ * @param args - The arguments for getting inbox.
14
+ * @param args.workspaceId - The workspace ID.
15
+ * @param args.newerThan - Optional date to get items newer than.
16
+ * @param args.olderThan - Optional date to get items older than.
17
+ * @param args.limit - Optional limit on number of items returned.
18
+ * @param args.cursor - Optional cursor for pagination.
19
+ * @param args.archiveFilter - Optional filter: 'active' (default), 'archived', or 'all'.
20
+ * @returns Inbox threads.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const inbox = await api.inbox.getInbox({
25
+ * workspaceId: 123,
26
+ * newerThan: new Date('2024-01-01'),
27
+ * })
28
+ *
29
+ * // Include archived (done) items alongside active ones
30
+ * const allInbox = await api.inbox.getInbox({
31
+ * workspaceId: 123,
32
+ * archiveFilter: 'all',
33
+ * })
34
+ * ```
12
35
  */
13
36
  getInbox(args) {
14
37
  const params = { workspace_id: args.workspaceId };
15
- const newerThan = args.newerThan ?? args.since;
16
- if (newerThan)
17
- params.newer_than_ts = Math.floor(newerThan.getTime() / 1000);
18
- const olderThan = args.olderThan ?? args.until;
19
- if (olderThan)
20
- params.older_than_ts = Math.floor(olderThan.getTime() / 1000);
38
+ if (args.newerThan)
39
+ params.newer_than_ts = Math.floor(args.newerThan.getTime() / 1000);
40
+ if (args.olderThan)
41
+ params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
21
42
  if (args.limit)
22
43
  params.limit = args.limit;
23
44
  if (args.cursor)
@@ -33,7 +54,18 @@ class InboxClient extends base_client_1.BaseClient {
33
54
  customFetch: this.customFetch,
34
55
  }).then((response) => response.data.map((thread) => entities_1.InboxThreadSchema.parse(thread)));
35
56
  }
36
- /** Gets unread count for inbox. */
57
+ /**
58
+ * Gets unread count for inbox.
59
+ *
60
+ * @param workspaceId - The workspace ID.
61
+ * @returns The unread count.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const count = await api.inbox.getCount(123)
66
+ * console.log(`Unread items: ${count}`)
67
+ * ```
68
+ */
37
69
  getCount(workspaceId) {
38
70
  return (0, http_client_1.request)({
39
71
  httpMethod: 'GET',
@@ -44,7 +76,16 @@ class InboxClient extends base_client_1.BaseClient {
44
76
  customFetch: this.customFetch,
45
77
  }).then((response) => response.data.data);
46
78
  }
47
- /** Archives a thread in the inbox. */
79
+ /**
80
+ * Archives a thread in the inbox.
81
+ *
82
+ * @param id - The thread ID.
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * await api.inbox.archiveThread('7YpL3oZ4kZ9vP7Q1tR2sX3z')
87
+ * ```
88
+ */
48
89
  archiveThread(id) {
49
90
  return (0, http_client_1.request)({
50
91
  httpMethod: 'POST',
@@ -55,7 +96,16 @@ class InboxClient extends base_client_1.BaseClient {
55
96
  customFetch: this.customFetch,
56
97
  }).then(() => undefined);
57
98
  }
58
- /** Unarchives a thread in the inbox. */
99
+ /**
100
+ * Unarchives a thread in the inbox.
101
+ *
102
+ * @param id - The thread ID.
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * await api.inbox.unarchiveThread('7YpL3oZ4kZ9vP7Q1tR2sX3z')
107
+ * ```
108
+ */
59
109
  unarchiveThread(id) {
60
110
  return (0, http_client_1.request)({
61
111
  httpMethod: 'POST',
@@ -66,7 +116,16 @@ class InboxClient extends base_client_1.BaseClient {
66
116
  customFetch: this.customFetch,
67
117
  }).then(() => undefined);
68
118
  }
69
- /** Marks all inbox items as read in a workspace. */
119
+ /**
120
+ * Marks all inbox items as read in a workspace.
121
+ *
122
+ * @param workspaceId - The workspace ID.
123
+ *
124
+ * @example
125
+ * ```typescript
126
+ * await api.inbox.markAllRead(123)
127
+ * ```
128
+ */
70
129
  markAllRead(workspaceId) {
71
130
  return (0, http_client_1.request)({
72
131
  httpMethod: 'POST',
@@ -77,14 +136,28 @@ class InboxClient extends base_client_1.BaseClient {
77
136
  customFetch: this.customFetch,
78
137
  }).then(() => undefined);
79
138
  }
80
- /** Archives all inbox items in a workspace. */
139
+ /**
140
+ * Archives all inbox items in a workspace.
141
+ *
142
+ * @param args - The arguments for archiving all.
143
+ * @param args.workspaceId - The workspace ID.
144
+ * @param args.channelIds - Optional array of channel IDs to filter by.
145
+ * @param args.olderThan - Optional date to filter items older than.
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * await api.inbox.archiveAll({
150
+ * workspaceId: 123,
151
+ * olderThan: new Date('2024-01-01'),
152
+ * })
153
+ * ```
154
+ */
81
155
  archiveAll(args) {
82
156
  const params = { workspace_id: args.workspaceId };
83
157
  if (args.channelIds)
84
158
  params.channel_ids = args.channelIds;
85
- const olderThan = args.olderThan ?? args.until;
86
- if (olderThan)
87
- params.older_than_ts = Math.floor(olderThan.getTime() / 1000);
159
+ if (args.olderThan)
160
+ params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
88
161
  return (0, http_client_1.request)({
89
162
  httpMethod: 'POST',
90
163
  baseUri: this.getBaseUri(),
@@ -17,7 +17,20 @@ function reactionTarget(args) {
17
17
  * Client for interacting with Comms reaction endpoints.
18
18
  */
19
19
  class ReactionsClient extends base_client_1.BaseClient {
20
- /** Adds an emoji reaction to a thread, comment, or conversation message. */
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
+ */
21
34
  add(args) {
22
35
  return (0, http_client_1.request)({
23
36
  httpMethod: 'POST',
@@ -33,6 +46,18 @@ class ReactionsClient extends base_client_1.BaseClient {
33
46
  *
34
47
  * Returns an object with emoji reactions as keys and arrays of user IDs as
35
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
+ * ```
36
61
  */
37
62
  get(args) {
38
63
  return (0, http_client_1.request)({
@@ -44,7 +69,20 @@ class ReactionsClient extends base_client_1.BaseClient {
44
69
  customFetch: this.customFetch,
45
70
  }).then((response) => response.data);
46
71
  }
47
- /** Removes an emoji reaction from a thread, comment, or conversation message. */
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
+ */
48
86
  remove(args) {
49
87
  return (0, http_client_1.request)({
50
88
  httpMethod: 'POST',
@@ -11,6 +11,26 @@ const base_client_1 = require("./base-client");
11
11
  class SearchClient extends base_client_1.BaseClient {
12
12
  /**
13
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
+ * ```
14
34
  */
15
35
  search(args) {
16
36
  const params = { workspace_id: args.workspaceId };
@@ -44,6 +64,21 @@ class SearchClient extends base_client_1.BaseClient {
44
64
  }
45
65
  /**
46
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
+ * ```
47
82
  */
48
83
  searchThread(args) {
49
84
  const params = {
@@ -65,6 +100,21 @@ class SearchClient extends base_client_1.BaseClient {
65
100
  }
66
101
  /**
67
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
+ * ```
68
118
  */
69
119
  searchConversation(args) {
70
120
  const params = {