@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
@@ -19,20 +19,55 @@ const GetUnreadResponseSchema = zod_1.z.object({
19
19
  * `createThread` when the caller doesn't supply one.
20
20
  */
21
21
  class ThreadsClient extends base_client_1.BaseClient {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.linkBaseUrl = this.getLinkBaseUrl();
25
+ // Reuse the shared singletons when no custom base is configured.
26
+ this.threadSchema = this.linkBaseUrl
27
+ ? (0, entities_1.createThreadSchema)(this.linkBaseUrl)
28
+ : entities_1.ThreadSchema;
29
+ this.threadListSchema = this.linkBaseUrl
30
+ ? zod_1.z.array(this.threadSchema)
31
+ : exports.ThreadListSchema;
32
+ this.commentSchema = this.linkBaseUrl
33
+ ? (0, entities_1.createCommentSchema)(this.linkBaseUrl)
34
+ : entities_1.CommentSchema;
35
+ }
22
36
  /**
23
- * Lists threads. At least one of `channelId` / `workspaceId` is required.
37
+ * Gets threads. At least one of `channelId` / `workspaceId` is required.
24
38
  * `newerThan` / `olderThan` (`Date`) are converted to the
25
39
  * `newer_than_ts` / `older_than_ts` epoch-second params on the wire.
40
+ *
41
+ * @param args - The arguments for getting threads.
42
+ * @param args.workspaceId - The workspace ID.
43
+ * @param args.channelId - Optional channel ID to narrow to a single channel.
44
+ * @param args.archived - Optional flag to include archived threads.
45
+ * @param args.newerThan - Optional date to get threads newer than.
46
+ * @param args.olderThan - Optional date to get threads older than.
47
+ * @param args.limit - Optional limit on number of threads returned.
48
+ * @returns An array of thread objects.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const threads = await api.threads.getThreads({
53
+ * workspaceId: 123,
54
+ * channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44',
55
+ * })
56
+ * threads.forEach(t => console.log(t.title))
57
+ * ```
26
58
  */
27
59
  getThreads(args) {
28
- const { newerThan, olderThan, newer_than_ts, older_than_ts, ...rest } = args;
29
- const resolvedNewerThan = newerThan ? Math.floor(newerThan.getTime() / 1000) : newer_than_ts;
30
- const resolvedOlderThan = olderThan ? Math.floor(olderThan.getTime() / 1000) : older_than_ts;
31
- const params = {
32
- ...rest,
33
- ...(resolvedNewerThan != null ? { newer_than_ts: resolvedNewerThan } : {}),
34
- ...(resolvedOlderThan != null ? { older_than_ts: resolvedOlderThan } : {}),
35
- };
60
+ const params = { workspaceId: args.workspaceId };
61
+ if (args.channelId != null)
62
+ params.channelId = args.channelId;
63
+ if (args.archived != null)
64
+ params.archived = args.archived;
65
+ if (args.limit != null)
66
+ params.limit = args.limit;
67
+ if (args.newerThan)
68
+ params.newer_than_ts = Math.floor(args.newerThan.getTime() / 1000);
69
+ if (args.olderThan)
70
+ params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
36
71
  return (0, http_client_1.request)({
37
72
  httpMethod: 'GET',
38
73
  baseUri: this.getBaseUri(),
@@ -40,54 +75,149 @@ class ThreadsClient extends base_client_1.BaseClient {
40
75
  apiToken: this.apiToken,
41
76
  payload: params,
42
77
  customFetch: this.customFetch,
43
- }).then((response) => exports.ThreadListSchema.parse(response.data));
78
+ }).then((response) => this.threadListSchema.parse(response.data));
44
79
  }
45
- /** Fetches a single thread by ID. */
80
+ /**
81
+ * Gets a single thread object by id.
82
+ *
83
+ * @param id - The thread ID.
84
+ * @returns The thread object.
85
+ */
46
86
  getThread(id) {
47
- return this.simple('GET', 'getone', { id }, entities_1.ThreadSchema);
87
+ return this.simple('GET', 'getone', { id }, this.threadSchema);
48
88
  }
49
- /** Creates a new thread. `id` is auto-generated if not supplied. */
89
+ /**
90
+ * Creates a new thread in a channel. `id` is auto-generated if not supplied.
91
+ *
92
+ * @param args - The arguments for creating a thread.
93
+ * @param args.channelId - The channel ID.
94
+ * @param args.title - Optional thread title.
95
+ * @param args.content - The thread content.
96
+ * @param args.recipients - Optional array of user IDs to notify.
97
+ * @param args.groups - Optional array of custom group IDs to notify.
98
+ * @returns The created thread object.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * const thread = await api.threads.createThread({
103
+ * channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44',
104
+ * title: 'New Feature Discussion',
105
+ * content: 'Let\'s discuss the new feature...',
106
+ * })
107
+ * ```
108
+ */
50
109
  createThread(args) {
51
- return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.ThreadSchema);
110
+ return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, this.threadSchema);
52
111
  }
