@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
@@ -8,17 +8,45 @@ import { BaseClient } from './base-client.js';
8
8
  * `loginWithTodoist` are the available entry points.
9
9
  */
10
10
  export class UsersClient extends BaseClient {
11
- /** Registers a new user via the Todoist-ID bridge. */
11
+ /**
12
+ * Registers a new user via the Todoist-ID bridge.
13
+ *
14
+ * @param args - Registration arguments.
15
+ * @param args.name - The new user's full name.
16
+ * @param args.email - The new user's email.
17
+ * @param args.password - The new user's password.
18
+ * @param args.lang - Optional preferred language.
19
+ * @param args.acceptTerms - Optional flag confirming the user accepts the terms of service.
20
+ * @returns The newly registered user object.
21
+ */
12
22
  register(args) {
13
23
  return this.post(`${ENDPOINT_USERS}/register`, args, UserSchema, { authed: false });
14
24
  }
15
- /** Logs in an existing user. */
25
+ /**
26
+ * Logs in an existing user.
27
+ *
28
+ * @param args - Login credentials.
29
+ * @param args.email - The user's email.
30
+ * @param args.password - The user's password.
31
+ * @param args.setSessionCookie - Optional flag to set a session cookie (default: true).
32
+ * @returns The authenticated user object.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const user = await api.users.login({
37
+ * email: 'user@example.com',
38
+ * password: 'secret',
39
+ * })
40
+ * ```
41
+ */
16
42
  login(args) {
17
43
  return this.post(`${ENDPOINT_USERS}/login`, args, UserSchema, { authed: false });
18
44
  }
19
45
  /**
20
46
  * Logs in using a valid token (sent via Authorization header). The SDK
21
47
  * client is already configured with the token, so no args are needed.
48
+ *
49
+ * @returns The authenticated user object.
22
50
  */
23
51
  loginWithToken() {
24
52
  return this.post(`${ENDPOINT_USERS}/login_with_token`, undefined, UserSchema);
@@ -27,17 +55,35 @@ export class UsersClient extends BaseClient {
27
55
  * Exchanges the browser's Todoist web-session cookie for a Comms session.
28
56
  * Only useful when running in a browser context on the shared Todoist
29
57
  * registrable domain — the cookie is sent automatically by the browser.
58
+ *
59
+ * @returns The authenticated user object.
30
60
  */
31
61
  loginWithTodoist() {
32
62
  return this.post(`${ENDPOINT_USERS}/login_with_todoist`, {}, UserSchema, { authed: false });
33
63
  }
34
- /** Logs in (and auto-signs-up) via a Google ID token. */
64
+ /**
65
+ * Logs in (and auto-signs-up) via a Google ID token.
66
+ *
67
+ * @param args - Google login arguments.
68
+ * @param args.idToken - The Google ID token.
69
+ * @param args.nonce - The nonce that was sent to Google.
70
+ * @param args.timezone - Optional user timezone.
71
+ * @param args.lang - Optional preferred language.
72
+ * @param args.mfaToken - Optional MFA token from a prior `mfaChallenge` response.
73
+ * @returns The authenticated user object.
74
+ */
35
75
  loginWithGoogle(args) {
36
76
  return this.post(`${ENDPOINT_USERS}/login_with_google`, args, UserSchema, { authed: false });
37
77
  }
38
78
  /**
39
79
  * Completes an MFA challenge issued by `loginWithGoogle` (returns an MFA
40
80
  * token to pass back to `loginWithGoogle.mfaToken`).
81
+ *
82
+ * @param args - MFA challenge arguments.
83
+ * @param args.challengeId - The challenge ID from the prior login attempt.
84
+ * @param args.factor - The MFA factor identifier.
85
+ * @param args.methodType - The MFA method type.
86
+ * @returns The MFA token to forward to `loginWithGoogle`.
41
87
  */
42
88
  mfaChallenge(args) {
43
89
  return request({
@@ -60,7 +106,17 @@ export class UsersClient extends BaseClient {
60
106
  customFetch: this.customFetch,
61
107
  }).then(() => undefined);
62
108
  }
63
- /** Returns the user associated with the current access token. */
109
+ /**
110
+ * Gets the user associated with the current access token.
111
+ *
112
+ * @returns The authenticated user's information.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const user = await api.users.getSessionUser()
117
+ * console.log(user.fullName, user.email)
118
+ * ```
119
+ */
64
120
  getSessionUser() {
65
121
  return this.get(`${ENDPOINT_USERS}/get_session_user`, undefined, UserSchema);
66
122
  }
@@ -68,32 +124,74 @@ export class UsersClient extends BaseClient {
68
124
  * Fetches a single user. Defaults to the session user when no `id` is
69
125
  * passed. Cross-workspace lookups require that the caller and the target
70
126
  * share a workspace.
127
+ *
128
+ * @param args - Optional lookup arguments.
129
+ * @param args.id - The user ID. Defaults to the session user.
130
+ * @param args.workspaceId - Optional workspace ID for cross-workspace lookups.
131
+ * @param args.asList - Optional flag controlling list-style response.
132
+ * @returns The user object.
71
133
  */
72
134
  getUser(args) {
73
135
  return this.get(`${ENDPOINT_USERS}/getone`, args ?? {}, UserSchema);
74
136
  }
75
- /** Looks up a user by their email address. */
137
+ /**
138
+ * Looks up a user by their email address.
139
+ *
140
+ * @param email - The email to look up.
141
+ * @returns The user object.
142
+ */
76
143
  getUserByEmail(email) {
77
144
  return this.get(`${ENDPOINT_USERS}/get_by_email`, { email }, UserSchema);
78
145
  }
79
146
  /**
80
147
  * Updates the logged-in user's profile. Most fields are proxied to
81
148
  * Todoist (full name, password, language, timezone, etc.).
149
+ *
150
+ * @param args - The user properties to update.
151
+ * @returns The updated user object.
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const user = await api.users.update({
156
+ * name: 'John Doe',
157
+ * timezone: 'America/New_York',
158
+ * })
159
+ * ```
82
160
  */
83
161
  update(args) {
84
162
  return this.post(`${ENDPOINT_USERS}/update`, args, UserSchema);
85
163
  }
86
- /** Updates the user's password. Requires `currentPassword`. */
164
+ /**
165
+ * Updates the user's password.
166
+ *
167
+ * @param args - Password update arguments.
168
+ * @param args.newPassword - The new password.
169
+ * @param args.currentPassword - The user's existing password. Optional — sent for
170
+ * re-authentication when the account has a password set.
171
+ * @returns The updated user object.
172
+ */
87
173
  updatePassword(args) {
88
174
  return this.post(`${ENDPOINT_USERS}/update_password`, args, UserSchema);
89
175
  }
90
- /** Removes the user's avatar. */
176
+ /**
177
+ * Removes the user's avatar.
178
+ *
179
+ * @returns The updated user object.
180
+ */
91
181
  removeAvatar() {
92
182
  return this.post(`${ENDPOINT_USERS}/remove_avatar`, undefined, UserSchema);
93
183
  }
94
184
  /**
95
185
  * Invalidates the current API token and returns the user with a fresh
96
186
  * token.
187
+ *
188
+ * @returns The user object with the new token.
189
+ *
190
+ * @example
191
+ * ```typescript
192
+ * const user = await api.users.invalidateToken()
193
+ * console.log('New token:', user.token)
194
+ * ```
97
195
  */
98
196
  invalidateToken() {
99
197
  return this.post(`${ENDPOINT_USERS}/invalidate_token`, undefined, UserSchema);
@@ -102,6 +200,8 @@ export class UsersClient extends BaseClient {
102
200
  * Validates that an arbitrary token is still active. Note this is sent
103
201
  * as a GET — the token is read from the query string, not the
104
202
  * Authorization header.
203
+ *
204
+ * @param token - The token to validate.
105
205
  */
106
206
  validateToken(token) {
107
207
  return request({
@@ -113,7 +213,18 @@ export class UsersClient extends BaseClient {
113
213
  customFetch: this.customFetch,
114
214
  }).then(() => undefined);
115
215
  }
116
- /** Marks the user as active on a workspace (presence beacon). */
216
+ /**
217
+ * Marks the user as active on a workspace (presence beacon).
218
+ *
219
+ * @param args - Heartbeat arguments.
220
+ * @param args.workspaceId - The workspace ID.
221
+ * @param args.platform - The platform identifier (e.g., 'mobile', 'desktop', 'api').
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * await api.users.heartbeat({ workspaceId: 123, platform: 'api' })
226
+ * ```
227
+ */
117
228
  heartbeat(args) {
118
229
  return request({
119
230
  httpMethod: 'GET',
@@ -124,7 +235,11 @@ export class UsersClient extends BaseClient {
124
235
  customFetch: this.customFetch,
125
236
  }).then(() => undefined);
126
237
  }
127
- /** Resets the user's presence for a workspace. */
238
+ /**
239
+ * Resets the user's presence for a workspace (marks the user as inactive).
240
+ *
241
+ * @param workspaceId - The workspace ID.
242
+ */
128
243
  resetPresence(workspaceId) {
129
244
  return request({
130
245
  httpMethod: 'POST',
@@ -135,7 +250,12 @@ export class UsersClient extends BaseClient {
135
250
  customFetch: this.customFetch,
136
251
  }).then(() => undefined);
137
252
  }
138
- /** Checks whether an email address is registered (and verified). */
253
+ /**
254
+ * Checks whether an email address is registered (and verified).
255
+ *
256
+ * @param email - The email to check.
257
+ * @returns Object indicating whether the email exists and is verified.
258
+ */
139
259
  checkEmail(email) {
140
260
  return request({
141
261
  httpMethod: 'POST',
@@ -149,6 +269,8 @@ export class UsersClient extends BaseClient {
149
269
  /**
150
270
  * Returns the current per-channel mail unsubscribe settings for the
151
271
  * caller's primary email.
272
+ *
273
+ * @returns Object mapping email-type keys to their opt-out flag.
152
274
  */
153
275
  getUnsubscribeSettings() {
154
276
  return request({
@@ -160,7 +282,12 @@ export class UsersClient extends BaseClient {
160
282
  customFetch: this.customFetch,
161
283
  }).then((response) => response.data);
162
284
  }
163
- /** Toggles per-email-type opt-out settings. */
285
+ /**
286
+ * Toggles per-email-type opt-out settings.
287
+ *
288
+ * @param settings - Object mapping email-type keys to their opt-out flag.
289
+ * @returns Status object with `"ok"` status.
290
+ */
164
291
  updateUnsubscribeSettings(settings) {
165
292
  return request({
166
293
  httpMethod: 'POST',
@@ -6,7 +6,20 @@ import { BaseClient } from './base-client.js';
6
6
  * rejects non-empty `name` and `channelIds` — set neither.
7
7
  */
8
8
  export class WorkspaceUsersClient extends BaseClient {
9
- /** Returns workspace user objects for the given workspace id. */
9
+ /**
10
+ * Returns a list of workspace user objects for the given workspace id.
11
+ *
12
+ * @param args - The arguments for getting workspace users.
13
+ * @param args.workspaceId - The workspace ID.
14
+ * @param args.archived - Optional flag to filter archived users.
15
+ * @returns An array of workspace user objects.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const users = await api.workspaceUsers.getWorkspaceUsers({ workspaceId: 123 })
20
+ * users.forEach(u => console.log(u.fullName, u.userType))
21
+ * ```
22
+ */
10
23
  getWorkspaceUsers(args) {
11
24
  return request({
12
25
  httpMethod: 'GET',
@@ -17,7 +30,12 @@ export class WorkspaceUsersClient extends BaseClient {
17
30
  customFetch: this.customFetch,
18
31
  }).then((response) => response.data.map((user) => WorkspaceUserSchema.parse(user)));
19
32
  }
20
- /** Returns workspace user IDs for the given workspace id. */
33
+ /**
34
+ * Returns a list of workspace user IDs for the given workspace id.
35
+ *
36
+ * @param workspaceId - The workspace ID.
37
+ * @returns An array of user IDs.
38
+ */
21
39
  getWorkspaceUserIds(workspaceId) {
22
40
  return request({
23
41
  httpMethod: 'GET',
@@ -28,7 +46,20 @@ export class WorkspaceUsersClient extends BaseClient {
28
46
  customFetch: this.customFetch,
29
47
  }).then((response) => response.data);
30
48
  }
31
- /** Gets a user by id. */
49
+ /**
50
+ * Gets a user by id.
51
+ *
52
+ * @param args - The arguments for getting a user by ID.
53
+ * @param args.workspaceId - The workspace ID.
54
+ * @param args.userId - The user's ID.
55
+ * @returns The workspace user object.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const user = await api.workspaceUsers.getUserById({ workspaceId: 123, userId: 456 })
60
+ * console.log(user.fullName, user.email)
61
+ * ```
62
+ */
32
63
  getUserById(args) {
33
64
  return request({
34
65
  httpMethod: 'GET',
@@ -39,7 +70,22 @@ export class WorkspaceUsersClient extends BaseClient {
39
70
  customFetch: this.customFetch,
40
71
  }).then((response) => WorkspaceUserSchema.parse(response.data));
41
72
  }
42
- /** Gets a user by email. */
73
+ /**
74
+ * Gets a user by email.
75
+ *
76
+ * @param args - The arguments for getting a user by email.
77
+ * @param args.workspaceId - The workspace ID.
78
+ * @param args.email - The user's email.
79
+ * @returns The workspace user object.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const user = await api.workspaceUsers.getUserByEmail({
84
+ * workspaceId: 123,
85
+ * email: 'user@example.com',
86
+ * })
87
+ * ```
88
+ */
43
89
  getUserByEmail(args) {
44
90
  return request({
45
91
  httpMethod: 'GET',
@@ -50,7 +96,14 @@ export class WorkspaceUsersClient extends BaseClient {
50
96
  customFetch: this.customFetch,
51
97
  }).then((response) => WorkspaceUserSchema.parse(response.data));
52
98
  }
53
- /** Gets the user's info in the context of the workspace. */
99
+ /**
100
+ * Gets the user's info in the context of the workspace.
101
+ *
102
+ * @param args - The arguments for getting user info.
103
+ * @param args.workspaceId - The workspace ID.
104
+ * @param args.userId - The user's ID.
105
+ * @returns Information about the user in the workspace context.
106
+ */
54
107
  getUserInfo(args) {
55
108
  return request({
56
109
  httpMethod: 'GET',
@@ -61,7 +114,23 @@ export class WorkspaceUsersClient extends BaseClient {
61
114
  customFetch: this.customFetch,
62
115
  }).then((response) => response.data);
63
116
  }
64
- /** Gets the user's local time (e.g., "2017-05-10 07:55:40"). */
117
+ /**
118
+ * Gets the user's local time (e.g., "2017-05-10 07:55:40").
119
+ *
120
+ * @param args - The arguments for getting user local time.
121
+ * @param args.workspaceId - The workspace ID.
122
+ * @param args.userId - The user's ID.
123
+ * @returns The user's local time as a string.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const localTime = await api.workspaceUsers.getUserLocalTime({
128
+ * workspaceId: 123,
129
+ * userId: 456,
130
+ * })
131
+ * console.log('User local time:', localTime)
132
+ * ```
133
+ */
65
134
  getUserLocalTime(args) {
66
135
  return request({
67
136
  httpMethod: 'GET',
@@ -72,7 +141,15 @@ export class WorkspaceUsersClient extends BaseClient {
72
141
  customFetch: this.customFetch,
73
142
  }).then((response) => response.data);
74
143
  }
75
- /** Adds a person to a workspace. */
144
+ /**
145
+ * Adds a person to a workspace.
146
+ *
147
+ * @param args - The arguments for adding a user.
148
+ * @param args.workspaceId - The workspace ID.
149
+ * @param args.email - The user's email.
150
+ * @param args.userType - Optional user type (USER, GUEST, or ADMIN).
151
+ * @returns The created workspace user object.
152
+ */
76
153
  addUser(args) {
77
154
  return request({
78
155
  httpMethod: 'POST',
@@ -87,7 +164,16 @@ export class WorkspaceUsersClient extends BaseClient {
87
164
  customFetch: this.customFetch,
88
165
  }).then((response) => WorkspaceUserSchema.parse(response.data));
89
166
  }
90
- /** Updates a person in a workspace. */
167
+ /**
168
+ * Updates a person in a workspace.
169
+ *
170
+ * @param args - The arguments for updating a user.
171
+ * @param args.workspaceId - The workspace ID.
172
+ * @param args.userType - The user type (USER, GUEST, or ADMIN).
173
+ * @param args.email - Optional email of the user to update.
174
+ * @param args.userId - Optional user ID to update (use either email or userId).
175
+ * @returns The updated workspace user object.
176
+ */
91
177
  updateUser(args) {
92
178
  return request({
93
179
  httpMethod: 'POST',
@@ -103,7 +189,14 @@ export class WorkspaceUsersClient extends BaseClient {
103
189
  customFetch: this.customFetch,
104
190
  }).then((response) => WorkspaceUserSchema.parse(response.data));
105
191
  }
106
- /** Removes a person from a workspace. */
192
+ /**
193
+ * Removes a person from a workspace.
194
+ *
195
+ * @param args - The arguments for removing a user.
196
+ * @param args.workspaceId - The workspace ID.
197
+ * @param args.email - Optional email of the user to remove.
198
+ * @param args.userId - Optional user ID to remove (use either email or userId).
199
+ */
107
200
  removeUser(args) {
108
201
  return request({
109
202
  httpMethod: 'POST',
@@ -118,7 +211,14 @@ export class WorkspaceUsersClient extends BaseClient {
118
211
  customFetch: this.customFetch,
119
212
  }).then(() => undefined);
120
213
  }
121
- /** Sends a new workspace invitation to the selected user. */
214
+ /**
215
+ * Sends a new workspace invitation to the selected user.
216
+ *
217
+ * @param args - The arguments for resending an invite.
218
+ * @param args.workspaceId - The workspace ID.
219
+ * @param args.email - The user's email.
220
+ * @param args.userId - Optional user ID.
221
+ */
122
222
  resendInvite(args) {
123
223
  return request({
124
224
  httpMethod: 'POST',
@@ -9,7 +9,17 @@ export const ChannelListSchema = z.array(ChannelSchema);
9
9
  * currently rejects any `color` other than `1` on add/update.
10
10
  */
11
11
  export class WorkspacesClient extends BaseClient {
12
- /** Gets all the user's workspaces. */
12
+ /**
13
+ * Gets all the user's workspaces.
14
+ *
15
+ * @returns An array of all workspaces the user belongs to.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const workspaces = await api.workspaces.getWorkspaces()
20
+ * workspaces.forEach(ws => console.log(ws.name))
21
+ * ```
22
+ */
13
23
  getWorkspaces() {
14
24
  return request({
15
25
  httpMethod: 'GET',
@@ -20,7 +30,18 @@ export class WorkspacesClient extends BaseClient {
20
30
  customFetch: this.customFetch,
21
31
  }).then((response) => response.data.map((workspace) => WorkspaceSchema.parse(workspace)));
22
32
  }
23
- /** Gets a single workspace object by id. */
33
+ /**
34
+ * Gets a single workspace object by id.
35
+ *
36
+ * @param id - The workspace ID.
37
+ * @returns The workspace object.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const workspace = await api.workspaces.getWorkspace(123)
42
+ * console.log(workspace.name)
43
+ * ```
44
+ */
24
45
  getWorkspace(id) {
25
46
  return request({
26
47
  httpMethod: 'GET',
@@ -31,7 +52,17 @@ export class WorkspacesClient extends BaseClient {
31
52
  customFetch: this.customFetch,
32
53
  }).then((response) => WorkspaceSchema.parse(response.data));
33
54
  }
34
- /** Gets the user's default workspace. */
55
+ /**
56
+ * Gets the user's default workspace.
57
+ *
58
+ * @returns The default workspace object.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const workspace = await api.workspaces.getDefaultWorkspace()
63
+ * console.log(workspace.name)
64
+ * ```
65
+ */
35
66
  getDefaultWorkspace() {
36
67
  return request({
37
68
  httpMethod: 'GET',
@@ -42,7 +73,18 @@ export class WorkspacesClient extends BaseClient {
42
73
  customFetch: this.customFetch,
43
74
  }).then((response) => WorkspaceSchema.parse(response.data));
44
75
  }
45
- /** Creates a new workspace. */
76
+ /**
77
+ * Creates a new workspace.
78
+ *
79
+ * @param name - The name of the new workspace.
80
+ * @returns The created workspace object.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * const workspace = await api.workspaces.createWorkspace('My Team')
85
+ * console.log('Created:', workspace.name)
86
+ * ```
87
+ */
46
88
  createWorkspace(name) {
47
89
  return request({
48
90
  httpMethod: 'POST',
@@ -53,7 +95,18 @@ export class WorkspacesClient extends BaseClient {
53
95
  customFetch: this.customFetch,
54
96
  }).then((response) => WorkspaceSchema.parse(response.data));
55
97
  }
56
- /** Updates an existing workspace. */
98
+ /**
99
+ * Updates an existing workspace.
100
+ *
101
+ * @param id - The workspace ID.
102
+ * @param name - The new name for the workspace.
103
+ * @returns The updated workspace object.
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const workspace = await api.workspaces.updateWorkspace(123, 'New Team Name')
108
+ * ```
109
+ */
57
110
  updateWorkspace(id, name) {
58
111
  return request({
59
112
  httpMethod: 'POST',
@@ -64,7 +117,16 @@ export class WorkspacesClient extends BaseClient {
64
117
  customFetch: this.customFetch,
65
118
  }).then((response) => WorkspaceSchema.parse(response.data));
66
119
  }
67
- /** Removes a workspace and all its data (not recoverable). */
120
+ /**
121
+ * Removes a workspace and all its data (not recoverable).
122
+ *
123
+ * @param id - The workspace ID.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * await api.workspaces.removeWorkspace(123)
128
+ * ```
129
+ */
68
130
  removeWorkspace(id) {
69
131
  return request({
70
132
  httpMethod: 'POST',
@@ -75,7 +137,18 @@ export class WorkspacesClient extends BaseClient {
75
137
  customFetch: this.customFetch,
76
138
  }).then(() => undefined);
77
139
  }
78
- /** Gets the public channels of a workspace. */
140
+ /**
141
+ * Gets the public channels of a workspace.
142
+ *
143
+ * @param id - The workspace ID.
144
+ * @returns An array of public channel objects.
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const channels = await api.workspaces.getPublicChannels(123)
149
+ * channels.forEach(ch => console.log(ch.name))
150
+ * ```
151
+ */
79
152
  getPublicChannels(id) {
80
153
  return request({
81
154
  httpMethod: 'GET',
@@ -33,6 +33,7 @@ export class CommsApi {
33
33
  const clientConfig = {
34
34
  apiToken: authToken,
35
35
  baseUrl: options?.baseUrl,
36
+ version: options?.version,
36
37
  customFetch: options?.customFetch,
37
38
  };
38
39
  this.users = new UsersClient(clientConfig);
@@ -1,13 +1,18 @@
1
+ import { DEFAULT_API_VERSION } from '../types/api-version.js';
1
2
  const BASE_URI = 'https://comms.todoist.com';
2
- const API_VERSION = 'v1';
3
3
  /**
4
4
  * Gets the base URI for Comms API requests.
5
5
  *
6
+ * Preserves any path component on `domainBase` so callers can route through
7
+ * a proxy (e.g. `https://proxy.example.com/comms` → `.../comms/api/v1/`).
8
+ *
9
+ * @param version - API version. Defaults to 'v1'.
6
10
  * @param domainBase - Custom domain base URL. Defaults to Comms' API domain.
7
11
  * @returns Complete base URI with trailing slash (e.g., 'https://comms.todoist.com/api/v1/')
8
12
  */
9
- export function getCommsBaseUri(domainBase = BASE_URI) {
10
- return new URL(`/api/${API_VERSION}/`, domainBase).toString();
13
+ export function getCommsBaseUri(version = DEFAULT_API_VERSION, domainBase = BASE_URI) {
14
+ const base = domainBase.endsWith('/') ? domainBase : `${domainBase}/`;
15
+ return new URL(`api/${version}/`, base).toString();
11
16
  }
12
17
  export const ENDPOINT_USERS = 'users';
13
18
  export const ENDPOINT_WORKSPACES = 'workspaces';
@@ -1,4 +1,6 @@
1
+ import { getCommsBaseUri } from '../consts/endpoints.js';
1
2
  export const TEST_API_TOKEN = 'test-api-token';
3
+ export const TEST_API_BASE_URL = getCommsBaseUri().replace(/\/$/, '');
2
4
  // Canonical test IDs — shaped so they pass SDK-side validation.
3
5
  export const TEST_CHANNEL_ID = '7YpL3oZ4kZ9vP7Q1tR2sX3y';
4
6
  export const TEST_THREAD_ID = '7YpL3oZ4kZ9vP7Q1tR2sX3z';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Supported Comms API versions
3
+ */
4
+ export const API_VERSIONS = ['v1'];
5
+ export const DEFAULT_API_VERSION = 'v1';
@@ -1,3 +1,4 @@
1
+ export * from './api-version.js';
1
2
  export * from './entities.js';
2
3
  export * from './enums.js';
3
4
  export * from './errors.js';
@@ -94,7 +94,6 @@ export const GetThreadsArgsSchema = z.object({
94
94
  });
95
95
  export const GetCommentsArgsSchema = z.object({
96
96
  threadId: z.string(),
97
- from: z.date().nullable().optional(),
98
97
  newerThan: z.date().nullable().optional(),
99
98
  olderThan: z.date().nullable().optional(),
100
99
  limit: z.number().nullable().optional(),
@@ -6,6 +6,23 @@ type ClientContext = {
6
6
  apiToken: string;
7
7
  customFetch?: CustomFetch;
8
8
  };
9
+ /**
10
+ * Internal helper that powers `comments.createComment`,
11
+ * `threads.closeThread`, and `threads.reopenThread`.
12
+ *
13
+ * Normalizes the `notifyAudience` flag into a sentinel `groups` entry,
14
+ * rejects sentinel IDs passed via `groups` / `directGroupMentions`, mints a
15
+ * UUIDv7 `id` when the caller omits one, and posts to `/comments/add`. When
16
+ * `threadAction` is set (`'close'` / `'reopen'`), it is forwarded on the
17
+ * wire so the same request both adds the comment and transitions the
18
+ * parent thread.
19
+ *
20
+ * @param context - Per-call client context (base URI, API token, optional `customFetch`).
21
+ * @param params - The comment payload (`{@link CreateCommentArgs}`).
22
+ * @param options - Optional configuration.
23
+ * @param options.threadAction - When set, also transitions the parent thread (`'close'` or `'reopen'`).
24
+ * @returns The parsed {@link Comment} returned by the API.
25
+ */
9
26
  export declare function addCommentRequest(context: ClientContext, params: CreateCommentArgs, options?: {
10
27
  threadAction?: ThreadAction;
11
28
  }): Promise<Comment>;
@@ -1,9 +1,12 @@
1
+ import type { ApiVersion } from '../types/api-version.js';
1
2
  import type { CustomFetch } from '../types/http.js';
2
3
  export type ClientConfig = {
3
4
  /** API token for authentication */
4
5
  apiToken: string;
5
6
  /** Optional custom base URL. If not provided, uses the default Comms API URL */
6
7
  baseUrl?: string;
8
+ /** Optional API version. Defaults to 'v1' */
9
+ version?: ApiVersion;
7
10
  /** Optional custom fetch implementation for cross-platform compatibility */
8
11
  customFetch?: CustomFetch;
9
12
  };
@@ -14,6 +17,7 @@ export type ClientConfig = {
14
17
  export declare class BaseClient {
15
18
  protected readonly apiToken: string;
16
19
  protected readonly baseUrl?: string;
20
+ protected readonly defaultVersion: ApiVersion;
17
21
  protected readonly customFetch?: CustomFetch;
18
22
  constructor(config: ClientConfig);
19
23
  /**