@scalekit-sdk/node 2.1.7 → 2.1.8

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 (82) hide show
  1. package/buf.gen.yaml +1 -0
  2. package/lib/auth.d.ts +41 -9
  3. package/lib/auth.js +44 -12
  4. package/lib/auth.js.map +1 -1
  5. package/lib/connection.d.ts +195 -21
  6. package/lib/connection.js +197 -23
  7. package/lib/connection.js.map +1 -1
  8. package/lib/core.d.ts +2 -2
  9. package/lib/core.js +13 -12
  10. package/lib/core.js.map +1 -1
  11. package/lib/directory.d.ts +293 -40
  12. package/lib/directory.js +308 -44
  13. package/lib/directory.js.map +1 -1
  14. package/lib/domain.d.ts +166 -18
  15. package/lib/domain.js +178 -29
  16. package/lib/domain.js.map +1 -1
  17. package/lib/organization.d.ts +404 -44
  18. package/lib/organization.js +419 -54
  19. package/lib/organization.js.map +1 -1
  20. package/lib/permission.d.ts +179 -35
  21. package/lib/permission.js +190 -38
  22. package/lib/permission.js.map +1 -1
  23. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.d.ts +3 -3
  24. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js +2 -2
  25. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js.map +1 -1
  26. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.d.ts +16 -16
  27. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js +21 -21
  28. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js.map +1 -1
  29. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.d.ts +82 -0
  30. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js +90 -0
  31. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js.map +1 -0
  32. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.d.ts +647 -0
  33. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js +993 -0
  34. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js.map +1 -0
  35. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.d.ts +142 -0
  36. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js +165 -1
  37. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js.map +1 -1
  38. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.d.ts +1 -10
  39. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js +0 -9
  40. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js.map +1 -1
  41. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.d.ts +28 -63
  42. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js +9 -90
  43. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js.map +1 -1
  44. package/lib/pkg/grpc/scalekit/v1/users/users_pb.d.ts +2 -2
  45. package/lib/pkg/grpc/scalekit/v1/users/users_pb.js +1 -1
  46. package/lib/pkg/grpc/scalekit/v1/users/users_pb.js.map +1 -1
  47. package/lib/role.d.ts +252 -56
  48. package/lib/role.js +262 -62
  49. package/lib/role.js.map +1 -1
  50. package/lib/scalekit.d.ts +323 -54
  51. package/lib/scalekit.js +354 -76
  52. package/lib/scalekit.js.map +1 -1
  53. package/lib/session.d.ts +235 -22
  54. package/lib/session.js +237 -24
  55. package/lib/session.js.map +1 -1
  56. package/lib/user.d.ts +571 -53
  57. package/lib/user.js +598 -89
  58. package/lib/user.js.map +1 -1
  59. package/lib/webauthn.d.ts +33 -0
  60. package/lib/webauthn.js +80 -0
  61. package/lib/webauthn.js.map +1 -0
  62. package/package.json +2 -2
  63. package/src/auth.ts +53 -19
  64. package/src/connection.ts +237 -62
  65. package/src/core.ts +39 -33
  66. package/src/directory.ts +356 -98
  67. package/src/domain.ts +215 -68
  68. package/src/organization.ts +490 -112
  69. package/src/permission.ts +234 -88
  70. package/src/pkg/grpc/scalekit/v1/auth/auth_connect.ts +3 -3
  71. package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +24 -24
  72. package/src/pkg/grpc/scalekit/v1/auth/webauthn_connect.ts +89 -0
  73. package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +1263 -0
  74. package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +217 -0
  75. package/src/pkg/grpc/scalekit/v1/connections/connections_connect.ts +1 -10
  76. package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +42 -129
  77. package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +3 -3
  78. package/src/role.ts +336 -136
  79. package/src/scalekit.ts +478 -149
  80. package/src/session.ts +266 -63
  81. package/src/user.ts +675 -168
  82. package/src/webauthn.ts +98 -0
