@doist/comms-sdk 2.0.1 → 3.0.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 (48) hide show
  1. package/dist/esm/utils/multipart-upload.js +73 -15
  2. package/dist/esm/utils/url-helpers.js +104 -16
  3. package/dist/types/utils/multipart-upload.d.ts +3 -4
  4. package/dist/types/utils/url-helpers.d.ts +41 -0
  5. package/package.json +5 -10
  6. package/dist/cjs/authentication.js +0 -256
  7. package/dist/cjs/clients/add-comment-helper.js +0 -43
  8. package/dist/cjs/clients/attachments-client.js +0 -71
  9. package/dist/cjs/clients/base-client.js +0 -33
  10. package/dist/cjs/clients/channels-client.js +0 -211
  11. package/dist/cjs/clients/comments-client.js +0 -175
  12. package/dist/cjs/clients/conversation-messages-client.js +0 -169
  13. package/dist/cjs/clients/conversations-client.js +0 -283
  14. package/dist/cjs/clients/groups-client.js +0 -172
  15. package/dist/cjs/clients/hooks-client.js +0 -52
  16. package/dist/cjs/clients/inbox-client.js +0 -184
  17. package/dist/cjs/clients/notify-audience.js +0 -45
  18. package/dist/cjs/clients/reactions-client.js +0 -97
  19. package/dist/cjs/clients/search-client.js +0 -138
  20. package/dist/cjs/clients/threads-client.js +0 -364
  21. package/dist/cjs/clients/users-client.js +0 -326
  22. package/dist/cjs/clients/workspace-users-client.js +0 -252
  23. package/dist/cjs/clients/workspaces-client.js +0 -174
  24. package/dist/cjs/comms-api.js +0 -70
  25. package/dist/cjs/consts/endpoints.js +0 -34
  26. package/dist/cjs/index.js +0 -53
  27. package/dist/cjs/migration.js +0 -96
  28. package/dist/cjs/package.json +0 -1
  29. package/dist/cjs/testUtils/msw-handlers.js +0 -51
  30. package/dist/cjs/testUtils/msw-setup.js +0 -35
  31. package/dist/cjs/testUtils/obsidian-fetch-adapter.js +0 -53
  32. package/dist/cjs/testUtils/test-defaults.js +0 -106
  33. package/dist/cjs/transport/fetch-with-retry.js +0 -146
  34. package/dist/cjs/transport/http-client.js +0 -56
  35. package/dist/cjs/transport/http-dispatcher.js +0 -190
  36. package/dist/cjs/types/api-version.js +0 -8
  37. package/dist/cjs/types/entities.js +0 -496
  38. package/dist/cjs/types/enums.js +0 -37
  39. package/dist/cjs/types/errors.js +0 -12
  40. package/dist/cjs/types/http.js +0 -4
  41. package/dist/cjs/types/index.js +0 -22
  42. package/dist/cjs/types/requests.js +0 -183
  43. package/dist/cjs/utils/case-conversion.js +0 -54
  44. package/dist/cjs/utils/index.js +0 -19
  45. package/dist/cjs/utils/multipart-upload.js +0 -144
  46. package/dist/cjs/utils/timestamp-conversion.js +0 -58
  47. package/dist/cjs/utils/url-helpers.js +0 -133
  48. package/dist/cjs/utils/uuidv7.js +0 -182
