@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.
- package/README.md +1 -1
- package/dist/cjs/clients/add-comment-helper.js +18 -2
- package/dist/cjs/clients/base-client.js +11 -5
- package/dist/cjs/clients/channels-client.js +142 -14
- package/dist/cjs/clients/comments-client.js +99 -14
- package/dist/cjs/clients/conversation-messages-client.js +91 -9
- package/dist/cjs/clients/conversations-client.js +166 -15
- package/dist/cjs/clients/groups-client.js +98 -5
- package/dist/cjs/clients/inbox-client.js +102 -16
- package/dist/cjs/clients/reactions-client.js +40 -2
- package/dist/cjs/clients/search-client.js +50 -0
- package/dist/cjs/clients/threads-client.js +238 -24
- package/dist/cjs/clients/users-client.js +138 -11
- package/dist/cjs/clients/workspace-users-client.js +110 -10
- package/dist/cjs/clients/workspaces-client.js +89 -8
- package/dist/cjs/comms-api.js +1 -0
- package/dist/cjs/consts/endpoints.js +8 -3
- package/dist/cjs/testUtils/test-defaults.js +3 -1
- package/dist/cjs/types/api-version.js +8 -0
- package/dist/cjs/types/entities.js +119 -98
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/types/requests.js +0 -1
- package/dist/cjs/utils/url-helpers.js +3 -1
- package/dist/esm/clients/add-comment-helper.js +18 -2
- package/dist/esm/clients/base-client.js +11 -5
- package/dist/esm/clients/channels-client.js +143 -15
- package/dist/esm/clients/comments-client.js +100 -15
- package/dist/esm/clients/conversation-messages-client.js +92 -10
- package/dist/esm/clients/conversations-client.js +167 -16
- package/dist/esm/clients/groups-client.js +98 -5
- package/dist/esm/clients/inbox-client.js +102 -16
- package/dist/esm/clients/reactions-client.js +40 -2
- package/dist/esm/clients/search-client.js +50 -0
- package/dist/esm/clients/threads-client.js +239 -25
- package/dist/esm/clients/users-client.js +138 -11
- package/dist/esm/clients/workspace-users-client.js +110 -10
- package/dist/esm/clients/workspaces-client.js +90 -9
- package/dist/esm/comms-api.js +1 -0
- package/dist/esm/consts/endpoints.js +8 -3
- package/dist/esm/testUtils/test-defaults.js +2 -0
- package/dist/esm/types/api-version.js +5 -0
- package/dist/esm/types/entities.js +111 -97
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/requests.js +0 -1
- package/dist/esm/utils/url-helpers.js +3 -1
- package/dist/types/clients/add-comment-helper.d.ts +20 -1
- package/dist/types/clients/base-client.d.ts +10 -0
- package/dist/types/clients/channels-client.d.ts +126 -6
- package/dist/types/clients/comments-client.d.ts +77 -6
- package/dist/types/clients/conversation-messages-client.d.ts +79 -5
- package/dist/types/clients/conversations-client.d.ts +146 -3
- package/dist/types/clients/groups-client.d.ts +98 -5
- package/dist/types/clients/inbox-client.d.ts +463 -5
- package/dist/types/clients/reactions-client.d.ts +40 -2
- package/dist/types/clients/search-client.d.ts +50 -0
- package/dist/types/clients/threads-client.d.ts +204 -8
- package/dist/types/clients/users-client.d.ts +138 -11
- package/dist/types/clients/workspace-users-client.d.ts +110 -10
- package/dist/types/clients/workspaces-client.d.ts +82 -7
- package/dist/types/comms-api.d.ts +3 -0
- package/dist/types/consts/endpoints.d.ts +6 -1
- package/dist/types/testUtils/test-defaults.d.ts +1 -0
- package/dist/types/types/api-version.d.ts +6 -0
- package/dist/types/types/entities.d.ts +1654 -126
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/requests.d.ts +2 -21
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ENDPOINT_THREADS } from '../consts/endpoints.js';
|
|
3
3
|
import { request } from '../transport/http-client.js';
|
|
4
|
-
import { StatusOkSchema, ThreadSchema, UnreadThreadSchema, } from '../types/entities.js';
|
|
4
|
+
import { CommentSchema, createCommentSchema, createThreadSchema, StatusOkSchema, ThreadSchema, UnreadThreadSchema, } from '../types/entities.js';
|
|
5
5
|
import { resolveCreateId } from '../utils/uuidv7.js';
|
|
6
6
|
import { addCommentRequest } from './add-comment-helper.js';
|
|
7
7
|
import { BaseClient } from './base-client.js';
|
|
@@ -16,20 +16,55 @@ const GetUnreadResponseSchema = z.object({
|
|
|
16
16
|
* `createThread` when the caller doesn't supply one.
|
|
17
17
|
*/
|
|
18
18
|
export class ThreadsClient extends BaseClient {
|
|
19
|
+
constructor() {
|
|
20
|
+
super(...arguments);
|
|
21
|
+
this.linkBaseUrl = this.getLinkBaseUrl();
|
|
22
|
+
// Reuse the shared singletons when no custom base is configured.
|
|
23
|
+
this.threadSchema = this.linkBaseUrl
|
|
24
|
+
? createThreadSchema(this.linkBaseUrl)
|
|
25
|
+
: ThreadSchema;
|
|
26
|
+
this.threadListSchema = this.linkBaseUrl
|
|
27
|
+
? z.array(this.threadSchema)
|
|
28
|
+
: ThreadListSchema;
|
|
29
|
+
this.commentSchema = this.linkBaseUrl
|
|
30
|
+
? createCommentSchema(this.linkBaseUrl)
|
|
31
|
+
: CommentSchema;
|
|
32
|
+
}
|
|
19
33
|
/**
|
|
20
|
-
*
|
|
34
|
+
* Gets threads. At least one of `channelId` / `workspaceId` is required.
|
|
21
35
|
* `newerThan` / `olderThan` (`Date`) are converted to the
|
|
22
36
|
* `newer_than_ts` / `older_than_ts` epoch-second params on the wire.
|
|
37
|
+
*
|
|
38
|
+
* @param args - The arguments for getting threads.
|
|
39
|
+
* @param args.workspaceId - The workspace ID.
|
|
40
|
+
* @param args.channelId - Optional channel ID to narrow to a single channel.
|
|
41
|
+
* @param args.archived - Optional flag to include archived threads.
|
|
42
|
+
* @param args.newerThan - Optional date to get threads newer than.
|
|
43
|
+
* @param args.olderThan - Optional date to get threads older than.
|
|
44
|
+
* @param args.limit - Optional limit on number of threads returned.
|
|
45
|
+
* @returns An array of thread objects.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const threads = await api.threads.getThreads({
|
|
50
|
+
* workspaceId: 123,
|
|
51
|
+
* channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44',
|
|
52
|
+
* })
|
|
53
|
+
* threads.forEach(t => console.log(t.title))
|
|
54
|
+
* ```
|
|
23
55
|
*/
|
|
24
56
|
getThreads(args) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
57
|
+
const params = { workspaceId: args.workspaceId };
|
|
58
|
+
if (args.channelId != null)
|
|
59
|
+
params.channelId = args.channelId;
|
|
60
|
+
if (args.archived != null)
|
|
61
|
+
params.archived = args.archived;
|
|
62
|
+
if (args.limit != null)
|
|
63
|
+
params.limit = args.limit;
|
|
64
|
+
if (args.newerThan)
|
|
65
|
+
params.newer_than_ts = Math.floor(args.newerThan.getTime() / 1000);
|
|
66
|
+
if (args.olderThan)
|
|
67
|
+
params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
|
|
33
68
|
return request({
|
|
34
69
|
httpMethod: 'GET',
|
|
35
70
|
baseUri: this.getBaseUri(),
|
|
@@ -37,54 +72,149 @@ export class ThreadsClient extends BaseClient {
|
|
|
37
72
|
apiToken: this.apiToken,
|
|
38
73
|
payload: params,
|
|
39
74
|
customFetch: this.customFetch,
|
|
40
|
-
}).then((response) =>
|
|
75
|
+
}).then((response) => this.threadListSchema.parse(response.data));
|
|
41
76
|
}
|
|
42
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* Gets a single thread object by id.
|
|
79
|
+
*
|
|
80
|
+
* @param id - The thread ID.
|
|
81
|
+
* @returns The thread object.
|
|
82
|
+
*/
|
|
43
83
|
getThread(id) {
|
|
44
|
-
return this.simple('GET', 'getone', { id },
|
|
84
|
+
return this.simple('GET', 'getone', { id }, this.threadSchema);
|
|
45
85
|
}
|
|
46
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new thread in a channel. `id` is auto-generated if not supplied.
|
|
88
|
+
*
|
|
89
|
+
* @param args - The arguments for creating a thread.
|
|
90
|
+
* @param args.channelId - The channel ID.
|
|
91
|
+
* @param args.title - Optional thread title.
|
|
92
|
+
* @param args.content - The thread content.
|
|
93
|
+
* @param args.recipients - Optional array of user IDs to notify.
|
|
94
|
+
* @param args.groups - Optional array of custom group IDs to notify.
|
|
95
|
+
* @returns The created thread object.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const thread = await api.threads.createThread({
|
|
100
|
+
* channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44',
|
|
101
|
+
* title: 'New Feature Discussion',
|
|
102
|
+
* content: 'Let\'s discuss the new feature...',
|
|
103
|
+
* })
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
47
106
|
createThread(args) {
|
|
48
|
-
return this.simple('POST', 'add', { ...args, id: resolveCreateId(args.id) },
|
|
107
|
+
return this.simple('POST', 'add', { ...args, id: resolveCreateId(args.id) }, this.threadSchema);
|
|
49
108
|
}
|
|
50
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* Partial update of an existing thread.
|
|
111
|
+
*
|
|
112
|
+
* @param args - The arguments for updating a thread.
|
|
113
|
+
* @param args.id - The thread ID.
|
|
114
|
+
* @param args.title - Optional new thread title.
|
|
115
|
+
* @param args.content - Optional new thread content.
|
|
116
|
+
* @returns The updated thread object.
|
|
117
|
+
*/
|
|
51
118
|
updateThread(args) {
|
|
52
|
-
return this.simple('POST', 'update', { ...args },
|
|
119
|
+
return this.simple('POST', 'update', { ...args }, this.threadSchema);
|
|
53
120
|
}
|
|
54
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Permanently deletes a thread.
|
|
123
|
+
*
|
|
124
|
+
* @param id - The thread ID.
|
|
125
|
+
*/
|
|
55
126
|
deleteThread(id) {
|
|
56
127
|
return this.simple('POST', 'remove', { id }, StatusOkSchema);
|
|
57
128
|
}
|
|
58
|
-
/**
|
|
129
|
+
/**
|
|
130
|
+
* Saves a thread (formerly "star").
|
|
131
|
+
*
|
|
132
|
+
* @param id - The thread ID.
|
|
133
|
+
*/
|
|
59
134
|
saveThread(id) {
|
|
60
135
|
return this.simple('GET', 'save', { id }, StatusOkSchema);
|
|
61
136
|
}
|
|
62
|
-
/**
|
|
137
|
+
/**
|
|
138
|
+
* Unsaves a thread (formerly "unstar").
|
|
139
|
+
*
|
|
140
|
+
* @param id - The thread ID.
|
|
141
|
+
*/
|
|
63
142
|
unsaveThread(id) {
|
|
64
143
|
return this.simple('GET', 'unsave', { id }, StatusOkSchema);
|
|
65
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Pins a thread.
|
|
147
|
+
*
|
|
148
|
+
* @param id - The thread ID.
|
|
149
|
+
*/
|
|
66
150
|
pinThread(id) {
|
|
67
151
|
return this.simple('GET', 'pin', { id }, StatusOkSchema);
|
|
68
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Unpins a thread.
|
|
155
|
+
*
|
|
156
|
+
* @param id - The thread ID.
|
|
157
|
+
*/
|
|
69
158
|
unpinThread(id) {
|
|
70
159
|
return this.simple('GET', 'unpin', { id }, StatusOkSchema);
|
|
71
160
|
}
|
|
72
|
-
/**
|
|
161
|
+
/**
|
|
162
|
+
* Moves a thread to another channel.
|
|
163
|
+
*
|
|
164
|
+
* @param args - The arguments for moving a thread.
|
|
165
|
+
* @param args.id - The thread ID.
|
|
166
|
+
* @param args.toChannel - The target channel ID.
|
|
167
|
+
* @returns The updated thread object.
|
|
168
|
+
*/
|
|
73
169
|
moveToChannel(args) {
|
|
74
|
-
return this.simple('GET', 'move_to_channel', { ...args },
|
|
170
|
+
return this.simple('GET', 'move_to_channel', { ...args }, this.threadSchema);
|
|
75
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Marks a thread as read.
|
|
174
|
+
*
|
|
175
|
+
* @param args - The arguments for marking a thread as read.
|
|
176
|
+
* @param args.id - The thread ID.
|
|
177
|
+
* @param args.objIndex - The index of the last known read message.
|
|
178
|
+
*/
|
|
76
179
|
markRead(args) {
|
|
77
180
|
return this.simple('POST', 'mark_read', { ...args }, StatusOkSchema);
|
|
78
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Marks a thread as unread.
|
|
184
|
+
*
|
|
185
|
+
* @param args - The arguments for marking a thread as unread.
|
|
186
|
+
* @param args.id - The thread ID.
|
|
187
|
+
* @param args.objIndex - The index of the last unread message. Use -1 to mark the whole thread as unread.
|
|
188
|
+
*/
|
|
79
189
|
markUnread(args) {
|
|
80
190
|
return this.simple('POST', 'mark_unread', { ...args }, StatusOkSchema);
|
|
81
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Marks a thread as unread for others. Useful to notify others about thread changes.
|
|
194
|
+
*
|
|
195
|
+
* @param args - The arguments for marking a thread as unread for others.
|
|
196
|
+
* @param args.id - The thread ID.
|
|
197
|
+
* @param args.objIndex - The index of the last unread message. Use -1 to mark the whole thread as unread.
|
|
198
|
+
*/
|
|
82
199
|
markUnreadForOthers(args) {
|
|
83
200
|
return this.simple('POST', 'mark_unread_for_others', { ...args }, StatusOkSchema);
|
|
84
201
|
}
|
|
85
202
|
/**
|
|
86
203
|
* Marks every thread in a workspace or channel as read. Exactly one of
|
|
87
204
|
* `workspaceId` / `channelId` should be set.
|
|
205
|
+
*
|
|
206
|
+
* @param args - Either workspaceId or channelId (one is required).
|
|
207
|
+
* @param args.workspaceId - The workspace ID.
|
|
208
|
+
* @param args.channelId - The channel ID.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```typescript
|
|
212
|
+
* // Mark all in workspace
|
|
213
|
+
* await api.threads.markAllRead({ workspaceId: 123 })
|
|
214
|
+
*
|
|
215
|
+
* // Mark all in channel
|
|
216
|
+
* await api.threads.markAllRead({ channelId: '7YpL3oZ4kZ9vP7Q1tR2sX44' })
|
|
217
|
+
* ```
|
|
88
218
|
*/
|
|
89
219
|
markAllRead(args) {
|
|
90
220
|
if (!args.workspaceId && !args.channelId) {
|
|
@@ -92,31 +222,115 @@ export class ThreadsClient extends BaseClient {
|
|
|
92
222
|
}
|
|
93
223
|
return this.simple('POST', 'mark_all_read', { ...args }, StatusOkSchema);
|
|
94
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Clears unread threads in a workspace.
|
|
227
|
+
*
|
|
228
|
+
* @param workspaceId - The workspace ID.
|
|
229
|
+
*/
|
|
95
230
|
clearUnread(workspaceId) {
|
|
96
231
|
return this.simple('GET', 'clear_unread', { workspaceId }, StatusOkSchema);
|
|
97
232
|
}
|
|
98
233
|
/**
|
|
99
234
|
* Returns unread threads for a workspace, paired with the unread version
|
|
100
235
|
* counter and (optionally) the inbox unread count.
|
|
236
|
+
*
|
|
237
|
+
* @param workspaceId - The workspace ID.
|
|
238
|
+
* @returns Object containing the array of unread thread references, a version counter, and optionally the inbox unread count.
|
|
101
239
|
*/
|
|
102
240
|
getUnread(workspaceId) {
|
|
103
241
|
return this.simple('GET', 'get_unread', { workspaceId }, GetUnreadResponseSchema);
|
|
104
242
|
}
|
|
243
|
+
/**
|
|
244
|
+
* Mutes a thread for a specified number of minutes.
|
|
245
|
+
* When muted, you will not get notified in your inbox about new comments.
|
|
246
|
+
*
|
|
247
|
+
* @param args - The arguments for muting a thread.
|
|
248
|
+
* @param args.id - The thread ID.
|
|
249
|
+
* @param args.minutes - Number of minutes to mute the thread.
|
|
250
|
+
* @returns The updated thread object.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* const thread = await api.threads.muteThread({ id: '7YpL3oZ4kZ9vP7Q1tR2sX3z', minutes: 30 })
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
105
257
|
muteThread(args) {
|
|
106
|
-
return this.simple('GET', 'mute', { ...args },
|
|
258
|
+
return this.simple('GET', 'mute', { ...args }, this.threadSchema);
|
|
107
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* Unmutes a thread.
|
|
262
|
+
* You will start to see notifications in your inbox again when new comments are added.
|
|
263
|
+
*
|
|
264
|
+
* @param id - The thread ID.
|
|
265
|
+
* @returns The updated thread object.
|
|
266
|
+
*/
|
|
108
267
|
unmuteThread(id) {
|
|
109
|
-
return this.simple('GET', 'unmute', { id },
|
|
268
|
+
return this.simple('GET', 'unmute', { id }, this.threadSchema);
|
|
110
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Closes a thread by adding a comment with a close action.
|
|
272
|
+
*
|
|
273
|
+
* @param args - The arguments for closing a thread.
|
|
274
|
+
* @param args.id - The thread ID.
|
|
275
|
+
* @param args.content - The comment content.
|
|
276
|
+
* @param args.attachments - Optional array of {@link Attachment} objects.
|
|
277
|
+
* @param args.actions - Optional array of action objects.
|
|
278
|
+
* @param args.recipients - Optional array of user IDs to notify directly.
|
|
279
|
+
* @param args.groups - Optional array of custom group IDs to notify.
|
|
280
|
+
* @param args.directMentions - Optional array of user IDs that were @-mentioned in
|
|
281
|
+
* `content`.
|
|
282
|
+
* @param args.notifyAudience - Optional broader audience to notify in addition to
|
|
283
|
+
* `recipients` and `groups`. `'channel'` notifies everyone in the channel;
|
|
284
|
+
* `'thread'` notifies everyone who has interacted with the thread.
|
|
285
|
+
* @returns The created comment object.
|
|
286
|
+
*
|
|
287
|
+
* @example
|
|
288
|
+
* ```typescript
|
|
289
|
+
* const comment = await api.threads.closeThread({
|
|
290
|
+
* id: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
|
|
291
|
+
* content: 'Closing this thread — resolved.',
|
|
292
|
+
* })
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
111
295
|
closeThread(args) {
|
|
112
296
|
return this.addCommentWithAction(args, 'close');
|
|
113
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* Reopens a thread by adding a comment with a reopen action.
|
|
300
|
+
*
|
|
301
|
+
* @param args - The arguments for reopening a thread.
|
|
302
|
+
* @param args.id - The thread ID.
|
|
303
|
+
* @param args.content - The comment content.
|
|
304
|
+
* @param args.attachments - Optional array of {@link Attachment} objects.
|
|
305
|
+
* @param args.actions - Optional array of action objects.
|
|
306
|
+
* @param args.recipients - Optional array of user IDs to notify directly.
|
|
307
|
+
* @param args.groups - Optional array of custom group IDs to notify.
|
|
308
|
+
* @param args.directMentions - Optional array of user IDs that were @-mentioned in
|
|
309
|
+
* `content`.
|
|
310
|
+
* @param args.notifyAudience - Optional broader audience to notify in addition to
|
|
311
|
+
* `recipients` and `groups`. `'channel'` notifies everyone in the channel;
|
|
312
|
+
* `'thread'` notifies everyone who has interacted with the thread.
|
|
313
|
+
* @returns The created comment object.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* const comment = await api.threads.reopenThread({
|
|
318
|
+
* id: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
|
|
319
|
+
* content: 'Reopening — need further discussion.',
|
|
320
|
+
* })
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
114
323
|
reopenThread(args) {
|
|
115
324
|
return this.addCommentWithAction(args, 'reopen');
|
|
116
325
|
}
|
|
117
326
|
addCommentWithAction(args, threadAction) {
|
|
118
327
|
const { id, ...rest } = args;
|
|
119
|
-
return addCommentRequest({
|
|
328
|
+
return addCommentRequest({
|
|
329
|
+
baseUri: this.getBaseUri(),
|
|
330
|
+
apiToken: this.apiToken,
|
|
331
|
+
customFetch: this.customFetch,
|
|
332
|
+
schema: this.commentSchema,
|
|
333
|
+
}, { threadId: id, ...rest }, { threadAction });
|
|
120
334
|
}
|
|
121
335
|
simple(httpMethod, suffix, params, schema) {
|
|
122
336
|
return request({
|
|
@@ -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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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',
|