@doist/comms-sdk 0.1.0-alpha.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/clients/add-comment-helper.js +18 -2
  3. package/dist/cjs/clients/base-client.js +11 -5
  4. package/dist/cjs/clients/channels-client.js +142 -14
  5. package/dist/cjs/clients/comments-client.js +99 -14
  6. package/dist/cjs/clients/conversation-messages-client.js +91 -9
  7. package/dist/cjs/clients/conversations-client.js +166 -15
  8. package/dist/cjs/clients/groups-client.js +98 -5
  9. package/dist/cjs/clients/inbox-client.js +102 -16
  10. package/dist/cjs/clients/reactions-client.js +40 -2
  11. package/dist/cjs/clients/search-client.js +50 -0
  12. package/dist/cjs/clients/threads-client.js +238 -24
  13. package/dist/cjs/clients/users-client.js +138 -11
  14. package/dist/cjs/clients/workspace-users-client.js +110 -10
  15. package/dist/cjs/clients/workspaces-client.js +89 -8
  16. package/dist/cjs/comms-api.js +1 -0
  17. package/dist/cjs/consts/endpoints.js +8 -3
  18. package/dist/cjs/testUtils/test-defaults.js +3 -1
  19. package/dist/cjs/types/api-version.js +8 -0
  20. package/dist/cjs/types/entities.js +119 -98
  21. package/dist/cjs/types/index.js +1 -0
  22. package/dist/cjs/types/requests.js +0 -1
  23. package/dist/cjs/utils/url-helpers.js +3 -1
  24. package/dist/esm/clients/add-comment-helper.js +18 -2
  25. package/dist/esm/clients/base-client.js +11 -5
  26. package/dist/esm/clients/channels-client.js +143 -15
  27. package/dist/esm/clients/comments-client.js +100 -15
  28. package/dist/esm/clients/conversation-messages-client.js +92 -10
  29. package/dist/esm/clients/conversations-client.js +167 -16
  30. package/dist/esm/clients/groups-client.js +98 -5
  31. package/dist/esm/clients/inbox-client.js +102 -16
  32. package/dist/esm/clients/reactions-client.js +40 -2
  33. package/dist/esm/clients/search-client.js +50 -0
  34. package/dist/esm/clients/threads-client.js +239 -25
  35. package/dist/esm/clients/users-client.js +138 -11
  36. package/dist/esm/clients/workspace-users-client.js +110 -10
  37. package/dist/esm/clients/workspaces-client.js +90 -9
  38. package/dist/esm/comms-api.js +1 -0
  39. package/dist/esm/consts/endpoints.js +8 -3
  40. package/dist/esm/testUtils/test-defaults.js +2 -0
  41. package/dist/esm/types/api-version.js +5 -0
  42. package/dist/esm/types/entities.js +111 -97
  43. package/dist/esm/types/index.js +1 -0
  44. package/dist/esm/types/requests.js +0 -1
  45. package/dist/esm/utils/url-helpers.js +3 -1
  46. package/dist/types/clients/add-comment-helper.d.ts +20 -1
  47. package/dist/types/clients/base-client.d.ts +10 -0
  48. package/dist/types/clients/channels-client.d.ts +126 -6
  49. package/dist/types/clients/comments-client.d.ts +77 -6
  50. package/dist/types/clients/conversation-messages-client.d.ts +79 -5
  51. package/dist/types/clients/conversations-client.d.ts +146 -3
  52. package/dist/types/clients/groups-client.d.ts +98 -5
  53. package/dist/types/clients/inbox-client.d.ts +463 -5
  54. package/dist/types/clients/reactions-client.d.ts +40 -2
  55. package/dist/types/clients/search-client.d.ts +50 -0
  56. package/dist/types/clients/threads-client.d.ts +204 -8
  57. package/dist/types/clients/users-client.d.ts +138 -11
  58. package/dist/types/clients/workspace-users-client.d.ts +110 -10
  59. package/dist/types/clients/workspaces-client.d.ts +82 -7
  60. package/dist/types/comms-api.d.ts +3 -0
  61. package/dist/types/consts/endpoints.d.ts +6 -1
  62. package/dist/types/testUtils/test-defaults.d.ts +1 -0
  63. package/dist/types/types/api-version.d.ts +6 -0
  64. package/dist/types/types/entities.d.ts +1654 -126
  65. package/dist/types/types/index.d.ts +1 -0
  66. package/dist/types/types/requests.d.ts +2 -21
  67. package/package.json +1 -1
