@doist/comms-sdk 0.0.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.
Files changed (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -45
  3. package/dist/cjs/authentication.js +211 -0
  4. package/dist/cjs/clients/add-comment-helper.js +70 -0
  5. package/dist/cjs/clients/base-client.js +25 -0
  6. package/dist/cjs/clients/channels-client.js +200 -0
  7. package/dist/cjs/clients/comments-client.js +159 -0
  8. package/dist/cjs/clients/conversation-messages-client.js +158 -0
  9. package/dist/cjs/clients/conversations-client.js +243 -0
  10. package/dist/cjs/clients/groups-client.js +164 -0
  11. package/dist/cjs/clients/inbox-client.js +171 -0
  12. package/dist/cjs/clients/reactions-client.js +97 -0
  13. package/dist/cjs/clients/search-client.js +138 -0
  14. package/dist/cjs/clients/threads-client.js +330 -0
  15. package/dist/cjs/clients/users-client.js +326 -0
  16. package/dist/cjs/clients/workspace-users-client.js +240 -0
  17. package/dist/cjs/clients/workspaces-client.js +166 -0
  18. package/dist/cjs/comms-api.js +66 -0
  19. package/dist/cjs/consts/endpoints.js +32 -0
  20. package/dist/cjs/index.js +48 -0
  21. package/dist/cjs/package.json +1 -0
  22. package/dist/cjs/testUtils/msw-handlers.js +51 -0
  23. package/dist/cjs/testUtils/msw-setup.js +21 -0
  24. package/dist/cjs/testUtils/obsidian-fetch-adapter.js +53 -0
  25. package/dist/cjs/testUtils/test-defaults.js +104 -0
  26. package/dist/cjs/transport/fetch-with-retry.js +136 -0
  27. package/dist/cjs/transport/http-client.js +56 -0
  28. package/dist/cjs/transport/http-dispatcher.js +143 -0
  29. package/dist/cjs/types/api-version.js +8 -0
  30. package/dist/cjs/types/entities.js +411 -0
  31. package/dist/cjs/types/enums.js +37 -0
  32. package/dist/cjs/types/errors.js +12 -0
  33. package/dist/cjs/types/http.js +4 -0
  34. package/dist/cjs/types/index.js +22 -0
  35. package/dist/cjs/types/requests.js +116 -0
  36. package/dist/cjs/utils/case-conversion.js +54 -0
  37. package/dist/cjs/utils/index.js +19 -0
  38. package/dist/cjs/utils/timestamp-conversion.js +49 -0
  39. package/dist/cjs/utils/url-helpers.js +131 -0
  40. package/dist/cjs/utils/uuidv7.js +174 -0
  41. package/dist/esm/authentication.js +203 -0
  42. package/dist/esm/clients/add-comment-helper.js +67 -0
  43. package/dist/esm/clients/base-client.js +21 -0
  44. package/dist/esm/clients/channels-client.js +196 -0
  45. package/dist/esm/clients/comments-client.js +155 -0
  46. package/dist/esm/clients/conversation-messages-client.js +154 -0
  47. package/dist/esm/clients/conversations-client.js +239 -0
  48. package/dist/esm/clients/groups-client.js +160 -0
  49. package/dist/esm/clients/inbox-client.js +167 -0
  50. package/dist/esm/clients/reactions-client.js +93 -0
  51. package/dist/esm/clients/search-client.js +134 -0
  52. package/dist/esm/clients/threads-client.js +326 -0
  53. package/dist/esm/clients/users-client.js +322 -0
  54. package/dist/esm/clients/workspace-users-client.js +236 -0
  55. package/dist/esm/clients/workspaces-client.js +162 -0
  56. package/dist/esm/comms-api.js +62 -0
  57. package/dist/esm/consts/endpoints.js +28 -0
  58. package/dist/esm/index.js +17 -0
  59. package/dist/esm/testUtils/msw-handlers.js +45 -0
  60. package/dist/esm/testUtils/msw-setup.js +18 -0
  61. package/dist/esm/testUtils/obsidian-fetch-adapter.js +50 -0
  62. package/dist/esm/testUtils/test-defaults.js +101 -0
  63. package/dist/esm/transport/fetch-with-retry.js +133 -0
  64. package/dist/esm/transport/http-client.js +51 -0
  65. package/dist/esm/transport/http-dispatcher.js +104 -0
  66. package/dist/esm/types/api-version.js +5 -0
  67. package/dist/esm/types/entities.js +408 -0
  68. package/dist/esm/types/enums.js +34 -0
  69. package/dist/esm/types/errors.js +8 -0
  70. package/dist/esm/types/http.js +1 -0
  71. package/dist/esm/types/index.js +6 -0
  72. package/dist/esm/types/requests.js +113 -0
  73. package/dist/esm/utils/case-conversion.js +47 -0
  74. package/dist/esm/utils/index.js +3 -0
  75. package/dist/esm/utils/timestamp-conversion.js +45 -0
  76. package/dist/esm/utils/url-helpers.js +112 -0
  77. package/dist/esm/utils/uuidv7.js +163 -0
  78. package/dist/types/authentication.d.ts +160 -0
  79. package/dist/types/clients/add-comment-helper.d.ts +29 -0
  80. package/dist/types/clients/base-client.d.ts +28 -0
  81. package/dist/types/clients/channels-client.d.ts +208 -0
  82. package/dist/types/clients/comments-client.d.ts +224 -0
  83. package/dist/types/clients/conversation-messages-client.d.ts +198 -0
  84. package/dist/types/clients/conversations-client.d.ts +346 -0
  85. package/dist/types/clients/groups-client.d.ts +148 -0
  86. package/dist/types/clients/inbox-client.d.ts +96 -0
  87. package/dist/types/clients/reactions-client.d.ts +57 -0
  88. package/dist/types/clients/search-client.d.ts +70 -0
  89. package/dist/types/clients/threads-client.d.ts +536 -0
  90. package/dist/types/clients/users-client.d.ts +250 -0
  91. package/dist/types/clients/workspace-users-client.d.ts +147 -0
  92. package/dist/types/clients/workspaces-client.d.ts +152 -0
  93. package/dist/types/comms-api.d.ts +62 -0
  94. package/dist/types/consts/endpoints.d.ts +24 -0
  95. package/dist/types/index.d.ts +18 -0
  96. package/dist/types/testUtils/msw-handlers.d.ts +28 -0
  97. package/dist/types/testUtils/msw-setup.d.ts +1 -0
  98. package/dist/types/testUtils/obsidian-fetch-adapter.d.ts +29 -0
  99. package/dist/types/testUtils/test-defaults.d.ts +17 -0
  100. package/dist/types/transport/fetch-with-retry.d.ts +4 -0
  101. package/dist/types/transport/http-client.d.ts +13 -0
  102. package/dist/types/transport/http-dispatcher.d.ts +10 -0
  103. package/dist/types/types/api-version.d.ts +6 -0
  104. package/dist/types/types/entities.d.ts +1288 -0
  105. package/dist/types/types/enums.d.ts +55 -0
  106. package/dist/types/types/errors.d.ts +6 -0
  107. package/dist/types/types/http.d.ts +54 -0
  108. package/dist/types/types/index.d.ts +6 -0
  109. package/dist/types/types/requests.d.ts +366 -0
  110. package/dist/types/utils/case-conversion.d.ts +8 -0
  111. package/dist/types/utils/index.d.ts +3 -0
  112. package/dist/types/utils/timestamp-conversion.d.ts +13 -0
  113. package/dist/types/utils/url-helpers.d.ts +88 -0
  114. package/dist/types/utils/uuidv7.d.ts +40 -0
  115. package/package.json +91 -8
@@ -0,0 +1,322 @@
1
+ import { ENDPOINT_USERS } from '../consts/endpoints.js';
2
+ import { request } from '../transport/http-client.js';
3
+ import { UserSchema } from '../types/entities.js';
4
+ import { BaseClient } from './base-client.js';
5
+ /**
6
+ * Client for the `/api/v1/users/` endpoints. Authentication flows through
7
+ * Todoist-ID; `register` / `login` / `loginWithGoogle` / `loginWithToken` /
8
+ * `loginWithTodoist` are the available entry points.
9
+ */
10
+ export class UsersClient extends BaseClient {
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
+ */
22
+ register(args) {
23
+ return this.post(`${ENDPOINT_USERS}/register`, args, UserSchema, { authed: false });
24
+ }
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
+ */
42
+ login(args) {
43
+ return this.post(`${ENDPOINT_USERS}/login`, args, UserSchema, { authed: false });
44
+ }
45
+ /**
46
+ * Logs in using a valid token (sent via Authorization header). The SDK
47
+ * client is already configured with the token, so no args are needed.
48
+ *
49
+ * @returns The authenticated user object.
50
+ */
51
+ loginWithToken() {
52
+ return this.post(`${ENDPOINT_USERS}/login_with_token`, undefined, UserSchema);
53
+ }
54
+ /**
55
+ * Exchanges the browser's Todoist web-session cookie for a Comms session.
56
+ * Only useful when running in a browser context on the shared Todoist
57
+ * registrable domain — the cookie is sent automatically by the browser.
58
+ *
59
+ * @returns The authenticated user object.
60
+ */
61
+ loginWithTodoist() {
62
+ return this.post(`${ENDPOINT_USERS}/login_with_todoist`, {}, UserSchema, { authed: false });
63
+ }
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
+ */
75
+ loginWithGoogle(args) {
76
+ return this.post(`${ENDPOINT_USERS}/login_with_google`, args, UserSchema, { authed: false });
77
+ }
78
+ /**
79
+ * Completes an MFA challenge issued by `loginWithGoogle` (returns an MFA
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`.
87
+ */
88
+ mfaChallenge(args) {
89
+ return request({
90
+ httpMethod: 'POST',
91
+ baseUri: this.getBaseUri(),
92
+ relativePath: `${ENDPOINT_USERS}/mfa/challenge`,
93
+ apiToken: undefined,
94
+ payload: args,
95
+ customFetch: this.customFetch,
96
+ }).then((response) => response.data);
97
+ }
98
+ /** Logs out the current user and clears the session cookie. */
99
+ logout() {
100
+ return request({
101
+ httpMethod: 'POST',
102
+ baseUri: this.getBaseUri(),
103
+ relativePath: `${ENDPOINT_USERS}/logout`,
104
+ apiToken: this.apiToken,
105
+ payload: undefined,
106
+ customFetch: this.customFetch,
107
+ }).then(() => undefined);
108
+ }
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
+ */
120
+ getSessionUser() {
121
+ return this.get(`${ENDPOINT_USERS}/get_session_user`, undefined, UserSchema);
122
+ }
123
+ /**
124
+ * Fetches a single user. Defaults to the session user when no `id` is
125
+ * passed. Cross-workspace lookups require that the caller and the target
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.
133
+ */
134
+ getUser(args) {
135
+ return this.get(`${ENDPOINT_USERS}/getone`, args ?? {}, UserSchema);
136
+ }
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
+ */
143
+ getUserByEmail(email) {
144
+ return this.get(`${ENDPOINT_USERS}/get_by_email`, { email }, UserSchema);
145
+ }
146
+ /**
147
+ * Updates the logged-in user's profile. Most fields are proxied to
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
+ * ```
160
+ */
161
+ update(args) {
162
+ return this.post(`${ENDPOINT_USERS}/update`, args, UserSchema);
163
+ }
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
+ */
173
+ updatePassword(args) {
174
+ return this.post(`${ENDPOINT_USERS}/update_password`, args, UserSchema);
175
+ }
176
+ /**
177
+ * Removes the user's avatar.
178
+ *
179
+ * @returns The updated user object.
180
+ */
181
+ removeAvatar() {
182
+ return this.post(`${ENDPOINT_USERS}/remove_avatar`, undefined, UserSchema);
183
+ }
184
+ /**
185
+ * Invalidates the current API token and returns the user with a fresh
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
+ * ```
195
+ */
196
+ invalidateToken() {
197
+ return this.post(`${ENDPOINT_USERS}/invalidate_token`, undefined, UserSchema);
198
+ }
199
+ /**
200
+ * Validates that an arbitrary token is still active. Note this is sent
201
+ * as a GET — the token is read from the query string, not the
202
+ * Authorization header.
203
+ *
204
+ * @param token - The token to validate.
205
+ */
206
+ validateToken(token) {
207
+ return request({
208
+ httpMethod: 'GET',
209
+ baseUri: this.getBaseUri(),
210
+ relativePath: `${ENDPOINT_USERS}/validate_token`,
211
+ apiToken: undefined,
212
+ payload: { token },
213
+ customFetch: this.customFetch,
214
+ }).then(() => undefined);
215
+ }
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
+ */
228
+ heartbeat(args) {
229
+ return request({
230
+ httpMethod: 'GET',
231
+ baseUri: this.getBaseUri(),
232
+ relativePath: `${ENDPOINT_USERS}/heartbeat`,
233
+ apiToken: this.apiToken,
234
+ payload: args,
235
+ customFetch: this.customFetch,
236
+ }).then(() => undefined);
237
+ }
238
+ /**
239
+ * Resets the user's presence for a workspace (marks the user as inactive).
240
+ *
241
+ * @param workspaceId - The workspace ID.
242
+ */
243
+ resetPresence(workspaceId) {
244
+ return request({
245
+ httpMethod: 'POST',
246
+ baseUri: this.getBaseUri(),
247
+ relativePath: `${ENDPOINT_USERS}/reset_presence`,
248
+ apiToken: this.apiToken,
249
+ payload: { workspaceId },
250
+ customFetch: this.customFetch,
251
+ }).then(() => undefined);
252
+ }
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
+ */
259
+ checkEmail(email) {
260
+ return request({
261
+ httpMethod: 'POST',
262
+ baseUri: this.getBaseUri(),
263
+ relativePath: `${ENDPOINT_USERS}/check_email`,
264
+ apiToken: undefined,
265
+ payload: { email },
266
+ customFetch: this.customFetch,
267
+ }).then((response) => response.data);
268
+ }
269
+ /**
270
+ * Returns the current per-channel mail unsubscribe settings for the
271
+ * caller's primary email.
272
+ *
273
+ * @returns Object mapping email-type keys to their opt-out flag.
274
+ */
275
+ getUnsubscribeSettings() {
276
+ return request({
277
+ httpMethod: 'GET',
278
+ baseUri: this.getBaseUri(),
279
+ relativePath: `${ENDPOINT_USERS}/get_unsubscribe_settings`,
280
+ apiToken: this.apiToken,
281
+ payload: undefined,
282
+ customFetch: this.customFetch,
283
+ }).then((response) => response.data);
284
+ }
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
+ */
291
+ updateUnsubscribeSettings(settings) {
292
+ return request({
293
+ httpMethod: 'POST',
294
+ baseUri: this.getBaseUri(),
295
+ relativePath: `${ENDPOINT_USERS}/update_unsubscribe_settings`,
296
+ apiToken: this.apiToken,
297
+ payload: settings,
298
+ customFetch: this.customFetch,
299
+ }).then((response) => response.data);
300
+ }
301
+ get(url, params, schema) {
302
+ return request({
303
+ httpMethod: 'GET',
304
+ baseUri: this.getBaseUri(),
305
+ relativePath: url,
306
+ apiToken: this.apiToken,
307
+ payload: params,
308
+ customFetch: this.customFetch,
309
+ }).then((response) => schema.parse(response.data));
310
+ }
311
+ post(url, params, schema, options = {}) {
312
+ const authed = options.authed ?? true;
313
+ return request({
314
+ httpMethod: 'POST',
315
+ baseUri: this.getBaseUri(),
316
+ relativePath: url,
317
+ apiToken: authed ? this.apiToken : undefined,
318
+ payload: params,
319
+ customFetch: this.customFetch,
320
+ }).then((response) => schema.parse(response.data));
321
+ }
322
+ }
@@ -0,0 +1,236 @@
1
+ import { request } from '../transport/http-client.js';
2
+ import { WorkspaceUserSchema } from '../types/entities.js';
3
+ import { BaseClient } from './base-client.js';
4
+ /**
5
+ * Client for `/api/v1/workspace_users/`. The backend's `add` endpoint
6
+ * rejects non-empty `name` and `channelIds` — set neither.
7
+ */
8
+ export class WorkspaceUsersClient extends BaseClient {
9
+ /**
10
+ * Returns a list of workspace user objects for the given workspace id.
11
+ *
12
+ * @param args - The arguments for getting workspace users.
13
+ * @param args.workspaceId - The workspace ID.
14
+ * @param args.archived - Optional flag to filter archived users.
15
+ * @returns An array of workspace user objects.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const users = await api.workspaceUsers.getWorkspaceUsers({ workspaceId: 123 })
20
+ * users.forEach(u => console.log(u.fullName, u.userType))
21
+ * ```
22
+ */
23
+ getWorkspaceUsers(args) {
24
+ return request({
25
+ httpMethod: 'GET',
26
+ baseUri: this.getBaseUri(),
27
+ relativePath: 'workspace_users/get',
28
+ apiToken: this.apiToken,
29
+ payload: { id: args.workspaceId, archived: args.archived },
30
+ customFetch: this.customFetch,
31
+ }).then((response) => response.data.map((user) => WorkspaceUserSchema.parse(user)));
32
+ }
33
+ /**
34
+ * Returns a list of workspace user IDs for the given workspace id.
35
+ *
36
+ * @param workspaceId - The workspace ID.
37
+ * @returns An array of user IDs.
38
+ */
39
+ getWorkspaceUserIds(workspaceId) {
40
+ return request({
41
+ httpMethod: 'GET',
42
+ baseUri: this.getBaseUri(),
43
+ relativePath: 'workspace_users/get_ids',
44
+ apiToken: this.apiToken,
45
+ payload: { id: workspaceId },
46
+ customFetch: this.customFetch,
47
+ }).then((response) => response.data);
48
+ }
49
+ /**
50
+ * Gets a user by id.
51
+ *
52
+ * @param args - The arguments for getting a user by ID.
53
+ * @param args.workspaceId - The workspace ID.
54
+ * @param args.userId - The user's ID.
55
+ * @returns The workspace user object.
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const user = await api.workspaceUsers.getUserById({ workspaceId: 123, userId: 456 })
60
+ * console.log(user.fullName, user.email)
61
+ * ```
62
+ */
63
+ getUserById(args) {
64
+ return request({
65
+ httpMethod: 'GET',
66
+ baseUri: this.getBaseUri(),
67
+ relativePath: 'workspace_users/getone',
68
+ apiToken: this.apiToken,
69
+ payload: { id: args.workspaceId, user_id: args.userId },
70
+ customFetch: this.customFetch,
71
+ }).then((response) => WorkspaceUserSchema.parse(response.data));
72
+ }
73
+ /**
74
+ * Gets a user by email.
75
+ *
76
+ * @param args - The arguments for getting a user by email.
77
+ * @param args.workspaceId - The workspace ID.
78
+ * @param args.email - The user's email.
79
+ * @returns The workspace user object.
80
+ *
81
+ * @example
82
+ * ```typescript
83
+ * const user = await api.workspaceUsers.getUserByEmail({
84
+ * workspaceId: 123,
85
+ * email: 'user@example.com',
86
+ * })
87
+ * ```
88
+ */
89
+ getUserByEmail(args) {
90
+ return request({
91
+ httpMethod: 'GET',
92
+ baseUri: this.getBaseUri(),
93
+ relativePath: 'workspace_users/get_by_email',
94
+ apiToken: this.apiToken,
95
+ payload: { id: args.workspaceId, email: args.email },
96
+ customFetch: this.customFetch,
97
+ }).then((response) => WorkspaceUserSchema.parse(response.data));
98
+ }
99
+ /**
100
+ * Gets the user's info in the context of the workspace.
101
+ *
102
+ * @param args - The arguments for getting user info.
103
+ * @param args.workspaceId - The workspace ID.
104
+ * @param args.userId - The user's ID.
105
+ * @returns Information about the user in the workspace context.
106
+ */
107
+ getUserInfo(args) {
108
+ return request({
109
+ httpMethod: 'GET',
110
+ baseUri: this.getBaseUri(),
111
+ relativePath: 'workspace_users/get_info',
112
+ apiToken: this.apiToken,
113
+ payload: { id: args.workspaceId, user_id: args.userId },
114
+ customFetch: this.customFetch,
115
+ }).then((response) => response.data);
116
+ }
117
+ /**
118
+ * Gets the user's local time (e.g., "2017-05-10 07:55:40").
119
+ *
120
+ * @param args - The arguments for getting user local time.
121
+ * @param args.workspaceId - The workspace ID.
122
+ * @param args.userId - The user's ID.
123
+ * @returns The user's local time as a string.
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * const localTime = await api.workspaceUsers.getUserLocalTime({
128
+ * workspaceId: 123,
129
+ * userId: 456,
130
+ * })
131
+ * console.log('User local time:', localTime)
132
+ * ```
133
+ */
134
+ getUserLocalTime(args) {
135
+ return request({
136
+ httpMethod: 'GET',
137
+ baseUri: this.getBaseUri(),
138
+ relativePath: 'workspace_users/get_local_time',
139
+ apiToken: this.apiToken,
140
+ payload: { id: args.workspaceId, user_id: args.userId },
141
+ customFetch: this.customFetch,
142
+ }).then((response) => response.data);
143
+ }
144
+ /**
145
+ * Adds a person to a workspace.
146
+ *
147
+ * @param args - The arguments for adding a user.
148
+ * @param args.workspaceId - The workspace ID.
149
+ * @param args.email - The user's email.
150
+ * @param args.userType - Optional user type (USER, GUEST, or ADMIN).
151
+ * @returns The created workspace user object.
152
+ */
153
+ addUser(args) {
154
+ return request({
155
+ httpMethod: 'POST',
156
+ baseUri: this.getBaseUri(),
157
+ relativePath: 'workspace_users/add',
158
+ apiToken: this.apiToken,
159
+ payload: {
160
+ id: args.workspaceId,
161
+ email: args.email,
162
+ userType: args.userType,
163
+ },
164
+ customFetch: this.customFetch,
165
+ }).then((response) => WorkspaceUserSchema.parse(response.data));
166
+ }
167
+ /**
168
+ * Updates a person in a workspace.
169
+ *
170
+ * @param args - The arguments for updating a user.
171
+ * @param args.workspaceId - The workspace ID.
172
+ * @param args.userType - The user type (USER, GUEST, or ADMIN).
173
+ * @param args.email - Optional email of the user to update.
174
+ * @param args.userId - Optional user ID to update (use either email or userId).
175
+ * @returns The updated workspace user object.
176
+ */
177
+ updateUser(args) {
178
+ return request({
179
+ httpMethod: 'POST',
180
+ baseUri: this.getBaseUri(),
181
+ relativePath: 'workspace_users/update',
182
+ apiToken: this.apiToken,
183
+ payload: {
184
+ id: args.workspaceId,
185
+ userType: args.userType,
186
+ email: args.email,
187
+ userId: args.userId,
188
+ },
189
+ customFetch: this.customFetch,
190
+ }).then((response) => WorkspaceUserSchema.parse(response.data));
191
+ }
192
+ /**
193
+ * Removes a person from a workspace.
194
+ *
195
+ * @param args - The arguments for removing a user.
196
+ * @param args.workspaceId - The workspace ID.
197
+ * @param args.email - Optional email of the user to remove.
198
+ * @param args.userId - Optional user ID to remove (use either email or userId).
199
+ */
200
+ removeUser(args) {
201
+ return request({
202
+ httpMethod: 'POST',
203
+ baseUri: this.getBaseUri(),
204
+ relativePath: 'workspace_users/remove',
205
+ apiToken: this.apiToken,
206
+ payload: {
207
+ id: args.workspaceId,
208
+ email: args.email,
209
+ userId: args.userId,
210
+ },
211
+ customFetch: this.customFetch,
212
+ }).then(() => undefined);
213
+ }
214
+ /**
215
+ * Sends a new workspace invitation to the selected user.
216
+ *
217
+ * @param args - The arguments for resending an invite.
218
+ * @param args.workspaceId - The workspace ID.
219
+ * @param args.email - The user's email.
220
+ * @param args.userId - Optional user ID.
221
+ */
222
+ resendInvite(args) {
223
+ return request({
224
+ httpMethod: 'POST',
225
+ baseUri: this.getBaseUri(),
226
+ relativePath: 'workspace_users/resend_invite',
227
+ apiToken: this.apiToken,
228
+ payload: {
229
+ id: args.workspaceId,
230
+ email: args.email,
231
+ userId: args.userId,
232
+ },
233
+ customFetch: this.customFetch,
234
+ }).then(() => undefined);
235
+ }
236
+ }