@@ -1,364 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ThreadsClient = exports.ThreadListSchema = 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 add_comment_helper_1 = require("./add-comment-helper");
10
- const base_client_1 = require("./base-client");
11
- const notify_audience_1 = require("./notify-audience");
12
- exports.ThreadListSchema = zod_1.z.array(entities_1.ThreadSchema);
13
- const GetUnreadResponseSchema = zod_1.z.object({
14
- data: zod_1.z.array(entities_1.UnreadThreadSchema),
15
- version: zod_1.z.number().int(),
16
- inboxUnread: zod_1.z.number().int().nullable().optional(),
17
- });
18
- /**
19
- * Client for `/api/v1/threads/`. The SDK auto-generates the thread `id` on
20
- * `createThread` when the caller doesn't supply one.
21
- */
22
- class ThreadsClient extends base_client_1.BaseClient {
23
- constructor() {
24
- super(...arguments);
25
- this.linkBaseUrl = this.getLinkBaseUrl();
26
- // Reuse the shared singletons when no custom base is configured.
27
- this.threadSchema = this.linkBaseUrl
28
- ? (0, entities_1.createThreadSchema)(this.linkBaseUrl)
29
- : entities_1.ThreadSchema;
30
- this.threadListSchema = this.linkBaseUrl
31
- ? zod_1.z.array(this.threadSchema)
32
- : exports.ThreadListSchema;
33
- this.commentSchema = this.linkBaseUrl
34
- ? (0, entities_1.createCommentSchema)(this.linkBaseUrl)
35
- : entities_1.CommentSchema;
36
- }
37
- /**
38
- * Gets threads. At least one of `channelId` / `workspaceId` is required.
39
- * `newerThan` / `olderThan` (`Date`) are converted to the
40
- * `newer_than_ts` / `older_than_ts` epoch-second params on the wire.
41
- *
42
- * @param args - The arguments for getting threads.
43
- * @param args.workspaceId - The workspace ID.
44
- * @param args.channelId - Optional channel ID to narrow to a single channel.
45
- * @param args.archived - Optional flag to include archived threads.
46
- * @param args.newerThan - Optional date to get threads newer than.
47
- * @param args.olderThan - Optional date to get threads older than.
48
- * @param args.limit - Optional limit on number of threads returned.
49
- * @returns An array of thread objects.
50
- *
51
- * @example
52
- * ```typescript
53
- * const threads = await api.threads.getThreads({
54
- * workspaceId: 123,
55
- * channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44',
56
- * })
57
- * threads.forEach(t => console.log(t.title))
58
- * ```
59
- */
60
- getThreads(args) {
61
- const params = { workspaceId: args.workspaceId };
62
- if (args.channelId != null)
63
- params.channelId = args.channelId;
64
- if (args.archived != null)
65
- params.archived = args.archived;
66
- if (args.limit != null)
67
- params.limit = args.limit;
68
- if (args.newerThan)
69
- params.newer_than_ts = Math.floor(args.newerThan.getTime() / 1000);
70
- if (args.olderThan)
71
- params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
72
- return (0, http_client_1.request)({
73
- httpMethod: 'GET',
74
- baseUri: this.getBaseUri(),
75
- relativePath: `${endpoints_1.ENDPOINT_THREADS}/get`,
76
- apiToken: this.apiToken,
77
- payload: params,
78
- customFetch: this.customFetch,
79
- }).then((response) => this.threadListSchema.parse(response.data));
80
- }
81
- /**
82
- * Gets a single thread object by id.
83
- *
84
- * @param id - The thread ID.
85
- * @returns The thread object.
86
- */
87
- getThread(id) {
88
- return this.simple('GET', 'getone', { id }, this.threadSchema);
89
- }
90
- /**
91
- * Creates a new thread in a channel. `id` is auto-generated if not supplied.
92
- *
93
- * @param args - The arguments for creating a thread.
94
- * @param args.channelId - The channel ID.
95
- * @param args.title - Optional thread title.
96
- * @param args.content - The thread content.
97
- * @param args.recipients - Optional array of user IDs to notify.
98
- * @param args.groups - Optional array of custom group IDs to notify.
99
- * @param args.notifyAudience - Optional broader audience to notify in addition to
100
- * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
101
- * `'thread'` notifies everyone who has interacted with the thread — but a
102
- * brand-new thread has no interactions yet, so the backend discards
103
- * `'thread'` at create time. It is only meaningful on replies (`createComment`).
104
- * @param args.attachments - Optional array of {@link Attachment}s (from `attachments.upload`).
105
- * @returns The created thread object.
106
- *
107
- * @example
108
- * ```typescript
109
- * const thread = await api.threads.createThread({
110
- * channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44',
111
- * title: 'New Feature Discussion',
112
- * content: 'Let\'s discuss the new feature...',
113
- * notifyAudience: 'channel', // tag "Everyone in channel"
114
- * })
115
- * ```
116
- */
117
- createThread(args) {
118
- const normalized = (0, notify_audience_1.applyNotifyAudience)(args);
119
- return this.simple('POST', 'add', {
120
- ...normalized,
121
- id: (0, uuidv7_1.resolveCreateId)(normalized.id),
122
- channelId: (0, uuidv7_1.resolveReferenceId)(normalized.channelId, 'channelId'),
123
- }, this.threadSchema);
124
- }
125
- /**
126
- * Partial update of an existing thread.
127
- *
128
- * @param args - The arguments for updating a thread.
129
- * @param args.id - The thread ID.
130
- * @param args.title - Optional new thread title.
131
- * @param args.content - Optional new thread content.
132
- * @returns The updated thread object.
133
- */
134
- updateThread(args) {
135
- return this.simple('POST', 'update', { ...args }, this.threadSchema);
136
- }
137
- /**
138
- * Permanently deletes a thread.
139
- *
140
- * @param id - The thread ID.
141
- */
142
- deleteThread(id) {
143
- return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
144
- }
145
- /**
146
- * Saves a thread (formerly "star").
147
- *
148
- * @param id - The thread ID.
149
- */
150
- saveThread(id) {
151
- return this.simple('GET', 'save', { id }, entities_1.StatusOkSchema);
152
- }
153
- /**
154
- * Unsaves a thread (formerly "unstar").
155
- *
156
- * @param id - The thread ID.
157
- */
158
- unsaveThread(id) {
159
- return this.simple('GET', 'unsave', { id }, entities_1.StatusOkSchema);
160
- }
161
- /**
162
- * Pins a thread.
163
- *
164
- * @param id - The thread ID.
165
- */
166
- pinThread(id) {
167
- return this.simple('GET', 'pin', { id }, entities_1.StatusOkSchema);
168
- }
169
- /**
170
- * Unpins a thread.
171
- *
172
- * @param id - The thread ID.
173
- */
174
- unpinThread(id) {
175
- return this.simple('GET', 'unpin', { id }, entities_1.StatusOkSchema);
176
- }
177
- /**
178
- * Moves a thread to another channel.
179
- *
180
- * @param args - The arguments for moving a thread.
181
- * @param args.id - The thread ID.
182
- * @param args.toChannel - The target channel ID.
183
- * @returns The updated thread object.
184
- */
185
- moveToChannel(args) {
186
- return this.simple('GET', 'move_to_channel', { ...args }, this.threadSchema);
187
- }
188
- /**
189
- * Marks a thread as read.
190
- *
191
- * @param args - The arguments for marking a thread as read.
192
- * @param args.id - The thread ID.
193
- * @param args.objIndex - The index of the last known read message.
194
- */
195
- markRead(args) {
196
- const { id, ...rest } = args;
197
- return this.simple('POST', 'mark_read', { threadId: id, ...rest }, entities_1.StatusOkSchema);
198
- }
199
- /**
200
- * Marks a thread as unread.
201
- *
202
- * @param args - The arguments for marking a thread as unread.
203
- * @param args.id - The thread ID.
204
- * @param args.objIndex - The index of the last unread message. Use -1 to mark the whole thread as unread.
205
- */
206
- markUnread(args) {
207
- const { id, ...rest } = args;
208
- return this.simple('POST', 'mark_unread', { threadId: id, ...rest }, entities_1.StatusOkSchema);
209
- }
210
- /**
211
- * Marks a thread as unread for others. Useful to notify others about thread changes.
212
- *
213
- * @param args - The arguments for marking a thread as unread for others.
214
- * @param args.id - The thread ID.
215
- * @param args.objIndex - The index of the last unread message. Use -1 to mark the whole thread as unread.
216
- */
217
- markUnreadForOthers(args) {
218
- return this.simple('POST', 'mark_unread_for_others', { ...args }, entities_1.StatusOkSchema);
219
- }
220
- /**
221
- * Marks every thread in a workspace or channel as read. Exactly one of
222
- * `workspaceId` / `channelId` should be set.
223
- *
224
- * @param args - Either workspaceId or channelId (one is required).
225
- * @param args.workspaceId - The workspace ID.
226
- * @param args.channelId - The channel ID.
227
- *
228
- * @example
229
- * ```typescript
230
- * // Mark all in workspace
231
- * await api.threads.markAllRead({ workspaceId: 123 })
232
- *
233
- * // Mark all in channel
234
- * await api.threads.markAllRead({ channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44' })
235
- * ```
236
- */
237
- markAllRead(args) {
238
- if (!args.workspaceId && !args.channelId) {
239
- throw new Error('Either workspaceId or channelId is required');
240
- }
241
- return this.simple('POST', 'mark_all_read', { ...args }, entities_1.StatusOkSchema);
242
- }
243
- /**
244
- * Clears unread threads in a workspace.
245
- *
246
- * @param workspaceId - The workspace ID.
247
- */
248
- clearUnread(workspaceId) {
249
- return this.simple('GET', 'clear_unread', { workspaceId }, entities_1.StatusOkSchema);
250
- }
251
- /**
252
- * Returns unread threads for a workspace, paired with the unread version
253
- * counter and (optionally) the inbox unread count.
254
- *
255
- * @param workspaceId - The workspace ID.
256
- * @returns Object containing the array of unread thread references, a version counter, and optionally the inbox unread count.
257
- */
258
- getUnread(workspaceId) {
259
- return this.simple('GET', 'get_unread', { workspaceId }, GetUnreadResponseSchema);
260
- }
261
- /**
262
- * Mutes a thread for a specified number of minutes.
263
- * When muted, you will not get notified in your inbox about new comments.
264
- *
265
- * @param args - The arguments for muting a thread.
266
- * @param args.id - The thread ID.
267
- * @param args.minutes - Number of minutes to mute the thread.
268
- * @returns The updated thread object.
269
- *
270
- * @example
271
- * ```typescript
272
- * const thread = await api.threads.muteThread({ id: '7YpL3oZ4kZ9vP7Q1tR2sX3z', minutes: 30 })
273
- * ```
274
- */
275
- muteThread(args) {
276
- return this.simple('GET', 'mute', { ...args }, this.threadSchema);
277
- }
278
- /**
279
- * Unmutes a thread.
280
- * You will start to see notifications in your inbox again when new comments are added.
281
- *
282
- * @param id - The thread ID.
283
- * @returns The updated thread object.
284
- */
285
- unmuteThread(id) {
286
- return this.simple('GET', 'unmute', { id }, this.threadSchema);
287
- }
288
- /**
289
- * Closes a thread by adding a comment with a close action.
290
- *
291
- * @param args - The arguments for closing a thread.
292
- * @param args.id - The thread ID.
293
- * @param args.content - The comment content.
294
- * @param args.attachments - Optional array of {@link Attachment} objects.
295
- * @param args.actions - Optional array of action objects.
296
- * @param args.recipients - Optional array of user IDs to notify directly.
297
- * @param args.groups - Optional array of custom group IDs to notify.
298
- * @param args.directMentions - Optional array of user IDs that were @-mentioned in
299
- * `content`.
300
- * @param args.notifyAudience - Optional broader audience to notify in addition to
301
- * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
302
- * `'thread'` notifies everyone who has interacted with the thread.
303
- * @returns The created comment object.
304
- *
305
- * @example
306
- * ```typescript
307
- * const comment = await api.threads.closeThread({
308
- * id: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
309
- * content: 'Closing this thread — resolved.',
310
- * })
311
- * ```
312
- */
313
- closeThread(args) {
314
- return this.addCommentWithAction(args, 'close');
315
- }
316
- /**
317
- * Reopens a thread by adding a comment with a reopen action.
318
- *
319
- * @param args - The arguments for reopening a thread.
320
- * @param args.id - The thread ID.
321
- * @param args.content - The comment content.
322
- * @param args.attachments - Optional array of {@link Attachment} objects.
323
- * @param args.actions - Optional array of action objects.
324
- * @param args.recipients - Optional array of user IDs to notify directly.
325
- * @param args.groups - Optional array of custom group IDs to notify.
326
- * @param args.directMentions - Optional array of user IDs that were @-mentioned in
327
- * `content`.
328
- * @param args.notifyAudience - Optional broader audience to notify in addition to
329
- * `recipients` and `groups`. `'channel'` notifies everyone in the channel;
330
- * `'thread'` notifies everyone who has interacted with the thread.
331
- * @returns The created comment object.
332
- *
333
- * @example
334
- * ```typescript
335
- * const comment = await api.threads.reopenThread({
336
- * id: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
337
- * content: 'Reopening — need further discussion.',
338
- * })
339
- * ```
340
- */
341
- reopenThread(args) {
342
- return this.addCommentWithAction(args, 'reopen');
343
- }
344
- addCommentWithAction(args, threadAction) {
345
- const { id, ...rest } = args;
346
- return (0, add_comment_helper_1.addCommentRequest)({
347
- baseUri: this.getBaseUri(),
348
- apiToken: this.apiToken,
349
- customFetch: this.customFetch,
350
- schema: this.commentSchema,
351
- }, { threadId: (0, uuidv7_1.resolveReferenceId)(id, 'id'), ...rest }, { threadAction });
352
- }
353
- simple(httpMethod, suffix, params, schema) {
354
- return (0, http_client_1.request)({
355
- httpMethod,
356
- baseUri: this.getBaseUri(),
357
- relativePath: `${endpoints_1.ENDPOINT_THREADS}/${suffix}`,
358
- apiToken: this.apiToken,
359
- payload: params,
360
- customFetch: this.customFetch,
361
- }).then((response) => schema.parse(response.data));
362
- }
363
- }
364
- exports.ThreadsClient = ThreadsClient;
@@ -1,326 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UsersClient = void 0;
4
- const endpoints_1 = require("../consts/endpoints");
5
- const http_client_1 = require("../transport/http-client");
6
- const entities_1 = require("../types/entities");
7
- const base_client_1 = require("./base-client");
8
- /**
9
- * Client for the `/api/v1/users/` endpoints. Authentication flows through
10
- * Todoist-ID; `register` / `login` / `loginWithGoogle` / `loginWithToken` /
11
- * `loginWithTodoist` are the available entry points.
12
- */
13
- class UsersClient extends base_client_1.BaseClient {
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
- */
25
- register(args) {
26
- return this.post(`${endpoints_1.ENDPOINT_USERS}/register`, args, entities_1.UserSchema, { authed: false });
27
- }
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
- */
45
- login(args) {
46
- return this.post(`${endpoints_1.ENDPOINT_USERS}/login`, args, entities_1.UserSchema, { authed: false });
47
- }
48
- /**
49
- * Logs in using a valid token (sent via Authorization header). The SDK
50
- * client is already configured with the token, so no args are needed.
51
- *
52
- * @returns The authenticated user object.
53
- */
54
- loginWithToken() {
55
- return this.post(`${endpoints_1.ENDPOINT_USERS}/login_with_token`, undefined, entities_1.UserSchema);
56
- }
57
- /**
58
- * Exchanges the browser's Todoist web-session cookie for a Comms session.
59
- * Only useful when running in a browser context on the shared Todoist
60
- * registrable domain — the cookie is sent automatically by the browser.
61
- *
62
- * @returns The authenticated user object.
63
- */
64
- loginWithTodoist() {
65
- return this.post(`${endpoints_1.ENDPOINT_USERS}/login_with_todoist`, {}, entities_1.UserSchema, { authed: false });
66
- }
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
- */
78
- loginWithGoogle(args) {
79
- return this.post(`${endpoints_1.ENDPOINT_USERS}/login_with_google`, args, entities_1.UserSchema, { authed: false });
80
- }
81
- /**
82
- * Completes an MFA challenge issued by `loginWithGoogle` (returns an MFA
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`.
90
- */
91
- mfaChallenge(args) {
92
- return (0, http_client_1.request)({
93
- httpMethod: 'POST',
94
- baseUri: this.getBaseUri(),
95
- relativePath: `${endpoints_1.ENDPOINT_USERS}/mfa/challenge`,
96
- apiToken: undefined,
97
- payload: args,
98
- customFetch: this.customFetch,
99
- }).then((response) => response.data);
100
- }
101
- /** Logs out the current user and clears the session cookie. */
102
- logout() {
103
- return (0, http_client_1.request)({
104
- httpMethod: 'POST',
105
- baseUri: this.getBaseUri(),
106
- relativePath: `${endpoints_1.ENDPOINT_USERS}/logout`,
107
- apiToken: this.apiToken,
108
- payload: undefined,
109
- customFetch: this.customFetch,
110
- }).then(() => undefined);
111
- }
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
- */
123
- getSessionUser() {
124
- return this.get(`${endpoints_1.ENDPOINT_USERS}/get_session_user`, undefined, entities_1.UserSchema);
125
- }
126
- /**
127
- * Fetches a single user. Defaults to the session user when no `id` is
128
- * passed. Cross-workspace lookups require that the caller and the target
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.
136
- */
137
- getUser(args) {
138
- return this.get(`${endpoints_1.ENDPOINT_USERS}/getone`, args ?? {}, entities_1.UserSchema);
139
- }
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
- */
146
- getUserByEmail(email) {
147
- return this.get(`${endpoints_1.ENDPOINT_USERS}/get_by_email`, { email }, entities_1.UserSchema);
148
- }
149
- /**
150
- * Updates the logged-in user's profile. Most fields are proxied to
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
- * ```
163
- */
164
- update(args) {
165
- return this.post(`${endpoints_1.ENDPOINT_USERS}/update`, args, entities_1.UserSchema);
166
- }
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
- */
176
- updatePassword(args) {
177
- return this.post(`${endpoints_1.ENDPOINT_USERS}/update_password`, args, entities_1.UserSchema);
178
- }
179
- /**
180
- * Removes the user's avatar.
181
- *
182
- * @returns The updated user object.
183
- */
184
- removeAvatar() {
185
- return this.post(`${endpoints_1.ENDPOINT_USERS}/remove_avatar`, undefined, entities_1.UserSchema);
186
- }
187
- /**
188
- * Invalidates the current API token and returns the user with a fresh
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
- * ```
198
- */
199
- invalidateToken() {
200
- return this.post(`${endpoints_1.ENDPOINT_USERS}/invalidate_token`, undefined, entities_1.UserSchema);
201
- }
202
- /**
203
- * Validates that an arbitrary token is still active. Note this is sent
204
- * as a GET — the token is read from the query string, not the
205
- * Authorization header.
206
- *
207
- * @param token - The token to validate.
208
- */
209
- validateToken(token) {
210
- return (0, http_client_1.request)({
211
- httpMethod: 'GET',
212
- baseUri: this.getBaseUri(),
213
- relativePath: `${endpoints_1.ENDPOINT_USERS}/validate_token`,
214
- apiToken: undefined,
215
- payload: { token },
216
- customFetch: this.customFetch,
217
- }).then(() => undefined);
218
- }
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
- */
231
- heartbeat(args) {
232
- return (0, http_client_1.request)({
233
- httpMethod: 'GET',
234
- baseUri: this.getBaseUri(),
235
- relativePath: `${endpoints_1.ENDPOINT_USERS}/heartbeat`,
236
- apiToken: this.apiToken,
237
- payload: args,
238
- customFetch: this.customFetch,
239
- }).then(() => undefined);
240
- }
241
- /**
242
- * Resets the user's presence for a workspace (marks the user as inactive).
243
- *
244
- * @param workspaceId - The workspace ID.
245
- */
246
- resetPresence(workspaceId) {
247
- return (0, http_client_1.request)({
248
- httpMethod: 'POST',
249
- baseUri: this.getBaseUri(),
250
- relativePath: `${endpoints_1.ENDPOINT_USERS}/reset_presence`,
251
- apiToken: this.apiToken,
252
- payload: { workspaceId },
253
- customFetch: this.customFetch,
254
- }).then(() => undefined);
255
- }
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
- */
262
- checkEmail(email) {
263
- return (0, http_client_1.request)({
264
- httpMethod: 'POST',
265
- baseUri: this.getBaseUri(),
266
- relativePath: `${endpoints_1.ENDPOINT_USERS}/check_email`,
267
- apiToken: undefined,
268
- payload: { email },
269
- customFetch: this.customFetch,
270
- }).then((response) => response.data);
271
- }
272
- /**
273
- * Returns the current per-channel mail unsubscribe settings for the
274
- * caller's primary email.
275
- *
276
- * @returns Object mapping email-type keys to their opt-out flag.
277
- */
278
- getUnsubscribeSettings() {
279
- return (0, http_client_1.request)({
280
- httpMethod: 'GET',
281
- baseUri: this.getBaseUri(),
282
- relativePath: `${endpoints_1.ENDPOINT_USERS}/get_unsubscribe_settings`,
283
- apiToken: this.apiToken,
284
- payload: undefined,
285
- customFetch: this.customFetch,
286
- }).then((response) => response.data);
287
- }
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
- */
294
- updateUnsubscribeSettings(settings) {
295
- return (0, http_client_1.request)({
296
- httpMethod: 'POST',
297
- baseUri: this.getBaseUri(),
298
- relativePath: `${endpoints_1.ENDPOINT_USERS}/update_unsubscribe_settings`,
299
- apiToken: this.apiToken,
300
- payload: settings,
301
- customFetch: this.customFetch,
302
- }).then((response) => response.data);
303
- }
304
- get(url, params, schema) {
305
- return (0, http_client_1.request)({
306
- httpMethod: 'GET',
307
- baseUri: this.getBaseUri(),
308
- relativePath: url,
309
- apiToken: this.apiToken,
310
- payload: params,
311
- customFetch: this.customFetch,
312
- }).then((response) => schema.parse(response.data));
313
- }
314
- post(url, params, schema, options = {}) {
315
- const authed = options.authed ?? true;
316
- return (0, http_client_1.request)({
317
- httpMethod: 'POST',
318
- baseUri: this.getBaseUri(),
319
- relativePath: url,
320
- apiToken: authed ? this.apiToken : undefined,
321
- payload: params,
322
- customFetch: this.customFetch,
323
- }).then((response) => schema.parse(response.data));
324
- }
325
- }
326
- exports.UsersClient = UsersClient;