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