@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.
- package/dist/esm/utils/multipart-upload.js +73 -15
- package/dist/esm/utils/url-helpers.js +104 -16
- package/dist/types/utils/multipart-upload.d.ts +3 -4
- package/dist/types/utils/url-helpers.d.ts +41 -0
- package/package.json +5 -10
- package/dist/cjs/authentication.js +0 -256
- package/dist/cjs/clients/add-comment-helper.js +0 -43
- package/dist/cjs/clients/attachments-client.js +0 -71
- package/dist/cjs/clients/base-client.js +0 -33
- package/dist/cjs/clients/channels-client.js +0 -211
- package/dist/cjs/clients/comments-client.js +0 -175
- package/dist/cjs/clients/conversation-messages-client.js +0 -169
- package/dist/cjs/clients/conversations-client.js +0 -283
- package/dist/cjs/clients/groups-client.js +0 -172
- package/dist/cjs/clients/hooks-client.js +0 -52
- package/dist/cjs/clients/inbox-client.js +0 -184
- package/dist/cjs/clients/notify-audience.js +0 -45
- package/dist/cjs/clients/reactions-client.js +0 -97
- package/dist/cjs/clients/search-client.js +0 -138
- package/dist/cjs/clients/threads-client.js +0 -364
- package/dist/cjs/clients/users-client.js +0 -326
- package/dist/cjs/clients/workspace-users-client.js +0 -252
- package/dist/cjs/clients/workspaces-client.js +0 -174
- package/dist/cjs/comms-api.js +0 -70
- package/dist/cjs/consts/endpoints.js +0 -34
- package/dist/cjs/index.js +0 -53
- package/dist/cjs/migration.js +0 -96
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/testUtils/msw-handlers.js +0 -51
- package/dist/cjs/testUtils/msw-setup.js +0 -35
- package/dist/cjs/testUtils/obsidian-fetch-adapter.js +0 -53
- package/dist/cjs/testUtils/test-defaults.js +0 -106
- package/dist/cjs/transport/fetch-with-retry.js +0 -146
- package/dist/cjs/transport/http-client.js +0 -56
- package/dist/cjs/transport/http-dispatcher.js +0 -190
- package/dist/cjs/types/api-version.js +0 -8
- package/dist/cjs/types/entities.js +0 -496
- package/dist/cjs/types/enums.js +0 -37
- package/dist/cjs/types/errors.js +0 -12
- package/dist/cjs/types/http.js +0 -4
- package/dist/cjs/types/index.js +0 -22
- package/dist/cjs/types/requests.js +0 -183
- package/dist/cjs/utils/case-conversion.js +0 -54
- package/dist/cjs/utils/index.js +0 -19
- package/dist/cjs/utils/multipart-upload.js +0 -144
- package/dist/cjs/utils/timestamp-conversion.js +0 -58
- package/dist/cjs/utils/url-helpers.js +0 -133
- package/dist/cjs/utils/uuidv7.js +0 -182
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConversationMessagesClient = exports.ConversationMessageListSchema = 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 base_client_1 = require("./base-client");
|
|
10
|
-
exports.ConversationMessageListSchema = zod_1.z.array(entities_1.ConversationMessageSchema);
|
|
11
|
-
/**
|
|
12
|
-
* Client for `/api/v1/conversation_messages/`. The SDK auto-generates the
|
|
13
|
-
* message `id` on `createMessage` when the caller doesn't supply one.
|
|
14
|
-
*/
|
|
15
|
-
class ConversationMessagesClient extends base_client_1.BaseClient {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
this.linkBaseUrl = this.getLinkBaseUrl();
|
|
19
|
-
// Reuse the shared singletons when no custom base is configured.
|
|
20
|
-
this.messageSchema = this.linkBaseUrl
|
|
21
|
-
? (0, entities_1.createConversationMessageSchema)(this.linkBaseUrl)
|
|
22
|
-
: entities_1.ConversationMessageSchema;
|
|
23
|
-
this.messageListSchema = this.linkBaseUrl
|
|
24
|
-
? zod_1.z.array(this.messageSchema)
|
|
25
|
-
: exports.ConversationMessageListSchema;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Gets all messages in a conversation.
|
|
29
|
-
*
|
|
30
|
-
* @param args - The arguments for getting messages.
|
|
31
|
-
* @param args.conversationId - The conversation ID.
|
|
32
|
-
* @param args.newerThan - Optional date to get messages newer than.
|
|
33
|
-
* @param args.olderThan - Optional date to get messages older than.
|
|
34
|
-
* @param args.limit - Optional limit on number of messages returned.
|
|
35
|
-
* @param args.cursor - Optional cursor for pagination.
|
|
36
|
-
* @returns An array of message objects.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* const messages = await api.conversationMessages.getMessages({
|
|
41
|
-
* conversationId: '7YpL3oZ4kZ9vP7Q1tR2sX42',
|
|
42
|
-
* newerThan: new Date('2024-01-01'),
|
|
43
|
-
* })
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
getMessages(args) {
|
|
47
|
-
const params = { conversationId: args.conversationId };
|
|
48
|
-
if (args.newerThan)
|
|
49
|
-
params.newerThanTs = Math.floor(args.newerThan.getTime() / 1000);
|
|
50
|
-
if (args.olderThan)
|
|
51
|
-
params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
|
|
52
|
-
if (args.limit)
|
|
53
|
-
params.limit = args.limit;
|
|
54
|
-
if (args.cursor)
|
|
55
|
-
params.cursor = args.cursor;
|
|
56
|
-
return (0, http_client_1.request)({
|
|
57
|
-
httpMethod: 'GET',
|
|
58
|
-
baseUri: this.getBaseUri(),
|
|
59
|
-
relativePath: `${endpoints_1.ENDPOINT_CONVERSATION_MESSAGES}/get`,
|
|
60
|
-
apiToken: this.apiToken,
|
|
61
|
-
payload: params,
|
|
62
|
-
customFetch: this.customFetch,
|
|
63
|
-
}).then((response) => this.messageListSchema.parse(response.data));
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Gets a single conversation message by id.
|
|
67
|
-
*
|
|
68
|
-
* @param id - The message ID.
|
|
69
|
-
* @returns The conversation message object.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const message = await api.conversationMessages.getMessage('7YpL3oZ4kZ9vP7Q1tR2sX43')
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
getMessage(id) {
|
|
77
|
-
return this.simple('GET', 'getone', { id }, this.messageSchema);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Creates a new message in a conversation. `id` is auto-generated if not
|
|
81
|
-
* supplied.
|
|
82
|
-
*
|
|
83
|
-
* @param args - The arguments for creating a message.
|
|
84
|
-
* @param args.conversationId - The conversation ID.
|
|
85
|
-
* @param args.content - The message content.
|
|
86
|
-
* @param args.attachments - Optional array of {@link Attachment} objects.
|
|
87
|
-
* @param args.actions - Optional array of action objects.
|
|
88
|
-
* @returns The created message object.
|
|
89
|
-
*
|
|
90
|
-
* @example
|
|
91
|
-
* ```typescript
|
|
92
|
-
* const message = await api.conversationMessages.createMessage({
|
|
93
|
-
* conversationId: '7YpL3oZ4kZ9vP7Q1tR2sX42',
|
|
94
|
-
* content: 'Thanks for the update!',
|
|
95
|
-
* })
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
98
|
-
createMessage(args) {
|
|
99
|
-
const params = {
|
|
100
|
-
conversationId: args.conversationId,
|
|
101
|
-
content: args.content,
|
|
102
|
-
id: (0, uuidv7_1.resolveCreateId)(args.id),
|
|
103
|
-
};
|
|
104
|
-
if (args.attachments)
|
|
105
|
-
params.attachments = args.attachments;
|
|
106
|
-
if (args.actions)
|
|
107
|
-
params.actions = args.actions;
|
|
108
|
-
if (args.directMentions)
|
|
109
|
-
params.directMentions = args.directMentions;
|
|
110
|
-
if (args.directGroupMentions)
|
|
111
|
-
params.directGroupMentions = args.directGroupMentions;
|
|
112
|
-
if (args.notify !== undefined)
|
|
113
|
-
params.notify = args.notify;
|
|
114
|
-
return this.simple('POST', 'add', params, this.messageSchema);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Updates a conversation message.
|
|
118
|
-
*
|
|
119
|
-
* @param args - The arguments for updating a message.
|
|
120
|
-
* @param args.id - The message ID.
|
|
121
|
-
* @param args.content - The new message content.
|
|
122
|
-
* @param args.attachments - Optional array of {@link Attachment} objects.
|
|
123
|
-
* @returns The updated message object.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const message = await api.conversationMessages.updateMessage({
|
|
128
|
-
* id: '7YpL3oZ4kZ9vP7Q1tR2sX43',
|
|
129
|
-
* content: 'Updated message content',
|
|
130
|
-
* })
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
updateMessage(args) {
|
|
134
|
-
const params = { id: args.id, content: args.content };
|
|
135
|
-
if (args.attachments)
|
|
136
|
-
params.attachments = args.attachments;
|
|
137
|
-
if (args.actions)
|
|
138
|
-
params.actions = args.actions;
|
|
139
|
-
if (args.directMentions)
|
|
140
|
-
params.directMentions = args.directMentions;
|
|
141
|
-
if (args.directGroupMentions)
|
|
142
|
-
params.directGroupMentions = args.directGroupMentions;
|
|
143
|
-
return this.simple('POST', 'update', params, this.messageSchema);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Permanently deletes a conversation message.
|
|
147
|
-
*
|
|
148
|
-
* @param id - The message ID.
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* await api.conversationMessages.deleteMessage('7YpL3oZ4kZ9vP7Q1tR2sX43')
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
deleteMessage(id) {
|
|
156
|
-
return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
|
|
157
|
-
}
|
|
158
|
-
simple(httpMethod, suffix, params, schema) {
|
|
159
|
-
return (0, http_client_1.request)({
|
|
160
|
-
httpMethod,
|
|
161
|
-
baseUri: this.getBaseUri(),
|
|
162
|
-
relativePath: `${endpoints_1.ENDPOINT_CONVERSATION_MESSAGES}/${suffix}`,
|
|
163
|
-
apiToken: this.apiToken,
|
|
164
|
-
payload: params,
|
|
165
|
-
customFetch: this.customFetch,
|
|
166
|
-
}).then((response) => schema.parse(response.data));
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.ConversationMessagesClient = ConversationMessagesClient;
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConversationsClient = exports.ConversationListSchema = 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 base_client_1 = require("./base-client");
|
|
10
|
-
exports.ConversationListSchema = zod_1.z.array(entities_1.ConversationSchema);
|
|
11
|
-
const GetUnreadResponseSchema = zod_1.z.object({
|
|
12
|
-
data: zod_1.z.array(entities_1.UnreadConversationSchema),
|
|
13
|
-
version: zod_1.z.number().int(),
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Client for `/api/v1/conversations/`. `getOrCreate` requires an `id` (the
|
|
17
|
-
* SDK auto-generates one for new conversations); the backend dedupes on
|
|
18
|
-
* `userIds`, so an existing conversation will be returned with its own
|
|
19
|
-
* already-assigned `id` and your generated one is silently dropped.
|
|
20
|
-
*/
|
|
21
|
-
class ConversationsClient 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.conversationSchema = this.linkBaseUrl
|
|
27
|
-
? (0, entities_1.createConversationSchema)(this.linkBaseUrl)
|
|
28
|
-
: entities_1.ConversationSchema;
|
|
29
|
-
this.conversationListSchema = this.linkBaseUrl
|
|
30
|
-
? zod_1.z.array(this.conversationSchema)
|
|
31
|
-
: exports.ConversationListSchema;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Gets a page of conversations for a workspace, newest activity first.
|
|
35
|
-
* The server returns at most 500 rows per request (20 by default); pass
|
|
36
|
-
* the last row's `lastActive`/`id` as `olderThan`/`beforeId` to fetch
|
|
37
|
-
* the next page. Paired, they form a strict compound boundary, so pages
|
|
38
|
-
* never repeat rows. Omitting `archived` returns active and archived
|
|
39
|
-
* conversations mixed.
|
|
40
|
-
*
|
|
41
|
-
* @param args - The arguments for getting conversations.
|
|
42
|
-
* @param args.workspaceId - The workspace ID.
|
|
43
|
-
* @param args.archived - Optional flag to filter archived (true) or active (false) conversations.
|
|
44
|
-
* @param args.olderThan - Optional date to get conversations last active before.
|
|
45
|
-
* @param args.beforeId - Optional conversation id. Paired with olderThan it forms the
|
|
46
|
-
* strict compound cursor; alone it pages by conversation id order instead.
|
|
47
|
-
* @param args.limit - Optional page size (server default 20, max 500).
|
|
48
|
-
* @returns An array of conversation objects.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* const page = await api.conversations.getConversations({ workspaceId: 123, limit: 500 })
|
|
53
|
-
* const last = page.at(-1)
|
|
54
|
-
* const nextPage = last
|
|
55
|
-
* ? await api.conversations.getConversations({
|
|
56
|
-
* workspaceId: 123,
|
|
57
|
-
* limit: 500,
|
|
58
|
-
* olderThan: last.lastActive,
|
|
59
|
-
* beforeId: last.id,
|
|
60
|
-
* })
|
|
61
|
-
* : []
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
getConversations(args) {
|
|
65
|
-
// Fields are picked explicitly (matching getThreads/getComments) so a
|
|
66
|
-
// future Date field can't silently reach the generic snake-casing,
|
|
67
|
-
// which would turn it into an empty object on the wire.
|
|
68
|
-
const params = { workspaceId: args.workspaceId };
|
|
69
|
-
if (args.archived != null)
|
|
70
|
-
params.archived = args.archived;
|
|
71
|
-
if (args.olderThan)
|
|
72
|
-
params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
|
|
73
|
-
if (args.beforeId != null)
|
|
74
|
-
params.beforeId = args.beforeId;
|
|
75
|
-
if (args.limit != null)
|
|
76
|
-
params.limit = args.limit;
|
|
77
|
-
return (0, http_client_1.request)({
|
|
78
|
-
httpMethod: 'GET',
|
|
79
|
-
baseUri: this.getBaseUri(),
|
|
80
|
-
relativePath: `${endpoints_1.ENDPOINT_CONVERSATIONS}/get`,
|
|
81
|
-
apiToken: this.apiToken,
|
|
82
|
-
payload: params,
|
|
83
|
-
customFetch: this.customFetch,
|
|
84
|
-
}).then((response) => this.conversationListSchema.parse(response.data));
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Gets a single conversation object by id.
|
|
88
|
-
*
|
|
89
|
-
* @param id - The conversation ID.
|
|
90
|
-
* @returns The conversation object.
|
|
91
|
-
*/
|
|
92
|
-
getConversation(id) {
|
|
93
|
-
return this.simple('GET', 'getone', { id }, this.conversationSchema);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Gets an existing 1:1 / group conversation with `userIds`, or creates a
|
|
97
|
-
* new one. `id` is auto-generated if not supplied — on dedupe, the
|
|
98
|
-
* backend returns the existing conversation's `id` instead.
|
|
99
|
-
*
|
|
100
|
-
* @param args - The arguments for getting or creating a conversation.
|
|
101
|
-
* @param args.workspaceId - The workspace ID.
|
|
102
|
-
* @param args.userIds - Array of user IDs to include in the conversation.
|
|
103
|
-
* @returns The conversation object (existing or newly created).
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* const conversation = await api.conversations.getOrCreateConversation({
|
|
108
|
-
* workspaceId: 123,
|
|
109
|
-
* userIds: [101, 202, 303],
|
|
110
|
-
* })
|
|
111
|
-
* ```
|
|
112
|
-
*/
|
|
113
|
-
getOrCreateConversation(args) {
|
|
114
|
-
return this.simple('GET', 'get_or_create', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, this.conversationSchema);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Updates a conversation's title.
|
|
118
|
-
*
|
|
119
|
-
* @param args - The arguments for updating a conversation.
|
|
120
|
-
* @param args.id - The conversation ID.
|
|
121
|
-
* @param args.title - The new title for the conversation.
|
|
122
|
-
* @param args.archived - Optional flag to archive/unarchive the conversation.
|
|
123
|
-
* @returns The updated conversation object.
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* const conversation = await api.conversations.updateConversation({
|
|
128
|
-
* id: '7YpL3oZ4kZ9vP7Q1tR2sX42',
|
|
129
|
-
* title: 'New Title',
|
|
130
|
-
* })
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
updateConversation(args) {
|
|
134
|
-
const params = { id: args.id, title: args.title };
|
|
135
|
-
if (args.archived !== undefined)
|
|
136
|
-
params.archived = args.archived;
|
|
137
|
-
return this.simple('POST', 'update', params, this.conversationSchema);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Archives a conversation.
|
|
141
|
-
*
|
|
142
|
-
* @param id - The conversation ID.
|
|
143
|
-
* @returns The updated conversation object.
|
|
144
|
-
*/
|
|
145
|
-
archiveConversation(id) {
|
|
146
|
-
return this.simple('POST', 'archive', { id }, this.conversationSchema);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Unarchives a conversation.
|
|
150
|
-
*
|
|
151
|
-
* @param id - The conversation ID.
|
|
152
|
-
* @returns The updated conversation object.
|
|
153
|
-
*/
|
|
154
|
-
unarchiveConversation(id) {
|
|
155
|
-
return this.simple('POST', 'unarchive', { id }, this.conversationSchema);
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Adds a user to a conversation.
|
|
159
|
-
*
|
|
160
|
-
* @param args - The arguments for adding a user.
|
|
161
|
-
* @param args.id - The conversation ID.
|
|
162
|
-
* @param args.userId - The user ID to add.
|
|
163
|
-
* @returns The updated conversation object.
|
|
164
|
-
*/
|
|
165
|
-
addUser(args) {
|
|
166
|
-
return this.simple('POST', 'add_user', { ...args }, this.conversationSchema);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Adds multiple users to a conversation.
|
|
170
|
-
*
|
|
171
|
-
* @param args - The arguments for adding users.
|
|
172
|
-
* @param args.id - The conversation ID.
|
|
173
|
-
* @param args.userIds - Array of user IDs to add.
|
|
174
|
-
* @returns The updated conversation object.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* ```typescript
|
|
178
|
-
* await api.conversations.addUsers({ id: '7YpL3oZ4kZ9vP7Q1tR2sX42', userIds: [101, 202] })
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
addUsers(args) {
|
|
182
|
-
return this.simple('POST', 'add_users', { ...args }, this.conversationSchema);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Removes a user from a conversation.
|
|
186
|
-
*
|
|
187
|
-
* @param args - The arguments for removing a user.
|
|
188
|
-
* @param args.id - The conversation ID.
|
|
189
|
-
* @param args.userId - The user ID to remove.
|
|
190
|
-
* @returns The updated conversation object.
|
|
191
|
-
*/
|
|
192
|
-
removeUser(args) {
|
|
193
|
-
return this.simple('POST', 'remove_user', { ...args }, this.conversationSchema);
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Removes multiple users from a conversation.
|
|
197
|
-
*
|
|
198
|
-
* @param args - The arguments for removing users.
|
|
199
|
-
* @param args.id - The conversation ID.
|
|
200
|
-
* @param args.userIds - Array of user IDs to remove.
|
|
201
|
-
* @returns The updated conversation object.
|
|
202
|
-
*/
|
|
203
|
-
removeUsers(args) {
|
|
204
|
-
return this.simple('POST', 'remove_users', { ...args }, this.conversationSchema);
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Marks a conversation as read.
|
|
208
|
-
*
|
|
209
|
-
* @param args - The arguments for marking as read.
|
|
210
|
-
* @param args.id - The conversation ID.
|
|
211
|
-
* @param args.objIndex - Optional index of the message to mark as last read.
|
|
212
|
-
* @param args.messageId - Optional message ID to mark as last read.
|
|
213
|
-
*/
|
|
214
|
-
markRead(args) {
|
|
215
|
-
return this.simple('POST', 'mark_read', { ...args }, entities_1.StatusOkSchema);
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Marks a conversation as unread.
|
|
219
|
-
*
|
|
220
|
-
* @param args - The arguments for marking as unread.
|
|
221
|
-
* @param args.id - The conversation ID.
|
|
222
|
-
* @param args.objIndex - Optional index of the message to mark as last unread.
|
|
223
|
-
* @param args.messageId - Optional message ID to mark as last unread.
|
|
224
|
-
*/
|
|
225
|
-
markUnread(args) {
|
|
226
|
-
return this.simple('POST', 'mark_unread', { ...args }, entities_1.StatusOkSchema);
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Returns unread conversations for a workspace, paired with the unread
|
|
230
|
-
* version counter.
|
|
231
|
-
*
|
|
232
|
-
* @param workspaceId - The workspace ID.
|
|
233
|
-
* @returns Object containing the array of unread conversation references and a version counter.
|
|
234
|
-
*/
|
|
235
|
-
getUnread(workspaceId) {
|
|
236
|
-
return this.simple('GET', 'get_unread', { workspaceId }, GetUnreadResponseSchema);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Clears all unread conversations for a workspace.
|
|
240
|
-
*
|
|
241
|
-
* @param workspaceId - The workspace ID.
|
|
242
|
-
*/
|
|
243
|
-
clearUnread(workspaceId) {
|
|
244
|
-
return this.simple('GET', 'clear_unread', { workspaceId }, entities_1.StatusOkSchema);
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Mutes a conversation for a specified number of minutes.
|
|
248
|
-
* The user will receive no notifications from this conversation during that period.
|
|
249
|
-
*
|
|
250
|
-
* @param args - The arguments for muting a conversation.
|
|
251
|
-
* @param args.id - The conversation ID.
|
|
252
|
-
* @param args.minutes - Number of minutes to mute the conversation.
|
|
253
|
-
* @returns The updated conversation object.
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* ```typescript
|
|
257
|
-
* const conversation = await api.conversations.muteConversation({ id: '7YpL3oZ4kZ9vP7Q1tR2sX42', minutes: 30 })
|
|
258
|
-
* ```
|
|
259
|
-
*/
|
|
260
|
-
muteConversation(args) {
|
|
261
|
-
return this.simple('GET', 'mute', { ...args }, this.conversationSchema);
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Unmutes a conversation.
|
|
265
|
-
*
|
|
266
|
-
* @param id - The conversation ID.
|
|
267
|
-
* @returns The updated conversation object.
|
|
268
|
-
*/
|
|
269
|
-
unmuteConversation(id) {
|
|
270
|
-
return this.simple('GET', 'unmute', { id }, this.conversationSchema);
|
|
271
|
-
}
|
|
272
|
-
simple(httpMethod, suffix, params, schema) {
|
|
273
|
-
return (0, http_client_1.request)({
|
|
274
|
-
httpMethod,
|
|
275
|
-
baseUri: this.getBaseUri(),
|
|
276
|
-
relativePath: `${endpoints_1.ENDPOINT_CONVERSATIONS}/${suffix}`,
|
|
277
|
-
apiToken: this.apiToken,
|
|
278
|
-
payload: params,
|
|
279
|
-
customFetch: this.customFetch,
|
|
280
|
-
}).then((response) => schema.parse(response.data));
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
exports.ConversationsClient = ConversationsClient;
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GroupsClient = exports.GroupListSchema = 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 base_client_1 = require("./base-client");
|
|
10
|
-
exports.GroupListSchema = zod_1.z.array(entities_1.GroupSchema);
|
|
11
|
-
/**
|
|
12
|
-
* Client for `/api/v1/groups/`. The broadcast markers `EVERYONE` /
|
|
13
|
-
* `EVERYONE_IN_THREAD` are NOT addressable through these endpoints — they
|
|
14
|
-
* only appear as members of `direct_group_mentions` / `groups` lists on
|
|
15
|
-
* thread/comment writes.
|
|
16
|
-
*
|
|
17
|
-
* `getone` / `update` / `remove` and the member-management ops all require
|
|
18
|
-
* `workspace_id` alongside the group `id`.
|
|
19
|
-
*/
|
|
20
|
-
class GroupsClient extends base_client_1.BaseClient {
|
|
21
|
-
/**
|
|
22
|
-
* Gets all groups for a given workspace.
|
|
23
|
-
*
|
|
24
|
-
* @param workspaceId - The workspace ID.
|
|
25
|
-
* @returns An array of group objects.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* const groups = await api.groups.getGroups(123)
|
|
30
|
-
* groups.forEach(g => console.log(g.name))
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
getGroups(workspaceId) {
|
|
34
|
-
return (0, http_client_1.request)({
|
|
35
|
-
httpMethod: 'GET',
|
|
36
|
-
baseUri: this.getBaseUri(),
|
|
37
|
-
relativePath: `${endpoints_1.ENDPOINT_GROUPS}/get`,
|
|
38
|
-
apiToken: this.apiToken,
|
|
39
|
-
payload: { workspaceId },
|
|
40
|
-
customFetch: this.customFetch,
|
|
41
|
-
}).then((response) => exports.GroupListSchema.parse(response.data));
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Gets a single group object by id. Requires `workspaceId`.
|
|
45
|
-
*
|
|
46
|
-
* @param args - The arguments for getting a group.
|
|
47
|
-
* @param args.id - The group ID.
|
|
48
|
-
* @param args.workspaceId - The workspace ID.
|
|
49
|
-
* @returns The group object.
|
|
50
|
-
*/
|
|
51
|
-
getGroup(args) {
|
|
52
|
-
return this.simple('GET', 'getone', { ...args }, entities_1.GroupSchema);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Creates a new group. `id` is auto-generated if not supplied.
|
|
56
|
-
*
|
|
57
|
-
* @param args - The arguments for creating a group.
|
|
58
|
-
* @param args.workspaceId - The workspace ID.
|
|
59
|
-
* @param args.name - The group name.
|
|
60
|
-
* @param args.id - Optional caller-supplied group ID (for optimistic-UI workflows).
|
|
61
|
-
* @param args.description - Optional group description.
|
|
62
|
-
* @param args.userIds - Optional array of user IDs to add to the group.
|
|
63
|
-
* @returns The created group object.
|
|
64
|
-
*
|
|
65
|
-
* @example
|
|
66
|
-
* ```typescript
|
|
67
|
-
* const group = await api.groups.createGroup({
|
|
68
|
-
* workspaceId: 123,
|
|
69
|
-
* name: 'Engineering Team',
|
|
70
|
-
* userIds: [1, 2, 3],
|
|
71
|
-
* })
|
|
72
|
-
* ```
|
|
73
|
-
*/
|
|
74
|
-
createGroup(args) {
|
|
75
|
-
return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.GroupSchema);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Updates a group's properties. Requires `workspaceId`.
|
|
79
|
-
*
|
|
80
|
-
* @param args - The arguments for updating a group.
|
|
81
|
-
* @param args.id - The group ID.
|
|
82
|
-
* @param args.workspaceId - The workspace ID.
|
|
83
|
-
* @param args.name - Optional new group name.
|
|
84
|
-
* @param args.description - Optional new group description.
|
|
85
|
-
* @returns The updated group object.
|
|
86
|
-
*/
|
|
87
|
-
updateGroup(args) {
|
|
88
|
-
return this.simple('POST', 'update', { ...args }, entities_1.GroupSchema);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Permanently deletes a group. Requires `workspaceId`.
|
|
92
|
-
*
|
|
93
|
-
* @param args - The arguments for deleting a group.
|
|
94
|
-
* @param args.id - The group ID.
|
|
95
|
-
* @param args.workspaceId - The workspace ID.
|
|
96
|
-
*/
|
|
97
|
-
deleteGroup(args) {
|
|
98
|
-
return this.simple('POST', 'remove', { ...args }, entities_1.StatusOkSchema);
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Adds a user to a group.
|
|
102
|
-
*
|
|
103
|
-
* @param args - The arguments for adding a user.
|
|
104
|
-
* @param args.id - The group ID.
|
|
105
|
-
* @param args.workspaceId - The workspace ID.
|
|
106
|
-
* @param args.userId - The user ID to add.
|
|
107
|
-
*/
|
|
108
|
-
addUser(args) {
|
|
109
|
-
// The backend only exposes the plural `add_users` endpoint (routed via
|
|
110
|
-
// Todoist); there is no `add_user`. Delegate to `addUsers` so the wire
|
|
111
|
-
// contract lives in one place.
|
|
112
|
-
const { userId, ...rest } = args;
|
|
113
|
-
return this.addUsers({ ...rest, userIds: [userId] });
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Adds multiple users to a group.
|
|
117
|
-
*
|
|
118
|
-
* @param args - The arguments for adding users.
|
|
119
|
-
* @param args.id - The group ID.
|
|
120
|
-
* @param args.workspaceId - The workspace ID.
|
|
121
|
-
* @param args.userIds - Array of user IDs to add.
|
|
122
|
-
*
|
|
123
|
-
* @example
|
|
124
|
-
* ```typescript
|
|
125
|
-
* await api.groups.addUsers({
|
|
126
|
-
* id: '7YpL3oZ4kZ9vP7Q1tR2sX45',
|
|
127
|
-
* workspaceId: 123,
|
|
128
|
-
* userIds: [101, 202, 303],
|
|
129
|
-
* })
|
|
130
|
-
* ```
|
|
131
|
-
*/
|
|
132
|
-
addUsers(args) {
|
|
133
|
-
return this.simple('POST', 'add_users', { ...args }, entities_1.StatusOkSchema);
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Removes a user from a group.
|
|
137
|
-
*
|
|
138
|
-
* @param args - The arguments for removing a user.
|
|
139
|
-
* @param args.id - The group ID.
|
|
140
|
-
* @param args.workspaceId - The workspace ID.
|
|
141
|
-
* @param args.userId - The user ID to remove.
|
|
142
|
-
*/
|
|
143
|
-
removeUser(args) {
|
|
144
|
-
// The backend only exposes the plural `remove_users` endpoint (routed
|
|
145
|
-
// via Todoist); there is no `remove_user`. Delegate to `removeUsers` so
|
|
146
|
-
// the wire contract lives in one place.
|
|
147
|
-
const { userId, ...rest } = args;
|
|
148
|
-
return this.removeUsers({ ...rest, userIds: [userId] });
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Removes multiple users from a group.
|
|
152
|
-
*
|
|
153
|
-
* @param args - The arguments for removing users.
|
|
154
|
-
* @param args.id - The group ID.
|
|
155
|
-
* @param args.workspaceId - The workspace ID.
|
|
156
|
-
* @param args.userIds - Array of user IDs to remove.
|
|
157
|
-
*/
|
|
158
|
-
removeUsers(args) {
|
|
159
|
-
return this.simple('POST', 'remove_users', { ...args }, entities_1.StatusOkSchema);
|
|
160
|
-
}
|
|
161
|
-
simple(httpMethod, suffix, params, schema) {
|
|
162
|
-
return (0, http_client_1.request)({
|
|
163
|
-
httpMethod,
|
|
164
|
-
baseUri: this.getBaseUri(),
|
|
165
|
-
relativePath: `${endpoints_1.ENDPOINT_GROUPS}/${suffix}`,
|
|
166
|
-
apiToken: this.apiToken,
|
|
167
|
-
payload: params,
|
|
168
|
-
customFetch: this.customFetch,
|
|
169
|
-
}).then((response) => schema.parse(response.data));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
exports.GroupsClient = GroupsClient;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HooksClient = 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 `/api/v1/hooks/`. REST hooks require Todoist OAuth bearer tokens
|
|
10
|
-
* that include Comms audience; session tokens are rejected by the backend.
|
|
11
|
-
*/
|
|
12
|
-
class HooksClient extends base_client_1.BaseClient {
|
|
13
|
-
/**
|
|
14
|
-
* Subscribes the current OAuth app to a REST hook event.
|
|
15
|
-
*
|
|
16
|
-
* @param args - The hook subscription parameters.
|
|
17
|
-
* @param args.targetUrl - HTTPS endpoint, up to 150 characters, that will receive webhook POSTs.
|
|
18
|
-
* @param args.event - Event name to subscribe to.
|
|
19
|
-
* @param args.workspaceId - Optional workspace filter.
|
|
20
|
-
* @param args.channelId - Optional channel filter.
|
|
21
|
-
* @param args.threadId - Optional thread filter.
|
|
22
|
-
* @param args.conversationId - Optional conversation filter for message events.
|
|
23
|
-
* @returns The `{ status: 'ok', id }` response for the subscription.
|
|
24
|
-
*/
|
|
25
|
-
subscribe(args) {
|
|
26
|
-
return (0, http_client_1.request)({
|
|
27
|
-
httpMethod: 'POST',
|
|
28
|
-
baseUri: this.getBaseUri(),
|
|
29
|
-
relativePath: `${endpoints_1.ENDPOINT_HOOKS}/subscribe`,
|
|
30
|
-
apiToken: this.apiToken,
|
|
31
|
-
payload: args,
|
|
32
|
-
customFetch: this.customFetch,
|
|
33
|
-
}).then((response) => entities_1.HookSubscribeResponseSchema.parse(response.data));
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Unsubscribes all hooks with the target URL for the current OAuth app.
|
|
37
|
-
*
|
|
38
|
-
* @param args - The hook unsubscribe parameters.
|
|
39
|
-
* @param args.targetUrl - Target URL to remove.
|
|
40
|
-
*/
|
|
41
|
-
unsubscribe(args) {
|
|
42
|
-
return (0, http_client_1.request)({
|
|
43
|
-
httpMethod: 'POST',
|
|
44
|
-
baseUri: this.getBaseUri(),
|
|
45
|
-
relativePath: `${endpoints_1.ENDPOINT_HOOKS}/unsubscribe`,
|
|
46
|
-
apiToken: this.apiToken,
|
|
47
|
-
payload: args,
|
|
48
|
-
customFetch: this.customFetch,
|
|
49
|
-
}).then((response) => entities_1.StatusOkSchema.parse(response.data));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.HooksClient = HooksClient;
|