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