53
- /** Partial update of an existing thread. */
112
+ /**
113
+ * Partial update of an existing thread.
114
+ *
115
+ * @param args - The arguments for updating a thread.
116
+ * @param args.id - The thread ID.
117
+ * @param args.title - Optional new thread title.
118
+ * @param args.content - Optional new thread content.
119
+ * @returns The updated thread object.
120
+ */
54
121
  updateThread(args) {
55
- return this.simple('POST', 'update', { ...args }, entities_1.ThreadSchema);
122
+ return this.simple('POST', 'update', { ...args }, this.threadSchema);
56
123
  }
57
- /** Permanently deletes a thread. */
124
+ /**
125
+ * Permanently deletes a thread.
126
+ *
127
+ * @param id - The thread ID.
128
+ */
58
129
  deleteThread(id) {
59
130
  return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
60
131
  }
61
- /** Saves a thread (formerly "star"). */
132
+ /**
133
+ * Saves a thread (formerly "star").
134
+ *
135
+ * @param id - The thread ID.
136
+ */
62
137
  saveThread(id) {
63
138
  return this.simple('GET', 'save', { id }, entities_1.StatusOkSchema);
64
139
  }
65
- /** Unsaves a thread (formerly "unstar"). */
140
+ /**
141
+ * Unsaves a thread (formerly "unstar").
142
+ *
143
+ * @param id - The thread ID.
144
+ */
66
145
  unsaveThread(id) {
67
146
  return this.simple('GET', 'unsave', { id }, entities_1.StatusOkSchema);
68
147
  }
148
+ /**
149
+ * Pins a thread.
150
+ *
151
+ * @param id - The thread ID.
152
+ */
69
153
  pinThread(id) {
70
154
  return this.simple('GET', 'pin', { id }, entities_1.StatusOkSchema);
71
155
  }
156
+ /**
157
+ * Unpins a thread.
158
+ *
159
+ * @param id - The thread ID.
160
+ */
72
161
  unpinThread(id) {
73
162
  return this.simple('GET', 'unpin', { id }, entities_1.StatusOkSchema);
74
163
  }
75
- /** Moves a thread to another channel. */
164
+ /**
165
+ * Moves a thread to another channel.
166
+ *
167
+ * @param args - The arguments for moving a thread.
168
+ * @param args.id - The thread ID.
169
+ * @param args.toChannel - The target channel ID.
170
+ * @returns The updated thread object.
171
+ */
76
172
  moveToChannel(args) {
77
- return this.simple('GET', 'move_to_channel', { ...args }, entities_1.ThreadSchema);
173
+ return this.simple('GET', 'move_to_channel', { ...args }, this.threadSchema);
78
174
  }
175
+ /**
176
+ * Marks a thread as read.
177
+ *
178
+ * @param args - The arguments for marking a thread as read.
179
+ * @param args.id - The thread ID.
180
+ * @param args.objIndex - The index of the last known read message.
181
+ */
79
182
  markRead(args) {
80
183
  return this.simple('POST', 'mark_read', { ...args }, entities_1.StatusOkSchema);
81
184
  }
185
+ /**
186
+ * Marks a thread as unread.
187
+ *
188
+ * @param args - The arguments for marking a thread as unread.
189
+ * @param args.id - The thread ID.
190
+ * @param args.objIndex - The index of the last unread message. Use -1 to mark the whole thread as unread.
191
+ */
82
192
  markUnread(args) {
83
193
  return this.simple('POST', 'mark_unread', { ...args }, entities_1.StatusOkSchema);
84
194
  }
195
+ /**
196
+ * Marks a thread as unread for others. Useful to notify others about thread changes.
197
+ *
198
+ * @param args - The arguments for marking a thread as unread for others.
199
+ * @param args.id - The thread ID.
200
+ * @param args.objIndex - The index of the last unread message. Use -1 to mark the whole thread as unread.
201
+ */
85
202
  markUnreadForOthers(args) {
86
203
  return this.simple('POST', 'mark_unread_for_others', { ...args }, entities_1.StatusOkSchema);
87
204
  }