package/lib/user.d.ts CHANGED
@@ -1,59 +1,398 @@
1
- import { Empty } from '@bufbuild/protobuf';
2
- import GrpcConnect from './connect';
3
- import CoreClient from './core';
4
- import { CreateUserAndMembershipResponse, GetUserResponse, ListUsersResponse, UpdateUserResponse, CreateMembershipResponse, UpdateMembershipResponse, ListOrganizationUsersResponse, ResendInviteResponse } from './pkg/grpc/scalekit/v1/users/users_pb';
5
- import { CreateUserRequest, UpdateUserRequest as UpdateUserRequestType } from './types/user';
1
+ /**
2
+ * Client for managing users and their organization memberships.
3
+ *
4
+ * This client provides comprehensive user management capabilities including creating users,
5
+ * managing their memberships across organizations, updating user profiles, and handling
6
+ * invitation emails. Users can belong to multiple organizations with different roles.
7
+ *
8
+ * @example
9
+ * const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
10
+ * const userClient = scalekitClient.user;
11
+ *
12
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | User API Documentation}
13
+ */
14
+ import { Empty } from "@bufbuild/protobuf";
15
+ import GrpcConnect from "./connect";
16
+ import CoreClient from "./core";
17
+ import { CreateUserAndMembershipResponse, GetUserResponse, ListUsersResponse, UpdateUserResponse, CreateMembershipResponse, UpdateMembershipResponse, ListOrganizationUsersResponse, ResendInviteResponse } from "./pkg/grpc/scalekit/v1/users/users_pb";
18
+ import { CreateUserRequest, UpdateUserRequest as UpdateUserRequestType } from "./types/user";
6
19
  export default class UserClient {
7
20
  private readonly grpcConnect;
8
21
  private readonly coreClient;
9
22
  private client;
10
23
  constructor(grpcConnect: GrpcConnect, coreClient: CoreClient);
11
24
  /**
12
- * Create a new user and add them to an organization
13
- * @param {string} organizationId The organization id
14
- * @param {CreateUserRequest} options The user creation options
15
- * @returns {Promise<CreateUserAndMembershipResponse>} The created user
25
+ * Creates a new user and adds them as a member of an organization in a single operation.
26
+ *
27
+ * This is the primary method for user provisioning. It creates the user account and establishes
28
+ * their membership in the specified organization. Optionally sends an invitation email to the user
29
+ * with instructions to activate their account.
30
+ *
31
+ * @param {string} organizationId - The organization ID to add the user to
32
+ * @param {CreateUserRequest} options - User creation configuration
33
+ * @param {string} options.email - User's email address (required, must be unique)
34
+ * @param {object} [options.userProfile] - Optional user profile information
35
+ * @param {string} [options.userProfile.firstName] - User's first name
36
+ * @param {string} [options.userProfile.lastName] - User's last name
37
+ * @param {Record<string, string>} [options.metadata] - Custom metadata key-value pairs
38
+ * @param {boolean} [options.sendInvitationEmail=true] - Whether to send invitation email to the user
39
+ *
40
+ * @returns {Promise<CreateUserAndMembershipResponse>} Response containing:
41
+ * - user: The created user object with profile and membership details
42
+ *
43
+ * @throws {Error} When organizationId is missing or invalid
44
+ * @throws {Error} When email is missing or already exists
45
+ * @throws {Error} When user creation fails
46
+ *
47
+ * @example
48
+ * // Create user with profile and send invitation
49
+ * const response = await scalekitClient.user.createUserAndMembership(
50
+ * 'org_123456',
51
+ * {
52
+ * email: 'john.doe@company.com',
53
+ * userProfile: {
54
+ * firstName: 'John',
55
+ * lastName: 'Doe'
56
+ * },
57
+ * sendInvitationEmail: true,
58
+ * metadata: {
59
+ * department: 'Engineering',
60
+ * role: 'Developer'
61
+ * }
62
+ * }
63
+ * );
64
+ *
65
+ * console.log('User created:', response.user.id);
66
+ *
67
+ * @example
68
+ * // Create user without sending invitation
69
+ * const response = await scalekitClient.user.createUserAndMembership(
70
+ * 'org_123456',
71
+ * {
72
+ * email: 'jane.smith@company.com',
73
+ * sendInvitationEmail: false
74
+ * }
75
+ * );
76
+ *
77
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | Create User API}
78
+ * @see {@link createMembership} - Add existing user to another organization
79
+ * @see {@link resendInvite} - Resend invitation email to a user
16
80
  */
17
81
  createUserAndMembership(organizationId: string, options: CreateUserRequest): Promise<CreateUserAndMembershipResponse>;
18
82
  /**
19
- * Get a user by id
20
- * @param {string} userId The user id
21
- * @returns {Promise<GetUserResponse>} The user
83
+ * Retrieves comprehensive details about a specific user including their profile and memberships.
84
+ *
85
+ * Use this method to fetch complete user information including their organization memberships,
86
+ * roles, profile details, and custom metadata. This is useful for displaying user profiles,
87
+ * verifying user access, or checking membership status across organizations.
88
+ *
89
+ * @param {string} userId - The Scalekit-generated user identifier (format: "usr_...")
90
+ *
91
+ * @returns {Promise<GetUserResponse>} Response containing:
92
+ * - user: Complete user object with:
93
+ * - id: Scalekit's unique user identifier
94
+ * - email: User's email address
95
+ * - userProfile: Profile information (firstName, lastName)
96
+ * - memberships: Array of organization memberships with roles
97
+ * - metadata: Custom metadata key-value pairs
98
+ * - createTime: When the user was created
99
+ * - updateTime: When the user was last updated
100
+ *
101
+ * @throws {Error} If the user is not found or access is denied
102
+ *
103
+ * @example
104
+ * // Get user details
105
+ * const response = await scalekitClient.user.getUser('usr_123456');
106
+ * const user = response.user;
107
+ *
108
+ * console.log('User:', user.email);
109
+ * console.log('Name:', user.userProfile?.firstName, user.userProfile?.lastName);
110
+ * console.log('Organizations:', user.memberships?.length);
111
+ *
112
+ * @example
113
+ * // Check user's organization memberships
114
+ * const response = await scalekitClient.user.getUser(userId);
115
+ * const userOrgs = response.user.memberships?.map(m => m.organizationId) || [];
116
+ *
117
+ * if (userOrgs.includes('org_12345')) {
118
+ * console.log('User is a member of this organization');
119
+ * }
120
+ *
121
+ * @example
122
+ * // Display user profile in application
123
+ * app.get('/api/profile', async (req, res) => {
124
+ * const userId = req.user.id;
125
+ *
126
+ * try {
127
+ * const response = await scalekitClient.user.getUser(userId);
128
+ * res.json({
129
+ * email: response.user.email,
130
+ * profile: response.user.userProfile,
131
+ * organizations: response.user.memberships
132
+ * });
133
+ * } catch (error) {
134
+ * res.status(404).json({ error: 'User not found' });
135
+ * }
136
+ * });
137
+ *
138
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | Get User API}
139
+ * @see {@link listUsers} - List all users across the environment
140
+ * @see {@link listOrganizationUsers} - List users in a specific organization
22
141
  */
23
142
  getUser(userId: string): Promise<GetUserResponse>;
24
143
  /**
25
- * List users with pagination
26
- * @param {object} options The pagination options
27
- * @param {number} options.pageSize The page size
28
- * @param {string} options.pageToken The page token
29
- * @returns {Promise<ListUsersResponse>} The list of users
144
+ * Retrieves a paginated list of all users across your Scalekit environment.
145
+ *
146
+ * This method returns all users in your environment regardless of organization membership.
147
+ * It's useful for administrative oversight, auditing, user management interfaces, and
148
+ * searching across all users. Use pagination to efficiently handle large user bases.
149
+ *
150
+ * @param {object} [options] - Optional pagination parameters
151
+ * @param {number} [options.pageSize] - Number of users to return per page (valid range: 10-100, default: 10)
152
+ * @param {string} [options.pageToken] - Token for retrieving the next page of results.
153
+ * Obtained from the previous response's nextPageToken.
154
+ *
155
+ * @returns {Promise<ListUsersResponse>} Response containing:
156
+ * - users: Array of user objects with profiles and membership details
157
+ * - nextPageToken: Token for fetching the next page (empty if no more pages)
158
+ * - totalSize: Total number of users in the environment
159
+ *
160
+ * @example
161
+ * // List first page of users
162
+ * const response = await scalekitClient.user.listUsers({
163
+ * pageSize: 20
164
+ * });
165
+ *
166
+ * console.log('Users:', response.users.length);
167
+ * console.log('Total users:', response.totalSize);
168
+ *
169
+ * @example
170
+ * // Paginate through all users
171
+ * let pageToken = undefined;
172
+ * let allUsers = [];
173
+ *
174
+ * do {
175
+ * const response = await scalekitClient.user.listUsers({
176
+ * pageSize: 50,
177
+ * pageToken
178
+ * });
179
+ *
180
+ * allUsers.push(...response.users);
181
+ * pageToken = response.nextPageToken;
182
+ * } while (pageToken);
183
+ *
184
+ * console.log('Fetched all users:', allUsers.length);
185
+ *
186
+ * @example
187
+ * // Build user management dashboard
188
+ * app.get('/api/admin/users', async (req, res) => {
189
+ * const { pageSize = 25, pageToken } = req.query;
190
+ *
191
+ * try {
192
+ * const response = await scalekitClient.user.listUsers({
193
+ * pageSize: parseInt(pageSize),
194
+ * pageToken
195
+ * });
196
+ *
197
+ * res.json({
198
+ * users: response.users,
199
+ * nextPageToken: response.nextPageToken,
200
+ * total: response.totalSize
201
+ * });
202
+ * } catch (error) {
203
+ * res.status(500).json({ error: 'Failed to fetch users' });
204
+ * }
205
+ * });
206
+ *
207
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | List Users API}
208
+ * @see {@link listOrganizationUsers} - List users in a specific organization
209
+ * @see {@link getUser} - Get details of a specific user
30
210
  */
31
211
  listUsers(options?: {
32
212
  pageSize?: number;
33
213
  pageToken?: string;
34
214
  }): Promise<ListUsersResponse>;
35
215
  /**
36
- * Update a user
37
- * @param {string} userId The user id
38
- * @param {UpdateUserRequestType} options The update options
39
- * @returns {Promise<UpdateUserResponse>} The updated user
216
+ * Updates a user's profile information and custom metadata.
217
+ *
218
+ * Use this method to modify user profile details such as name or to update custom metadata
219
+ * associated with the user. Note that the user's email address and user ID cannot be changed.
220
+ * Only the fields you specify in the update object will be modified; all other fields remain unchanged.
221
+ *
222
+ * @param {string} userId - The Scalekit user identifier (format: "usr_...")
223
+ * @param {UpdateUserRequestType} options - Object containing fields to update:
224
+ * - userProfile?: Profile information to update
225
+ * - firstName?: User's first name
226
+ * - lastName?: User's last name
227
+ * - metadata?: Custom key-value pairs for storing additional data
228
+ *
229
+ * @returns {Promise<UpdateUserResponse>} Response containing:
230
+ * - user: The updated user object with all current values
231
+ *
232
+ * @throws {Error} If the user is not found or update fails
233
+ *
234
+ * @example
235
+ * // Update user's name
236
+ * const response = await scalekitClient.user.updateUser('usr_123456', {
237
+ * userProfile: {
238
+ * firstName: 'John',
239
+ * lastName: 'Smith'
240
+ * }
241
+ * });
242
+ *
243
+ * console.log('Updated user:', response.user.userProfile);
244
+ *
245
+ * @example
246
+ * // Update user metadata only
247
+ * await scalekitClient.user.updateUser('usr_123456', {
248
+ * metadata: {
249
+ * department: 'Engineering',
250
+ * title: 'Senior Developer',
251
+ * employeeId: 'EMP-12345'
252
+ * }
253
+ * });
254
+ *
255
+ * @example
256
+ * // Update both profile and metadata
257
+ * const response = await scalekitClient.user.updateUser('usr_123456', {
258
+ * userProfile: {
259
+ * firstName: 'Jane',
260
+ * lastName: 'Doe'
261
+ * },
262
+ * metadata: {
263
+ * phoneNumber: '+1-555-0123',
264
+ * timezone: 'America/New_York'
265
+ * }
266
+ * });
267
+ *
268
+ * @example
269
+ * // Update user profile via API endpoint
270
+ * app.patch('/api/users/:userId', async (req, res) => {
271
+ * const { userId } = req.params;
272
+ * const { firstName, lastName, metadata } = req.body;
273
+ *
274
+ * try {
275
+ * const response = await scalekitClient.user.updateUser(userId, {
276
+ * userProfile: { firstName, lastName },
277
+ * metadata
278
+ * });
279
+ * res.json({ user: response.user });
280
+ * } catch (error) {
281
+ * res.status(500).json({ error: 'Failed to update user' });
282
+ * }
283
+ * });
284
+ *
285
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | Update User API}
286
+ * @see {@link getUser} - Retrieve current user details
287
+ * @see {@link createUserAndMembership} - Create a new user
40
288
  */
41
289
  updateUser(userId: string, options: UpdateUserRequestType): Promise<UpdateUserResponse>;
42
290
  /**
43
- * Delete a user
44
- * @param {string} userId The user id
45
- * @returns {Promise<Empty>} Empty response
291
+ * Permanently deletes a user from your Scalekit environment.
292
+ *
293
+ * This operation removes the user's profile, all organization memberships, and related data
294
+ * across all organizations. This action is irreversible and cannot be undone. Use with extreme
295
+ * caution, especially in production environments. Consider deactivating users or removing specific
296
+ * memberships instead of full deletion for compliance and audit purposes.
297
+ *
298
+ * @param {string} userId - The Scalekit user identifier to delete (format: "usr_...")
299
+ *
300
+ * @returns {Promise<Empty>} Empty response on successful deletion
301
+ *
302
+ * @throws {Error} If the user is not found or deletion fails
303
+ *
304
+ * @example
305
+ * // Delete a user
306
+ * await scalekitClient.user.deleteUser('usr_123456');
307
+ * console.log('User deleted successfully');
308
+ *
309
+ * @example
310
+ * // Delete user with confirmation flow
311
+ * const confirmDelete = await askUserConfirmation(
312
+ * 'Are you sure you want to permanently delete this user? This action cannot be undone.'
313
+ * );
314
+ *
315
+ * if (confirmDelete) {
316
+ * try {
317
+ * await scalekitClient.user.deleteUser(userId);
318
+ * console.log('User permanently deleted');
319
+ * } catch (error) {
320
+ * console.error('Failed to delete user:', error);
321
+ * }
322
+ * }
323
+ *
324
+ *
325
+ *
326
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | Delete User API}
327
+ * @see {@link deleteMembership} - Remove user from a specific organization only
328
+ * @see {@link getUser} - Check if user exists before deletion
46
329
  */
47
330
  deleteUser(userId: string): Promise<Empty>;
48
331
  /**
49
- * Create a membership for a user in an organization
50
- * @param {string} organizationId The organization id
51
- * @param {string} userId The user id
52
- * @param {object} options The membership options
53
- * @param {string[]} options.roles The roles to assign
54
- * @param {Record<string, string>} options.metadata Optional metadata
55
- * @param {boolean} options.sendInvitationEmail Whether to send invitation email
56
- * @returns {Promise<CreateMembershipResponse>} The response with updated user
332
+ * Adds an existing user as a member of a new organization with specified roles.
333
+ *
334
+ * Use this method to grant organization access to users who already have accounts in your
335
+ * Scalekit environment. This is useful for adding users to additional organizations, managing
336
+ * multi-tenant access, or onboarding existing users to new teams. Optionally sends an invitation
337
+ * email to notify the user of their new organization access.
338
+ *
339
+ * @param {string} organizationId - The organization ID to add the user to (format: "org_...")
340
+ * @param {string} userId - The user ID to add as a member (format: "usr_...")
341
+ * @param {object} [options={}] - Optional membership configuration
342
+ * @param {string[]} [options.roles] - Array of role names to assign to the user
343
+ * (e.g., ['admin', 'editor', 'viewer'])
344
+ * @param {Record<string, string>} [options.metadata] - Custom metadata key-value pairs
345
+ * for this specific membership
346
+ * @param {boolean} [options.sendInvitationEmail=true] - Whether to send invitation email
347
+ * notifying the user of new access
348
+ *
349
+ * @returns {Promise<CreateMembershipResponse>} Response containing:
350
+ * - user: The updated user object including the new membership details
351
+ *
352
+ * @throws {Error} When the user or organization is not found
353
+ * @throws {Error} When the user is already a member of the organization
354
+ *
355
+ * @example
356
+ * // Add user to organization with admin role
357
+ * const response = await scalekitClient.user.createMembership(
358
+ * 'org_123456',
359
+ * 'usr_789012',
360
+ * {
361
+ * roles: ['admin'],
362
+ * sendInvitationEmail: true
363
+ * }
364
+ * );
365
+ *
366
+ * console.log('Membership created:', response.user.memberships);
367
+ *
368
+ * @example
369
+ * // Add user with multiple roles and metadata
370
+ * await scalekitClient.user.createMembership(
371
+ * 'org_123456',
372
+ * 'usr_789012',
373
+ * {
374
+ * roles: ['member', 'billing_admin'],
375
+ * metadata: {
376
+ * department: 'Finance',
377
+ * accessLevel: 'full'
378
+ * },
379
+ * sendInvitationEmail: true
380
+ * }
381
+ * );
382
+ *
383
+ * @example
384
+ * // Add user to organization without sending email
385
+ * await scalekitClient.user.createMembership(
386
+ * 'org_123456',
387
+ * 'usr_789012',
388
+ * { sendInvitationEmail: false }
389
+ * );
390
+
391
+ *
392
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | Create Membership API}
393
+ * @see {@link createUserAndMembership} - Create new user with initial membership
394
+ * @see {@link updateMembership} - Modify existing membership roles
395
+ * @see {@link deleteMembership} - Remove user from organization
57
396
  */
58
397
  createMembership(organizationId: string, userId: string, options?: {
59
398
  roles?: string[];
@@ -61,42 +400,221 @@ export default class UserClient {
61
400
  sendInvitationEmail?: boolean;
62
401
  }): Promise<CreateMembershipResponse>;
63
402
  /**
64
- * Delete a user's membership from an organization
65
- * @param {string} organizationId The organization id
66
- * @param {string} userId The user id
67
- * @returns {Promise<Empty>} Empty response
403
+ * Removes a user's membership from a specific organization.
404
+ *
405
+ * This operation revokes the user's access to the specified organization while keeping their
406
+ * user account intact. The user remains in the system and can still access other organizations
407
+ * they're a member of. This is the recommended approach when you want to remove access to a
408
+ * specific organization without deleting the entire user account. This action is irreversible.
409
+ *
410
+ * @param {string} organizationId - The organization ID to remove the user from (format: "org_...")
411
+ * @param {string} userId - The user ID to remove (format: "usr_...")
412
+ *
413
+ * @returns {Promise<Empty>} Empty response on successful removal
414
+ *
415
+ * @throws {Error} If the user or organization is not found
416
+ * @throws {Error} If the membership doesn't exist
417
+ *
418
+ * @example
419
+ * // Remove user from organization
420
+ * await scalekitClient.user.deleteMembership('org_123456', 'usr_789012');
421
+ * console.log('User removed from organization');
422
+ *
423
+ * @example
424
+ * // Remove user with confirmation
425
+ * const confirmRemoval = await askUserConfirmation(
426
+ * 'Remove this user from the organization?'
427
+ * );
428
+ *
429
+ * if (confirmRemoval) {
430
+ * try {
431
+ * await scalekitClient.user.deleteMembership(organizationId, userId);
432
+ * console.log('User access revoked');
433
+ * } catch (error) {
434
+ * console.error('Failed to remove user:', error);
435
+ * }
436
+ * }
437
+ *
438
+ *
439
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | Delete Membership API}
440
+ * @see {@link deleteUser} - Permanently delete user from all organizations
441
+ * @see {@link createMembership} - Add user to an organization
442
+ * @see {@link updateMembership} - Modify user's roles in organization
68
443
  */
69
444
  deleteMembership(organizationId: string, userId: string): Promise<Empty>;
70
445
  /**
71
- * Update a user's membership in an organization
72
- * @param {string} organizationId The organization id
73
- * @param {string} userId The user id
74
- * @param {object} options The update options
75
- * @param {string[]} options.roles The roles to assign
76
- * @param {Record<string, string>} options.metadata Optional metadata
77
- * @returns {Promise<UpdateMembershipResponse>} The response with updated user
446
+ * Updates a user's roles and metadata within a specific organization.
447
+ *
448
+ * Use this method to modify a user's permissions by changing their assigned roles or to
449
+ * update membership-specific metadata. This allows you to adjust user access levels,
450
+ * promote/demote users, or track organization-specific information without affecting
451
+ * the user's memberships in other organizations.
452
+ *
453
+ * @param {string} organizationId - The organization ID where the membership exists (format: "org_...")
454
+ * @param {string} userId - The user ID whose membership to update (format: "usr_...")
455
+ * @param {object} [options={}] - Fields to update
456
+ * @param {string[]} [options.roles] - Array of role names to assign (replaces existing roles)
457
+ * (e.g., ['admin'], ['member', 'billing'])
458
+ * @param {Record<string, string>} [options.metadata] - Custom metadata key-value pairs
459
+ * specific to this membership
460
+ *
461
+ * @returns {Promise<UpdateMembershipResponse>} Response containing:
462
+ * - user: The updated user object with modified membership details
463
+ *
464
+ * @throws {Error} If the user, organization, or membership is not found
465
+ *
466
+ * @example
467
+ * // Promote user to admin
468
+ * const response = await scalekitClient.user.updateMembership(
469
+ * 'org_123456',
470
+ * 'usr_789012',
471
+ * { roles: ['admin'] }
472
+ * );
473
+ *
474
+ * console.log('User promoted:', response.user.memberships);
475
+ *
476
+ * @example
477
+ * // Assign multiple roles
478
+ * await scalekitClient.user.updateMembership(
479
+ * 'org_123456',
480
+ * 'usr_789012',
481
+ * { roles: ['member', 'billing_admin', 'support'] }
482
+ * );
483
+ *
484
+ * @example
485
+ * // Update membership metadata
486
+ * await scalekitClient.user.updateMembership(
487
+ * 'org_123456',
488
+ * 'usr_789012',
489
+ * {
490
+ * metadata: {
491
+ * department: 'Engineering',
492
+ * team: 'Backend',
493
+ * startDate: '2025-01-01'
494
+ * }
495
+ * }
496
+ * );
497
+ *
498
+ * @example
499
+ * // Update both roles and metadata
500
+ * await scalekitClient.user.updateMembership(
501
+ * 'org_123456',
502
+ * 'usr_789012',
503
+ * {
504
+ * roles: ['team_lead', 'developer'],
505
+ * metadata: {
506
+ * level: 'senior',
507
+ * permissions: 'full'
508
+ * }
509
+ * }
510
+ * );
511
+ *
512
+ *
513
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | Update Membership API}
514
+ * @see {@link createMembership} - Add user to organization
515
+ * @see {@link deleteMembership} - Remove user from organization
516
+ * @see {@link getUser} - View current user roles and memberships
78
517
  */
79
518
  updateMembership(organizationId: string, userId: string, options?: {
80
519
  roles?: string[];
81
520
  metadata?: Record<string, string>;
82
521
  }): Promise<UpdateMembershipResponse>;
83
522
  /**
84
- * List users in an organization with pagination
85
- * @param {string} organizationId The organization id
86
- * @param {object} options The pagination options
87
- * @param {number} options.pageSize The page size
88
- * @param {string} options.pageToken The page token
89
- * @returns {Promise<ListOrganizationUsersResponse>} The list of users in the organization
523
+ * Retrieves a paginated list of all users who are members of a specific organization.
524
+ *
525
+ * This method returns all users with access to the specified organization, including their
526
+ * roles, membership details, and profiles. This is useful for displaying team member lists,
527
+ * managing organization access, or building user management interfaces. Use pagination to
528
+ * efficiently handle organizations with large member counts.
529
+ *
530
+ * @param {string} organizationId - The organization ID to list users from (format: "org_...")
531
+ * @param {object} [options] - Optional pagination parameters
532
+ * @param {number} [options.pageSize] - Number of users to return per page (valid range: 1-100)
533
+ * @param {string} [options.pageToken] - Token for retrieving the next page of results.
534
+ * Obtained from the previous response's nextPageToken.
535
+ *
536
+ * @returns {Promise<ListOrganizationUsersResponse>} Response containing:
537
+ * - users: Array of user objects with profiles, roles, and membership details
538
+ * - nextPageToken: Token for fetching the next page (empty if no more pages)
539
+ * - totalSize: Total number of users in the organization
540
+ *
541
+ * @throws {Error} If the organization is not found
542
+ *
543
+ * @example
544
+ * // List first page of organization users
545
+ * const response = await scalekitClient.user.listOrganizationUsers('org_123456', {
546
+ * pageSize: 25
547
+ * });
548
+ *
549
+ * console.log('Organization users:', response.users.length);
550
+ * console.log('Total members:', response.totalSize);
551
+ *
552
+ * @example
553
+ * // Paginate through all organization members
554
+ * let pageToken = undefined;
555
+ * let allMembers = [];
556
+ *
557
+ * do {
558
+ * const response = await scalekitClient.user.listOrganizationUsers(
559
+ * 'org_123456',
560
+ * { pageSize: 50, pageToken }
561
+ * );
562
+ *
563
+ * allMembers.push(...response.users);
564
+ * pageToken = response.nextPageToken;
565
+ * } while (pageToken);
566
+ *
567
+ * console.log('All organization members:', allMembers.length);
568
+ *
569
+ *
570
+ * console.log('Organization admins:', admins.length);
571
+ *
572
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | List Organization Users API}
573
+ * @see {@link listUsers} - List all users across the environment
574
+ * @see {@link getUser} - Get details of a specific user
575
+ * @see {@link createMembership} - Add user to organization
90
576
  */
91
577
  listOrganizationUsers(organizationId: string, options?: {
92
578
  pageSize?: number;
93
579
  pageToken?: string;
94
580
  }): Promise<ListOrganizationUsersResponse>;
95
581
  /**
96
- * Resend an invitation to a user
97
- * @param {string} organizationId The organization id
98
- * @param {string} userId The user id
99
- * @returns {Promise<ResendInviteResponse>} The response with the invite
582
+ * Resends an invitation email to a user for a specific organization.
583
+ *
584
+ * Use this method when a user hasn't received or has lost their invitation email. If the
585
+ * original invitation is still valid, a reminder email will be sent. If the invitation has
586
+ * expired, a new invitation with a secure magic link will be created and sent. This is useful
587
+ * for helping users who need to complete their account setup or activate their organization access.
588
+ *
589
+ * @param {string} organizationId - The organization ID for which to resend the invite (format: "org_...")
590
+ * @param {string} userId - The user ID who should receive the invite (format: "usr_...")
591
+ *
592
+ * @returns {Promise<ResendInviteResponse>} Response containing:
593
+ * - invite: The invitation details including status and expiration
594
+ *
595
+ * @throws {Error} When organizationId is missing or invalid
596
+ * @throws {Error} When userId is missing or invalid
597
+ * @throws {Error} When the user or organization is not found
598
+ * @throws {Error} When the membership doesn't exist
599
+ *
600
+ * @example
601
+ * // Resend invitation to a user
602
+ * const response = await scalekitClient.user.resendInvite('org_123456', 'usr_789012');
603
+ * console.log('Invitation resent:', response.invite);
604
+ *
605
+ * @example
606
+ * // Resend invitation with error handling
607
+ * try {
608
+ * await scalekitClient.user.resendInvite(organizationId, userId);
609
+ * console.log('Invitation email sent successfully');
610
+ * } catch (error) {
611
+ * console.error('Failed to resend invitation:', error);
612
+ * }
613
+ *
614
+ * @see {@link https://docs.scalekit.com/apis/#tag/users | Resend Invite API}
615
+ * @see {@link createUserAndMembership} - Create user with initial invitation
616
+ * @see {@link createMembership} - Add user to organization with invitation option
617
+ * @see {@link getUser} - Check user's invitation status
100
618
  */
101
619
  resendInvite(organizationId: string, userId: string): Promise<ResendInviteResponse>;
102
620
  }