@doist/comms-sdk 0.1.0-alpha.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/clients/add-comment-helper.js +17 -0
- package/dist/cjs/clients/base-client.js +3 -5
- package/dist/cjs/clients/channels-client.js +123 -6
- package/dist/cjs/clients/comments-client.js +75 -9
- package/dist/cjs/clients/conversation-messages-client.js +76 -5
- package/dist/cjs/clients/conversations-client.js +143 -3
- package/dist/cjs/clients/groups-client.js +98 -5
- package/dist/cjs/clients/inbox-client.js +87 -14
- 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 +211 -16
- 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 +80 -7
- 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/index.js +1 -0
- package/dist/cjs/types/requests.js +0 -1
- package/dist/esm/clients/add-comment-helper.js +17 -0
- package/dist/esm/clients/base-client.js +3 -5
- package/dist/esm/clients/channels-client.js +123 -6
- package/dist/esm/clients/comments-client.js +75 -9
- package/dist/esm/clients/conversation-messages-client.js +76 -5
- package/dist/esm/clients/conversations-client.js +143 -3
- package/dist/esm/clients/groups-client.js +98 -5
- package/dist/esm/clients/inbox-client.js +87 -14
- 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 +211 -16
- 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 +80 -7
- 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/index.js +1 -0
- package/dist/esm/types/requests.js +0 -1
- package/dist/types/clients/add-comment-helper.d.ts +17 -0
- package/dist/types/clients/base-client.d.ts +4 -0
- package/dist/types/clients/channels-client.d.ts +123 -6
- package/dist/types/clients/comments-client.d.ts +73 -6
- package/dist/types/clients/conversation-messages-client.d.ts +76 -5
- package/dist/types/clients/conversations-client.d.ts +143 -3
- package/dist/types/clients/groups-client.d.ts +98 -5
- package/dist/types/clients/inbox-client.d.ts +81 -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 +200 -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 +80 -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/index.d.ts +1 -0
- package/dist/types/types/requests.d.ts +2 -21
- package/package.json +1 -1
|
@@ -9,7 +9,20 @@ const base_client_1 = require("./base-client");
|
|
|
9
9
|
* rejects non-empty `name` and `channelIds` — set neither.
|
|
10
10
|
*/
|
|
11
11
|
class WorkspaceUsersClient extends base_client_1.BaseClient {
|
|
12
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Returns a list of workspace user objects for the given workspace id.
|
|
14
|
+
*
|
|
15
|
+
* @param args - The arguments for getting workspace users.
|
|
16
|
+
* @param args.workspaceId - The workspace ID.
|
|
17
|
+
* @param args.archived - Optional flag to filter archived users.
|
|
18
|
+
* @returns An array of workspace user objects.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const users = await api.workspaceUsers.getWorkspaceUsers({ workspaceId: 123 })
|
|
23
|
+
* users.forEach(u => console.log(u.fullName, u.userType))
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
13
26
|
getWorkspaceUsers(args) {
|
|
14
27
|
return (0, http_client_1.request)({
|
|
15
28
|
httpMethod: 'GET',
|
|
@@ -20,7 +33,12 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
|
|
|
20
33
|
customFetch: this.customFetch,
|
|
21
34
|
}).then((response) => response.data.map((user) => entities_1.WorkspaceUserSchema.parse(user)));
|
|
22
35
|
}
|
|
23
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Returns a list of workspace user IDs for the given workspace id.
|
|
38
|
+
*
|
|
39
|
+
* @param workspaceId - The workspace ID.
|
|
40
|
+
* @returns An array of user IDs.
|
|
41
|
+
*/
|
|
24
42
|
getWorkspaceUserIds(workspaceId) {
|
|
25
43
|
return (0, http_client_1.request)({
|
|
26
44
|
httpMethod: 'GET',
|
|
@@ -31,7 +49,20 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
|
|
|
31
49
|
customFetch: this.customFetch,
|
|
32
50
|
}).then((response) => response.data);
|
|
33
51
|
}
|
|
34
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* Gets a user by id.
|
|
54
|
+
*
|
|
55
|
+
* @param args - The arguments for getting a user by ID.
|
|
56
|
+
* @param args.workspaceId - The workspace ID.
|
|
57
|
+
* @param args.userId - The user's ID.
|
|
58
|
+
* @returns The workspace user object.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const user = await api.workspaceUsers.getUserById({ workspaceId: 123, userId: 456 })
|
|
63
|
+
* console.log(user.fullName, user.email)
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
35
66
|
getUserById(args) {
|
|
36
67
|
return (0, http_client_1.request)({
|
|
37
68
|
httpMethod: 'GET',
|
|
@@ -42,7 +73,22 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
|
|
|
42
73
|
customFetch: this.customFetch,
|
|
43
74
|
}).then((response) => entities_1.WorkspaceUserSchema.parse(response.data));
|
|
44
75
|
}
|
|
45
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* Gets a user by email.
|
|
78
|
+
*
|
|
79
|
+
* @param args - The arguments for getting a user by email.
|
|
80
|
+
* @param args.workspaceId - The workspace ID.
|
|
81
|
+
* @param args.email - The user's email.
|
|
82
|
+
* @returns The workspace user object.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const user = await api.workspaceUsers.getUserByEmail({
|
|
87
|
+
* workspaceId: 123,
|
|
88
|
+
* email: 'user@example.com',
|
|
89
|
+
* })
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
46
92
|
getUserByEmail(args) {
|
|
47
93
|
return (0, http_client_1.request)({
|
|
48
94
|
httpMethod: 'GET',
|
|
@@ -53,7 +99,14 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
|
|
|
53
99
|
customFetch: this.customFetch,
|
|
54
100
|
}).then((response) => entities_1.WorkspaceUserSchema.parse(response.data));
|
|
55
101
|
}
|
|
56
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Gets the user's info in the context of the workspace.
|
|
104
|
+
*
|
|
105
|
+
* @param args - The arguments for getting user info.
|
|
106
|
+
* @param args.workspaceId - The workspace ID.
|
|
107
|
+
* @param args.userId - The user's ID.
|
|
108
|
+
* @returns Information about the user in the workspace context.
|
|
109
|
+
*/
|
|
57
110
|
getUserInfo(args) {
|
|
58
111
|
return (0, http_client_1.request)({
|
|
59
112
|
httpMethod: 'GET',
|
|
@@ -64,7 +117,23 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
|
|
|
64
117
|
customFetch: this.customFetch,
|
|
65
118
|
}).then((response) => response.data);
|
|
66
119
|
}
|
|
67
|
-
/**
|
|
120
|
+
/**
|
|
121
|
+
* Gets the user's local time (e.g., "2017-05-10 07:55:40").
|
|
122
|
+
*
|
|
123
|
+
* @param args - The arguments for getting user local time.
|
|
124
|
+
* @param args.workspaceId - The workspace ID.
|
|
125
|
+
* @param args.userId - The user's ID.
|
|
126
|
+
* @returns The user's local time as a string.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const localTime = await api.workspaceUsers.getUserLocalTime({
|
|
131
|
+
* workspaceId: 123,
|
|
132
|
+
* userId: 456,
|
|
133
|
+
* })
|
|
134
|
+
* console.log('User local time:', localTime)
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
68
137
|
getUserLocalTime(args) {
|
|
69
138
|
return (0, http_client_1.request)({
|
|
70
139
|
httpMethod: 'GET',
|
|
@@ -75,7 +144,15 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
|
|
|
75
144
|
customFetch: this.customFetch,
|
|
76
145
|
}).then((response) => response.data);
|
|
77
146
|
}
|
|
78
|
-
/**
|
|
147
|
+
/**
|
|
148
|
+
* Adds a person to a workspace.
|
|
149
|
+
*
|
|
150
|
+
* @param args - The arguments for adding a user.
|
|
151
|
+
* @param args.workspaceId - The workspace ID.
|
|
152
|
+
* @param args.email - The user's email.
|
|
153
|
+
* @param args.userType - Optional user type (USER, GUEST, or ADMIN).
|
|
154
|
+
* @returns The created workspace user object.
|
|
155
|
+
*/
|
|
79
156
|
addUser(args) {
|
|
80
157
|
return (0, http_client_1.request)({
|
|
81
158
|
httpMethod: 'POST',
|
|
@@ -90,7 +167,16 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
|
|
|
90
167
|
customFetch: this.customFetch,
|
|
91
168
|
}).then((response) => entities_1.WorkspaceUserSchema.parse(response.data));
|
|
92
169
|
}
|
|
93
|
-
/**
|
|
170
|
+
/**
|
|
171
|
+
* Updates a person in a workspace.
|
|
172
|
+
*
|
|
173
|
+
* @param args - The arguments for updating a user.
|
|
174
|
+
* @param args.workspaceId - The workspace ID.
|
|
175
|
+
* @param args.userType - The user type (USER, GUEST, or ADMIN).
|
|
176
|
+
* @param args.email - Optional email of the user to update.
|
|
177
|
+
* @param args.userId - Optional user ID to update (use either email or userId).
|
|
178
|
+
* @returns The updated workspace user object.
|
|
179
|
+
*/
|
|
94
180
|
updateUser(args) {
|
|
95
181
|
return (0, http_client_1.request)({
|
|
96
182
|
httpMethod: 'POST',
|
|
@@ -106,7 +192,14 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
|
|
|
106
192
|
customFetch: this.customFetch,
|
|
107
193
|
}).then((response) => entities_1.WorkspaceUserSchema.parse(response.data));
|
|
108
194
|
}
|
|
109
|
-
/**
|
|
195
|
+
/**
|
|
196
|
+
* Removes a person from a workspace.
|
|
197
|
+
*
|
|
198
|
+
* @param args - The arguments for removing a user.
|
|
199
|
+
* @param args.workspaceId - The workspace ID.
|
|
200
|
+
* @param args.email - Optional email of the user to remove.
|
|
201
|
+
* @param args.userId - Optional user ID to remove (use either email or userId).
|
|
202
|
+
*/
|
|
110
203
|
removeUser(args) {
|
|
111
204
|
return (0, http_client_1.request)({
|
|
112
205
|
httpMethod: 'POST',
|
|
@@ -121,7 +214,14 @@ class WorkspaceUsersClient extends base_client_1.BaseClient {
|
|
|
121
214
|
customFetch: this.customFetch,
|
|
122
215
|
}).then(() => undefined);
|
|
123
216
|
}
|
|
124
|
-
/**
|
|
217
|
+
/**
|
|
218
|
+
* Sends a new workspace invitation to the selected user.
|
|
219
|
+
*
|
|
220
|
+
* @param args - The arguments for resending an invite.
|
|
221
|
+
* @param args.workspaceId - The workspace ID.
|
|
222
|
+
* @param args.email - The user's email.
|
|
223
|
+
* @param args.userId - Optional user ID.
|
|
224
|
+
*/
|
|
125
225
|
resendInvite(args) {
|
|
126
226
|
return (0, http_client_1.request)({
|
|
127
227
|
httpMethod: 'POST',
|
|
@@ -12,7 +12,17 @@ exports.ChannelListSchema = zod_1.z.array(entities_1.ChannelSchema);
|
|
|
12
12
|
* currently rejects any `color` other than `1` on add/update.
|
|
13
13
|
*/
|
|
14
14
|
class WorkspacesClient extends base_client_1.BaseClient {
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Gets all the user's workspaces.
|
|
17
|
+
*
|
|
18
|
+
* @returns An array of all workspaces the user belongs to.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const workspaces = await api.workspaces.getWorkspaces()
|
|
23
|
+
* workspaces.forEach(ws => console.log(ws.name))
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
16
26
|
getWorkspaces() {
|
|
17
27
|
return (0, http_client_1.request)({
|
|
18
28
|
httpMethod: 'GET',
|
|
@@ -23,7 +33,18 @@ class WorkspacesClient extends base_client_1.BaseClient {
|
|
|
23
33
|
customFetch: this.customFetch,
|
|
24
34
|
}).then((response) => response.data.map((workspace) => entities_1.WorkspaceSchema.parse(workspace)));
|
|
25
35
|
}
|
|
26
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Gets a single workspace object by id.
|
|
38
|
+
*
|
|
39
|
+
* @param id - The workspace ID.
|
|
40
|
+
* @returns The workspace object.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const workspace = await api.workspaces.getWorkspace(123)
|
|
45
|
+
* console.log(workspace.name)
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
27
48
|
getWorkspace(id) {
|
|
28
49
|
return (0, http_client_1.request)({
|
|
29
50
|
httpMethod: 'GET',
|
|
@@ -34,7 +55,17 @@ class WorkspacesClient extends base_client_1.BaseClient {
|
|
|
34
55
|
customFetch: this.customFetch,
|
|
35
56
|
}).then((response) => entities_1.WorkspaceSchema.parse(response.data));
|
|
36
57
|
}
|
|
37
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Gets the user's default workspace.
|
|
60
|
+
*
|
|
61
|
+
* @returns The default workspace object.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const workspace = await api.workspaces.getDefaultWorkspace()
|
|
66
|
+
* console.log(workspace.name)
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
38
69
|
getDefaultWorkspace() {
|
|
39
70
|
return (0, http_client_1.request)({
|
|
40
71
|
httpMethod: 'GET',
|
|
@@ -45,7 +76,18 @@ class WorkspacesClient extends base_client_1.BaseClient {
|
|
|
45
76
|
customFetch: this.customFetch,
|
|
46
77
|
}).then((response) => entities_1.WorkspaceSchema.parse(response.data));
|
|
47
78
|
}
|
|
48
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Creates a new workspace.
|
|
81
|
+
*
|
|
82
|
+
* @param name - The name of the new workspace.
|
|
83
|
+
* @returns The created workspace object.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const workspace = await api.workspaces.createWorkspace('My Team')
|
|
88
|
+
* console.log('Created:', workspace.name)
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
49
91
|
createWorkspace(name) {
|
|
50
92
|
return (0, http_client_1.request)({
|
|
51
93
|
httpMethod: 'POST',
|
|
@@ -56,7 +98,18 @@ class WorkspacesClient extends base_client_1.BaseClient {
|
|
|
56
98
|
customFetch: this.customFetch,
|
|
57
99
|
}).then((response) => entities_1.WorkspaceSchema.parse(response.data));
|
|
58
100
|
}
|
|
59
|
-
/**
|
|
101
|
+
/**
|
|
102
|
+
* Updates an existing workspace.
|
|
103
|
+
*
|
|
104
|
+
* @param id - The workspace ID.
|
|
105
|
+
* @param name - The new name for the workspace.
|
|
106
|
+
* @returns The updated workspace object.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* ```typescript
|
|
110
|
+
* const workspace = await api.workspaces.updateWorkspace(123, 'New Team Name')
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
60
113
|
updateWorkspace(id, name) {
|
|
61
114
|
return (0, http_client_1.request)({
|
|
62
115
|
httpMethod: 'POST',
|
|
@@ -67,7 +120,16 @@ class WorkspacesClient extends base_client_1.BaseClient {
|
|
|
67
120
|
customFetch: this.customFetch,
|
|
68
121
|
}).then((response) => entities_1.WorkspaceSchema.parse(response.data));
|
|
69
122
|
}
|
|
70
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Removes a workspace and all its data (not recoverable).
|
|
125
|
+
*
|
|
126
|
+
* @param id - The workspace ID.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* await api.workspaces.removeWorkspace(123)
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
71
133
|
removeWorkspace(id) {
|
|
72
134
|
return (0, http_client_1.request)({
|
|
73
135
|
httpMethod: 'POST',
|
|
@@ -78,7 +140,18 @@ class WorkspacesClient extends base_client_1.BaseClient {
|
|
|
78
140
|
customFetch: this.customFetch,
|
|
79
141
|
}).then(() => undefined);
|
|
80
142
|
}
|
|
81
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* Gets the public channels of a workspace.
|
|
145
|
+
*
|
|
146
|
+
* @param id - The workspace ID.
|
|
147
|
+
* @returns An array of public channel objects.
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const channels = await api.workspaces.getPublicChannels(123)
|
|
152
|
+
* channels.forEach(ch => console.log(ch.name))
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
82
155
|
getPublicChannels(id) {
|
|
83
156
|
return (0, http_client_1.request)({
|
|
84
157
|
httpMethod: 'GET',
|
package/dist/cjs/comms-api.js
CHANGED
|
@@ -2,16 +2,21 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ENDPOINT_CONVERSATION_MESSAGES = exports.ENDPOINT_SEARCH = exports.ENDPOINT_REACTIONS = exports.ENDPOINT_INBOX = exports.ENDPOINT_NOTIFICATIONS = exports.ENDPOINT_COMMENTS = exports.ENDPOINT_CONVERSATIONS = exports.ENDPOINT_GROUPS = exports.ENDPOINT_THREADS = exports.ENDPOINT_CHANNELS = exports.ENDPOINT_WORKSPACES = exports.ENDPOINT_USERS = void 0;
|
|
4
4
|
exports.getCommsBaseUri = getCommsBaseUri;
|
|
5
|
+
const api_version_1 = require("../types/api-version");
|
|
5
6
|
const BASE_URI = 'https://comms.todoist.com';
|
|
6
|
-
const API_VERSION = 'v1';
|
|
7
7
|
/**
|
|
8
8
|
* Gets the base URI for Comms API requests.
|
|
9
9
|
*
|
|
10
|
+
* Preserves any path component on `domainBase` so callers can route through
|
|
11
|
+
* a proxy (e.g. `https://proxy.example.com/comms` → `.../comms/api/v1/`).
|
|
12
|
+
*
|
|
13
|
+
* @param version - API version. Defaults to 'v1'.
|
|
10
14
|
* @param domainBase - Custom domain base URL. Defaults to Comms' API domain.
|
|
11
15
|
* @returns Complete base URI with trailing slash (e.g., 'https://comms.todoist.com/api/v1/')
|
|
12
16
|
*/
|
|
13
|
-
function getCommsBaseUri(domainBase = BASE_URI) {
|
|
14
|
-
|
|
17
|
+
function getCommsBaseUri(version = api_version_1.DEFAULT_API_VERSION, domainBase = BASE_URI) {
|
|
18
|
+
const base = domainBase.endsWith('/') ? domainBase : `${domainBase}/`;
|
|
19
|
+
return new URL(`api/${version}/`, base).toString();
|
|
15
20
|
}
|
|
16
21
|
exports.ENDPOINT_USERS = 'users';
|
|
17
22
|
exports.ENDPOINT_WORKSPACES = 'workspaces';
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockWorkspaceUser = exports.mockComment = exports.mockConversation = exports.mockGroup = exports.mockThread = exports.mockChannel = exports.mockWorkspace = exports.mockUser = exports.TEST_GROUP_ID = exports.TEST_MESSAGE_ID = exports.TEST_CONVERSATION_ID = exports.TEST_COMMENT_ID = exports.TEST_THREAD_ID = exports.TEST_CHANNEL_ID = exports.TEST_API_TOKEN = void 0;
|
|
3
|
+
exports.mockWorkspaceUser = exports.mockComment = exports.mockConversation = exports.mockGroup = exports.mockThread = exports.mockChannel = exports.mockWorkspace = exports.mockUser = exports.TEST_GROUP_ID = exports.TEST_MESSAGE_ID = exports.TEST_CONVERSATION_ID = exports.TEST_COMMENT_ID = exports.TEST_THREAD_ID = exports.TEST_CHANNEL_ID = exports.TEST_API_BASE_URL = exports.TEST_API_TOKEN = void 0;
|
|
4
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
4
5
|
exports.TEST_API_TOKEN = 'test-api-token';
|
|
6
|
+
exports.TEST_API_BASE_URL = (0, endpoints_1.getCommsBaseUri)().replace(/\/$/, '');
|
|
5
7
|
// Canonical test IDs — shaped so they pass SDK-side validation.
|
|
6
8
|
exports.TEST_CHANNEL_ID = '7YpL3oZ4kZ9vP7Q1tR2sX3y';
|
|
7
9
|
exports.TEST_THREAD_ID = '7YpL3oZ4kZ9vP7Q1tR2sX3z';
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./api-version"), exports);
|
|
17
18
|
__exportStar(require("./entities"), exports);
|
|
18
19
|
__exportStar(require("./enums"), exports);
|
|
19
20
|
__exportStar(require("./errors"), exports);
|
|
@@ -97,7 +97,6 @@ exports.GetThreadsArgsSchema = zod_1.z.object({
|
|
|
97
97
|
});
|
|
98
98
|
exports.GetCommentsArgsSchema = zod_1.z.object({
|
|
99
99
|
threadId: zod_1.z.string(),
|
|
100
|
-
from: zod_1.z.date().nullable().optional(),
|
|
101
100
|
newerThan: zod_1.z.date().nullable().optional(),
|
|
102
101
|
olderThan: zod_1.z.date().nullable().optional(),
|
|
103
102
|
limit: zod_1.z.number().nullable().optional(),
|
|
@@ -33,6 +33,23 @@ function applyNotifyAudience(params) {
|
|
|
33
33
|
const { notifyAudience: _stripped, groups, ...rest } = params;
|
|
34
34
|
return { ...rest, groups: [...(groups ?? []), sentinel] };
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Internal helper that powers `comments.createComment`,
|
|
38
|
+
* `threads.closeThread`, and `threads.reopenThread`.
|
|
39
|
+
*
|
|
40
|
+
* Normalizes the `notifyAudience` flag into a sentinel `groups` entry,
|
|
41
|
+
* rejects sentinel IDs passed via `groups` / `directGroupMentions`, mints a
|
|
42
|
+
* UUIDv7 `id` when the caller omits one, and posts to `/comments/add`. When
|
|
43
|
+
* `threadAction` is set (`'close'` / `'reopen'`), it is forwarded on the
|
|
44
|
+
* wire so the same request both adds the comment and transitions the
|
|
45
|
+
* parent thread.
|
|
46
|
+
*
|
|
47
|
+
* @param context - Per-call client context (base URI, API token, optional `customFetch`).
|
|
48
|
+
* @param params - The comment payload (`{@link CreateCommentArgs}`).
|
|
49
|
+
* @param options - Optional configuration.
|
|
50
|
+
* @param options.threadAction - When set, also transitions the parent thread (`'close'` or `'reopen'`).
|
|
51
|
+
* @returns The parsed {@link Comment} returned by the API.
|
|
52
|
+
*/
|
|
36
53
|
export function addCommentRequest(context, params, options) {
|
|
37
54
|
const normalized = applyNotifyAudience(params);
|
|
38
55
|
const withId = { ...normalized, id: resolveCreateId(normalized.id) };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getCommsBaseUri } from '../consts/endpoints.js';
|
|
2
|
+
import { DEFAULT_API_VERSION } from '../types/api-version.js';
|
|
2
3
|
/**
|
|
3
4
|
* Base class for every Comms API client. Centralizes URL handling and
|
|
4
5
|
* config so individual clients stay focused on their endpoints.
|
|
@@ -7,6 +8,7 @@ export class BaseClient {
|
|
|
7
8
|
constructor(config) {
|
|
8
9
|
this.apiToken = config.apiToken;
|
|
9
10
|
this.baseUrl = config.baseUrl;
|
|
11
|
+
this.defaultVersion = config.version || DEFAULT_API_VERSION;
|
|
10
12
|
this.customFetch = config.customFetch;
|
|
11
13
|
}
|
|
12
14
|
/**
|
|
@@ -14,10 +16,6 @@ export class BaseClient {
|
|
|
14
16
|
* slash so relative paths resolve cleanly through `URL`.
|
|
15
17
|
*/
|
|
16
18
|
getBaseUri() {
|
|
17
|
-
|
|
18
|
-
const normalizedBaseUrl = this.baseUrl.endsWith('/') ? this.baseUrl : `${this.baseUrl}/`;
|
|
19
|
-
return `${normalizedBaseUrl}api/v1/`;
|
|
20
|
-
}
|
|
21
|
-
return getCommsBaseUri();
|
|
19
|
+
return getCommsBaseUri(this.defaultVersion, this.baseUrl);
|
|
22
20
|
}
|
|
23
21
|
}
|
|
@@ -11,7 +11,20 @@ export const ChannelListSchema = z.array(ChannelSchema);
|
|
|
11
11
|
* to keep an optimistic-UI ID stable through the round-trip.
|
|
12
12
|
*/
|
|
13
13
|
export class ChannelsClient extends BaseClient {
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Gets all channels for a given workspace.
|
|
16
|
+
*
|
|
17
|
+
* @param args - The arguments for getting channels.
|
|
18
|
+
* @param args.workspaceId - The workspace ID.
|
|
19
|
+
* @param args.archived - Optional flag to include archived channels.
|
|
20
|
+
* @returns An array of channel objects.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const channels = await api.channels.getChannels({ workspaceId: 123 })
|
|
25
|
+
* channels.forEach(ch => console.log(ch.name))
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
15
28
|
getChannels(args) {
|
|
16
29
|
return request({
|
|
17
30
|
httpMethod: 'GET',
|
|
@@ -22,47 +35,151 @@ export class ChannelsClient extends BaseClient {
|
|
|
22
35
|
customFetch: this.customFetch,
|
|
23
36
|
}).then((response) => ChannelListSchema.parse(response.data));
|
|
24
37
|
}
|
|
25
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* Gets a single channel object by id.
|
|
40
|
+
*
|
|
41
|
+
* @param id - The channel ID.
|
|
42
|
+
* @returns The channel object.
|
|
43
|
+
*/
|
|
26
44
|
getChannel(id) {
|
|
27
45
|
return this.simple('GET', 'getone', { id }, ChannelSchema);
|
|
28
46
|
}
|
|
29
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new channel. `id` is auto-generated if not supplied — pass your
|
|
49
|
+
* own `id` to keep an optimistic-UI ID stable through the round-trip.
|
|
50
|
+
*
|
|
51
|
+
* @param args - The arguments for creating a channel.
|
|
52
|
+
* @param args.workspaceId - The workspace ID.
|
|
53
|
+
* @param args.name - The channel name.
|
|
54
|
+
* @param args.description - Optional channel description.
|
|
55
|
+
* @param args.color - Optional channel color.
|
|
56
|
+
* @param args.userIds - Optional array of user IDs to add to the channel.
|
|
57
|
+
* @param args.public - Optional flag to make the channel public.
|
|
58
|
+
* @returns The created channel object.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const channel = await api.channels.createChannel({
|
|
63
|
+
* workspaceId: 123,
|
|
64
|
+
* name: 'Engineering',
|
|
65
|
+
* description: 'Engineering team channel',
|
|
66
|
+
* })
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
30
69
|
createChannel(args) {
|
|
31
70
|
return this.simple('POST', 'add', { ...args, id: resolveCreateId(args.id) }, ChannelSchema);
|
|
32
71
|
}
|
|
33
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Partial update of an existing channel.
|
|
74
|
+
*
|
|
75
|
+
* @param args - The arguments for updating a channel.
|
|
76
|
+
* @param args.id - The channel ID.
|
|
77
|
+
* @param args.name - Optional new channel name.
|
|
78
|
+
* @param args.description - Optional new channel description.
|
|
79
|
+
* @param args.color - Optional new channel color.
|
|
80
|
+
* @param args.public - Optional flag to change channel visibility.
|
|
81
|
+
* @returns The updated channel object.
|
|
82
|
+
*/
|
|
34
83
|
updateChannel(args) {
|
|
35
84
|
return this.simple('POST', 'update', { ...args }, ChannelSchema);
|
|
36
85
|
}
|
|
37
|
-
/**
|
|
86
|
+
/**
|
|
87
|
+
* Updates the channel's view filter (`only_open` / `all` / `only_closed`).
|
|
88
|
+
*
|
|
89
|
+
* @param args - The arguments for updating the channel filter.
|
|
90
|
+
* @param args.id - The channel ID.
|
|
91
|
+
* @param args.filterClosed - The new filter value.
|
|
92
|
+
*/
|
|
38
93
|
updateFilters(args) {
|
|
39
94
|
return this.simple('POST', 'update_filters', { ...args }, StatusOkSchema);
|
|
40
95
|
}
|
|
41
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Permanently deletes a channel.
|
|
98
|
+
*
|
|
99
|
+
* @param id - The channel ID.
|
|
100
|
+
*/
|
|
42
101
|
deleteChannel(id) {
|
|
43
102
|
return this.simple('POST', 'remove', { id }, StatusOkSchema);
|
|
44
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* Archives a channel.
|
|
106
|
+
*
|
|
107
|
+
* @param id - The channel ID.
|
|
108
|
+
*/
|
|
45
109
|
archiveChannel(id) {
|
|
46
110
|
return this.simple('POST', 'archive', { id }, StatusOkSchema);
|
|
47
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Unarchives a channel.
|
|
114
|
+
*
|
|
115
|
+
* @param id - The channel ID.
|
|
116
|
+
*/
|
|
48
117
|
unarchiveChannel(id) {
|
|
49
118
|
return this.simple('POST', 'unarchive', { id }, StatusOkSchema);
|
|
50
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Favorites a channel.
|
|
122
|
+
*
|
|
123
|
+
* @param id - The channel ID.
|
|
124
|
+
*/
|
|
51
125
|
favoriteChannel(id) {
|
|
52
126
|
return this.simple('POST', 'favorite', { id }, StatusOkSchema);
|
|
53
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Unfavorites a channel.
|
|
130
|
+
*
|
|
131
|
+
* @param id - The channel ID.
|
|
132
|
+
*/
|
|
54
133
|
unfavoriteChannel(id) {
|
|
55
134
|
return this.simple('POST', 'unfavorite', { id }, StatusOkSchema);
|
|
56
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Adds a user to a channel.
|
|
138
|
+
*
|
|
139
|
+
* @param args - The arguments for adding a user.
|
|
140
|
+
* @param args.id - The channel ID.
|
|
141
|
+
* @param args.userId - The user ID to add.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* await api.channels.addUser({ id: '7YpL3oZ4kZ9vP7Q1tR2sX44', userId: 101 })
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
57
148
|
addUser(args) {
|
|
58
149
|
return this.simple('POST', 'add_user', { ...args }, ChannelSchema);
|
|
59
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* Adds multiple users to a channel.
|
|
153
|
+
*
|
|
154
|
+
* @param args - The arguments for adding users.
|
|
155
|
+
* @param args.id - The channel ID.
|
|
156
|
+
* @param args.userIds - Array of user IDs to add.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* await api.channels.addUsers({ id: '7YpL3oZ4kZ9vP7Q1tR2sX44', userIds: [101, 202] })
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
60
163
|
addUsers(args) {
|
|
61
164
|
return this.simple('POST', 'add_users', { ...args }, ChannelSchema);
|
|
62
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Removes a user from a channel.
|
|
168
|
+
*
|
|
169
|
+
* @param args - The arguments for removing a user.
|
|
170
|
+
* @param args.id - The channel ID.
|
|
171
|
+
* @param args.userId - The user ID to remove.
|
|
172
|
+
*/
|
|
63
173
|
removeUser(args) {
|
|
64
174
|
return this.simple('POST', 'remove_user', { ...args }, ChannelSchema);
|
|
65
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Removes multiple users from a channel.
|
|
178
|
+
*
|
|
179
|
+
* @param args - The arguments for removing users.
|
|
180
|
+
* @param args.id - The channel ID.
|
|
181
|
+
* @param args.userIds - Array of user IDs to remove.
|
|
182
|
+
*/
|
|
66
183
|
removeUsers(args) {
|
|
67
184
|
return this.simple('POST', 'remove_users', { ...args }, ChannelSchema);
|
|
68
185
|
}
|