88
205
  /**
89
206
  * Marks every thread in a workspace or channel as read. Exactly one of
90
207
  * `workspaceId` / `channelId` should be set.
208
+ *
209
+ * @param args - Either workspaceId or channelId (one is required).
210
+ * @param args.workspaceId - The workspace ID.
211
+ * @param args.channelId - The channel ID.
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * // Mark all in workspace
216
+ * await api.threads.markAllRead({ workspaceId: 123 })
217
+ *
218
+ * // Mark all in channel
219
+ * await api.threads.markAllRead({ channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44' })
220
+ * ```
91
221
  */
92
222
  markAllRead(args) {
93
223
  if (!args.workspaceId && !args.channelId) {
@@ -95,31 +225,115 @@ class ThreadsClient extends base_client_1.BaseClient {
95
225
  }
96
226
  return this.simple('POST', 'mark_all_read', { ...args }, entities_1.StatusOkSchema);
97
227
  }
228
+ /**
229
+ * Clears unread threads in a workspace.
230
+ *
231
+ * @param workspaceId - The workspace ID.
232
+ */
98
233
  clearUnread(workspaceId) {
99
234
  return this.simple('GET', 'clear_unread', { workspaceId }, entities_1.StatusOkSchema);
100
235
  }
101
236
  /**
102
237
  * Returns unread threads for a workspace, paired with the unread version
103
238
  * counter and (optionally) the inbox unread count.
239
+ *
240
+ * @param workspaceId - The workspace ID.
241
+ * @returns Object containing the array of unread thread references, a version counter, and optionally the inbox unread count.
104
242
  */
105
243
  getUnread(workspaceId) {
106
244
  return this.simple('GET', 'get_unread', { workspaceId }, GetUnreadResponseSchema);
107
245
  }
246
+ /**
247
+ * Mutes a thread for a specified number of minutes.
248
+ * When muted, you will not get notified in your inbox about new comments.
249
+ *
250
+ * @param args - The arguments for muting a thread.
251
+ * @param args.id - The thread ID.
252
+ * @param args.minutes - Number of minutes to mute the thread.
253
+ * @returns The updated thread object.
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * const thread = await api.threads.muteThread({ id: '7YpL3oZ4kZ9vP7Q1tR2sX3z', minutes: 30 })
258
+ * ```
259
+ */
108
260
  muteThread(args) {
109
- return this.simple('GET', 'mute', { ...args }, entities_1.ThreadSchema);
261
+ return this.simple('GET', 'mute', { ...args }, this.threadSchema);
110
262
  }
263
+ /**
264
+ * Unmutes a thread.
265
+ * You will start to see notifications in your inbox again when new comments are added.
266
+ *
267
+ * @param id - The thread ID.
268
+ * @returns The updated thread object.
269
+ */
111
270
  unmuteThread(id) {
112
- return this.simple('GET', 'unmute', { id }, entities_1.ThreadSchema);
271
+ return this.simple('GET', 'unmute', { id }, this.threadSchema);
113
272
  }
273
+ /**
274
+ * Closes a thread by adding a comment with a close action.
275
+ *
276
+ * @param args - The arguments for closing a thread.
277
+ * @param args.id - The thread ID.
278
+ * @param args.content - The comment content.
279
+ * @param args.attachments - Optional array of {@link Attachment} objects.
280
+ * @param args.actions - Optional array of action objects.
281
+ * @param args.recipients - Optional array of user IDs to notify directly.
282
+ * @param args.groups - Optional array of custom group IDs to notify.
283
+ * @param args.directMentions - Optional array of user IDs that were @-mentioned in
284
+ * `content`.
285
+ * @param args.notifyAudience - Optional broader audience to notify in addition to
286
+ * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
287
+ * `'thread'` notifies everyone who has interacted with the thread.
288
+ * @returns The created comment object.
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * const comment = await api.threads.closeThread({
293
+ * id: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
294
+ * content: 'Closing this thread — resolved.',
295
+ * })
296
+ * ```
297
+ */
114
298
  closeThread(args) {
115
299
  return this.addCommentWithAction(args, 'close');
116
300
  }
301
+ /**
302
+ * Reopens a thread by adding a comment with a reopen action.
303
+ *
304
+ * @param args - The arguments for reopening a thread.
305
+ * @param args.id - The thread ID.
306
+ * @param args.content - The comment content.
307
+ * @param args.attachments - Optional array of {@link Attachment} objects.
308
+ * @param args.actions - Optional array of action objects.
309
+ * @param args.recipients - Optional array of user IDs to notify directly.
310
+ * @param args.groups - Optional array of custom group IDs to notify.
311
+ * @param args.directMentions - Optional array of user IDs that were @-mentioned in
312
+ * `content`.
313
+ * @param args.notifyAudience - Optional broader audience to notify in addition to
314
+ * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
315
+ * `'thread'` notifies everyone who has interacted with the thread.
316
+ * @returns The created comment object.
317
+ *
318
+ * @example
319
+ * ```typescript
320
+ * const comment = await api.threads.reopenThread({
321
+ * id: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
322
+ * content: 'Reopening — need further discussion.',
323
+ * })
324
+ * ```
325
+ */
117
326
  reopenThread(args) {
118
327
  return this.addCommentWithAction(args, 'reopen');
119
328
  }
120
329
  addCommentWithAction(args, threadAction) {
121
330
  const { id, ...rest } = args;
122
- return (0, add_comment_helper_1.addCommentRequest)({ baseUri: this.getBaseUri(), apiToken: this.apiToken, customFetch: this.customFetch }, { threadId: id, ...rest }, { threadAction });
331
+ return (0, add_comment_helper_1.addCommentRequest)({
332
+ baseUri: this.getBaseUri(),
333
+ apiToken: this.apiToken,
334
+ customFetch: this.customFetch,
335
+ schema: this.commentSchema,
336
+ }, { threadId: id, ...rest }, { threadAction });
123
337
  }
124
338
  simple(httpMethod, suffix, params, schema) {
125
339
  return (0, http_client_1.request)({
@@ -11,17 +11,45 @@ const base_client_1 = require("./base-client");
11
11
  * `loginWithTodoist` are the available entry points.
12
12
  */
13
13
  class UsersClient extends base_client_1.BaseClient {
14
- /** Registers a new user via the Todoist-ID bridge. */
14
+ /**
15
+ * Registers a new user via the Todoist-ID bridge.
16
+ *
17
+ * @param args - Registration arguments.
18
+ * @param args.name - The new user's full name.
19
+ * @param args.email - The new user's email.
20
+ * @param args.password - The new user's password.
21
+ * @param args.lang - Optional preferred language.
22
+ * @param args.acceptTerms - Optional flag confirming the user accepts the terms of service.
23
+ * @returns The newly registered user object.
24
+ */
15
25
  register(args) {
16
26
  return this.post(`${endpoints_1.ENDPOINT_USERS}/register`, args, entities_1.UserSchema, { authed: false });
17
27
  }
18
- /** Logs in an existing user. */
28
+ /**
29
+ * Logs in an existing user.
30
+ *
31
+ * @param args - Login credentials.
32
+ * @param args.email - The user's email.
33
+ * @param args.password - The user's password.
34
+ * @param args.setSessionCookie - Optional flag to set a session cookie (default: true).
35
+ * @returns The authenticated user object.
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const user = await api.users.login({
40
+ * email: 'user@example.com',
41
+ * password: 'secret',
42
+ * })
43
+ * ```
44
+ */
19
45
  login(args) {
20
46
  return this.post(`${endpoints_1.ENDPOINT_USERS}/login`, args, entities_1.UserSchema, { authed: false });
21
47
  }
22
48
  /**
23
49
  * Logs in using a valid token (sent via Authorization header). The SDK
24
50
  * client is already configured with the token, so no args are needed.
51
+ *
52
+ * @returns The authenticated user object.
25
53
  */
26
54
  loginWithToken() {
27
55
  return this.post(`${endpoints_1.ENDPOINT_USERS}/login_with_token`, undefined, entities_1.UserSchema);
@@ -30,17 +58,35 @@ class UsersClient extends base_client_1.BaseClient {
30
58
  * Exchanges the browser's Todoist web-session cookie for a Comms session.
31
59
  * Only useful when running in a browser context on the shared Todoist
32
60
  * registrable domain — the cookie is sent automatically by the browser.
61
+ *
62
+ * @returns The authenticated user object.
33
63
  */
34
64
  loginWithTodoist() {
35
65
  return this.post(`${endpoints_1.ENDPOINT_USERS}/login_with_todoist`, {}, entities_1.UserSchema, { authed: false });
36
66
  }
37
- /** Logs in (and auto-signs-up) via a Google ID token. */
67
+ /**
68
+ * Logs in (and auto-signs-up) via a Google ID token.
69
+ *
70
+ * @param args - Google login arguments.
71
+ * @param args.idToken - The Google ID token.
72
+ * @param args.nonce - The nonce that was sent to Google.
73
+ * @param args.timezone - Optional user timezone.
74
+ * @param args.lang - Optional preferred language.
75
+ * @param args.mfaToken - Optional MFA token from a prior `mfaChallenge` response.
76
+ * @returns The authenticated user object.
77
+ */
38
78
  loginWithGoogle(args) {
39
79
  return this.post(`${endpoints_1.ENDPOINT_USERS}/login_with_google`, args, entities_1.UserSchema, { authed: false });
40
80
  }
41
81
  /**
42
82
  * Completes an MFA challenge issued by `loginWithGoogle` (returns an MFA
43
83
  * token to pass back to `loginWithGoogle.mfaToken`).
84
+ *
85
+ * @param args - MFA challenge arguments.
86
+ * @param args.challengeId - The challenge ID from the prior login attempt.
87
+ * @param args.factor - The MFA factor identifier.
88
+ * @param args.methodType - The MFA method type.
89
+ * @returns The MFA token to forward to `loginWithGoogle`.
44
90
  */
45
91
  mfaChallenge(args) {
46
92
  return (0, http_client_1.request)({
@@ -63,7 +109,17 @@ class UsersClient extends base_client_1.BaseClient {
63
109
  customFetch: this.customFetch,
64
110
  }).then(() => undefined);
65
111
  }
66
- /** Returns the user associated with the current access token. */
112
+ /**
113
+ * Gets the user associated with the current access token.
114
+ *
115
+ * @returns The authenticated user's information.
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * const user = await api.users.getSessionUser()
120
+ * console.log(user.fullName, user.email)
121
+ * ```
122
+ */
67
123
  getSessionUser() {
68
124
  return this.get(`${endpoints_1.ENDPOINT_USERS}/get_session_user`, undefined, entities_1.UserSchema);
69
125
  }
@@ -71,32 +127,74 @@ class UsersClient extends base_client_1.BaseClient {
71
127
  * Fetches a single user. Defaults to the session user when no `id` is
72
128
  * passed. Cross-workspace lookups require that the caller and the target
73
129
  * share a workspace.
130
+ *
131
+ * @param args - Optional lookup arguments.
132
+ * @param args.id - The user ID. Defaults to the session user.
133
+ * @param args.workspaceId - Optional workspace ID for cross-workspace lookups.
134
+ * @param args.asList - Optional flag controlling list-style response.
135
+ * @returns The user object.
74
136
  */
75
137
  getUser(args) {
76
138
  return this.get(`${endpoints_1.ENDPOINT_USERS}/getone`, args ?? {}, entities_1.UserSchema);
77
139
  }
78
- /** Looks up a user by their email address. */
140
+ /**
141
+ * Looks up a user by their email address.
142
+ *
143
+ * @param email - The email to look up.
144
+ * @returns The user object.
145
+ */
79
146
  getUserByEmail(email) {
80
147
  return this.get(`${endpoints_1.ENDPOINT_USERS}/get_by_email`, { email }, entities_1.UserSchema);
81
148
  }
82
149
  /**
83
150
  * Updates the logged-in user's profile. Most fields are proxied to
84
151
  * Todoist (full name, password, language, timezone, etc.).
152
+ *
153
+ * @param args - The user properties to update.
154
+ * @returns The updated user object.
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const user = await api.users.update({
159
+ * name: 'John Doe',
160
+ * timezone: 'America/New_York',
161
+ * })
162
+ * ```
85
163
  */
86
164
  update(args) {
87
165
  return this.post(`${endpoints_1.ENDPOINT_USERS}/update`, args, entities_1.UserSchema);
88
166
  }
89
- /** Updates the user's password. Requires `currentPassword`. */
167
+ /**
168
+ * Updates the user's password.
169
+ *
170
+ * @param args - Password update arguments.
171
+ * @param args.newPassword - The new password.
172
+ * @param args.currentPassword - The user's existing password. Optional — sent for
173
+ * re-authentication when the account has a password set.
174
+ * @returns The updated user object.
175
+ */
90
176
  updatePassword(args) {
91
177
  return this.post(`${endpoints_1.ENDPOINT_USERS}/update_password`, args, entities_1.UserSchema);
92
178
  }
93
- /** Removes the user's avatar. */
179
+ /**
180
+ * Removes the user's avatar.
181
+ *
182
+ * @returns The updated user object.
183
+ */
94
184
  removeAvatar() {
95
185
  return this.post(`${endpoints_1.ENDPOINT_USERS}/remove_avatar`, undefined, entities_1.UserSchema);
96
186
  }
97
187
  /**
98
188
  * Invalidates the current API token and returns the user with a fresh
99
189
  * token.
190
+ *
191
+ * @returns The user object with the new token.
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * const user = await api.users.invalidateToken()
196
+ * console.log('New token:', user.token)
197
+ * ```
100
198
  */
101
199
  invalidateToken() {
102
200
  return this.post(`${endpoints_1.ENDPOINT_USERS}/invalidate_token`, undefined, entities_1.UserSchema);
@@ -105,6 +203,8 @@ class UsersClient extends base_client_1.BaseClient {
105
203
  * Validates that an arbitrary token is still active. Note this is sent
106
204
  * as a GET — the token is read from the query string, not the
107
205
  * Authorization header.
206
+ *
207
+ * @param token - The token to validate.
108
208
  */
109
209
  validateToken(token) {
110
210
  return (0, http_client_1.request)({
@@ -116,7 +216,18 @@ class UsersClient extends base_client_1.BaseClient {
116
216
  customFetch: this.customFetch,
117
217
  }).then(() => undefined);
118
218
  }
119
- /** Marks the user as active on a workspace (presence beacon). */
219
+ /**
220
+ * Marks the user as active on a workspace (presence beacon).
221
+ *
222
+ * @param args - Heartbeat arguments.
223
+ * @param args.workspaceId - The workspace ID.
224
+ * @param args.platform - The platform identifier (e.g., 'mobile', 'desktop', 'api').
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * await api.users.heartbeat({ workspaceId: 123, platform: 'api' })
229
+ * ```
230
+ */
120
231
  heartbeat(args) {
121
232
  return (0, http_client_1.request)({
122
233
  httpMethod: 'GET',
@@ -127,7 +238,11 @@ class UsersClient extends base_client_1.BaseClient {
127
238
  customFetch: this.customFetch,
128
239
  }).then(() => undefined);
129
240
  }
130
- /** Resets the user's presence for a workspace. */
241
+ /**
242
+ * Resets the user's presence for a workspace (marks the user as inactive).
243
+ *
244
+ * @param workspaceId - The workspace ID.
245
+ */
131
246
  resetPresence(workspaceId) {
132
247
  return (0, http_client_1.request)({
133
248
  httpMethod: 'POST',
@@ -138,7 +253,12 @@ class UsersClient extends base_client_1.BaseClient {
138
253
  customFetch: this.customFetch,
139
254
  }).then(() => undefined);
140
255
  }
141
- /** Checks whether an email address is registered (and verified). */
256
+ /**
257
+ * Checks whether an email address is registered (and verified).
258
+ *
259
+ * @param email - The email to check.
260
+ * @returns Object indicating whether the email exists and is verified.
261
+ */
142
262
  checkEmail(email) {
143
263
  return (0, http_client_1.request)({
144
264
  httpMethod: 'POST',
@@ -152,6 +272,8 @@ class UsersClient extends base_client_1.BaseClient {
152
272
  /**
153
273
  * Returns the current per-channel mail unsubscribe settings for the
154
274
  * caller's primary email.
275
+ *
276
+ * @returns Object mapping email-type keys to their opt-out flag.
155
277
  */
156
278
  getUnsubscribeSettings() {
157
279
  return (0, http_client_1.request)({
@@ -163,7 +285,12 @@ class UsersClient extends base_client_1.BaseClient {
163
285
  customFetch: this.customFetch,
164
286
  }).then((response) => response.data);
165
287
  }
166
- /** Toggles per-email-type opt-out settings. */
288
+ /**
289
+ * Toggles per-email-type opt-out settings.
290
+ *
291
+ * @param settings - Object mapping email-type keys to their opt-out flag.
292
+ * @returns Status object with `"ok"` status.
293
+ */
167
294
  updateUnsubscribeSettings(settings) {
168
295
  return (0, http_client_1.request)({
169
296
  httpMethod: 'POST',