@@ -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
- /** Returns workspace user objects for the given workspace id. */
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
- /** Returns workspace user IDs for the given workspace id. */
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
- /** Gets a user by id. */
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
- /** Gets a user by email. */
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
- /** Gets the user's info in the context of the workspace. */
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
- /** Gets the user's local time (e.g., "2017-05-10 07:55:40"). */
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
- /** Adds a person to a workspace. */
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
- /** Updates a person in a workspace. */
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
- /** Removes a person from a workspace. */
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
- /** Sends a new workspace invitation to the selected user. */
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,25 @@ 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
- /** Gets all the user's workspaces. */
15
+ constructor() {
16
+ super(...arguments);
17
+ this.linkBaseUrl = this.getLinkBaseUrl();
18
+ // Reuse the shared singleton when no custom base is configured.
19
+ this.channelListSchema = this.linkBaseUrl
20
+ ? zod_1.z.array((0, entities_1.createChannelSchema)(this.linkBaseUrl))
21
+ : exports.ChannelListSchema;
22
+ }
23
+ /**
24
+ * Gets all the user's workspaces.
25
+ *
26
+ * @returns An array of all workspaces the user belongs to.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const workspaces = await api.workspaces.getWorkspaces()
31
+ * workspaces.forEach(ws => console.log(ws.name))
32
+ * ```
33
+ */
16
34
  getWorkspaces() {
17
35
  return (0, http_client_1.request)({
18
36
  httpMethod: 'GET',
@@ -23,7 +41,18 @@ class WorkspacesClient extends base_client_1.BaseClient {
23
41
  customFetch: this.customFetch,
24
42
  }).then((response) => response.data.map((workspace) => entities_1.WorkspaceSchema.parse(workspace)));
25
43
  }
26
- /** Gets a single workspace object by id. */
44
+ /**
45
+ * Gets a single workspace object by id.
46
+ *
47
+ * @param id - The workspace ID.
48
+ * @returns The workspace object.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * const workspace = await api.workspaces.getWorkspace(123)
53
+ * console.log(workspace.name)
54
+ * ```
55
+ */
27
56
  getWorkspace(id) {
28
57
  return (0, http_client_1.request)({
29
58
  httpMethod: 'GET',
@@ -34,7 +63,17 @@ class WorkspacesClient extends base_client_1.BaseClient {
34
63
  customFetch: this.customFetch,
35
64
  }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
36
65
  }
37
- /** Gets the user's default workspace. */
66
+ /**
67
+ * Gets the user's default workspace.
68
+ *
69
+ * @returns The default workspace object.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * const workspace = await api.workspaces.getDefaultWorkspace()
74
+ * console.log(workspace.name)
75
+ * ```
76
+ */
38
77
  getDefaultWorkspace() {
39
78
  return (0, http_client_1.request)({
40
79
  httpMethod: 'GET',
@@ -45,7 +84,18 @@ class WorkspacesClient extends base_client_1.BaseClient {
45
84
  customFetch: this.customFetch,
46
85
  }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
47
86
  }
48
- /** Creates a new workspace. */
87
+ /**
88
+ * Creates a new workspace.
89
+ *
90
+ * @param name - The name of the new workspace.
91
+ * @returns The created workspace object.
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const workspace = await api.workspaces.createWorkspace('My Team')
96
+ * console.log('Created:', workspace.name)
97
+ * ```
98
+ */
49
99
  createWorkspace(name) {
50
100
  return (0, http_client_1.request)({
51
101
  httpMethod: 'POST',
@@ -56,7 +106,18 @@ class WorkspacesClient extends base_client_1.BaseClient {
56
106
  customFetch: this.customFetch,
57
107
  }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
58
108
  }
59
- /** Updates an existing workspace. */
109
+ /**
110
+ * Updates an existing workspace.
111
+ *
112
+ * @param id - The workspace ID.
113
+ * @param name - The new name for the workspace.
114
+ * @returns The updated workspace object.
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const workspace = await api.workspaces.updateWorkspace(123, 'New Team Name')
119
+ * ```
120
+ */
60
121
  updateWorkspace(id, name) {
61
122
  return (0, http_client_1.request)({
62
123
  httpMethod: 'POST',
@@ -67,7 +128,16 @@ class WorkspacesClient extends base_client_1.BaseClient {
67
128
  customFetch: this.customFetch,
68
129
  }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
69
130
  }
70
- /** Removes a workspace and all its data (not recoverable). */
131
+ /**
132
+ * Removes a workspace and all its data (not recoverable).
133
+ *
134
+ * @param id - The workspace ID.
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * await api.workspaces.removeWorkspace(123)
139
+ * ```
140
+ */
71
141
  removeWorkspace(id) {
72
142
  return (0, http_client_1.request)({
73
143
  httpMethod: 'POST',
@@ -78,7 +148,18 @@ class WorkspacesClient extends base_client_1.BaseClient {
78
148
  customFetch: this.customFetch,
79
149
  }).then(() => undefined);
80
150
  }
81
- /** Gets the public channels of a workspace. */
151
+ /**
152
+ * Gets the public channels of a workspace.
153
+ *
154
+ * @param id - The workspace ID.
155
+ * @returns An array of public channel objects.
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const channels = await api.workspaces.getPublicChannels(123)
160
+ * channels.forEach(ch => console.log(ch.name))
161
+ * ```
162
+ */
82
163
  getPublicChannels(id) {
83
164
  return (0, http_client_1.request)({
84
165
  httpMethod: 'GET',
@@ -87,7 +168,7 @@ class WorkspacesClient extends base_client_1.BaseClient {
87
168
  apiToken: this.apiToken,
88
169
  payload: { id },
89
170
  customFetch: this.customFetch,
90
- }).then((response) => exports.ChannelListSchema.parse(response.data));
171
+ }).then((response) => this.channelListSchema.parse(response.data));
91
172
  }
92
173
  }
93
174
  exports.WorkspacesClient = WorkspacesClient;
@@ -36,6 +36,7 @@ class CommsApi {
36
36
  const clientConfig = {
37
37
  apiToken: authToken,
38
38
  baseUrl: options?.baseUrl,
39
+ version: options?.version,
39
40
  customFetch: options?.customFetch,
40
41
  };
41
42
  this.users = new users_client_1.UsersClient(clientConfig);
@@ -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
- return new URL(`/api/${API_VERSION}/`, domainBase).toString();
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';
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_API_VERSION = exports.API_VERSIONS = void 0;
4
+ /**
5
+ * Supported Comms API versions
6
+ */
7
+ exports.API_VERSIONS = ['v1'];
8
+ exports.DEFAULT_API_VERSION = 'v1';