@scalekit-sdk/node 2.2.0 → 2.2.2

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 (62) hide show
  1. package/{reference.md → REFERENCE.md} +530 -77
  2. package/lib/core.js +1 -1
  3. package/package.json +9 -3
  4. package/.github/dependabot.yml +0 -10
  5. package/.nvmrc +0 -1
  6. package/buf.gen.yaml +0 -20
  7. package/jest.config.js +0 -15
  8. package/src/auth.ts +0 -99
  9. package/src/connect.ts +0 -32
  10. package/src/connection.ts +0 -267
  11. package/src/constants/user.ts +0 -22
  12. package/src/core.ts +0 -139
  13. package/src/directory.ts +0 -431
  14. package/src/domain.ts +0 -273
  15. package/src/errors/base-exception.ts +0 -263
  16. package/src/errors/index.ts +0 -3
  17. package/src/errors/specific-exceptions.ts +0 -88
  18. package/src/index.ts +0 -10
  19. package/src/organization.ts +0 -571
  20. package/src/passwordless.ts +0 -139
  21. package/src/permission.ts +0 -310
  22. package/src/pkg/grpc/buf/validate/validate_pb.ts +0 -28
  23. package/src/pkg/grpc/google/api/annotations_pb.ts +0 -28
  24. package/src/pkg/grpc/google/api/field_behavior_pb.ts +0 -28
  25. package/src/pkg/grpc/google/api/visibility_pb.ts +0 -28
  26. package/src/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.ts +0 -28
  27. package/src/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.ts +0 -257
  28. package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +0 -836
  29. package/src/pkg/grpc/scalekit/v1/auth/passwordless_pb.ts +0 -264
  30. package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +0 -794
  31. package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +0 -452
  32. package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +0 -2645
  33. package/src/pkg/grpc/scalekit/v1/directories/directories_pb.ts +0 -1393
  34. package/src/pkg/grpc/scalekit/v1/domains/domains_pb.ts +0 -599
  35. package/src/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.ts +0 -311
  36. package/src/pkg/grpc/scalekit/v1/options/options_pb.ts +0 -200
  37. package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +0 -1141
  38. package/src/pkg/grpc/scalekit/v1/roles/roles_pb.ts +0 -1491
  39. package/src/pkg/grpc/scalekit/v1/sessions/sessions_pb.ts +0 -497
  40. package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +0 -1404
  41. package/src/role.ts +0 -463
  42. package/src/scalekit.ts +0 -800
  43. package/src/session.ts +0 -323
  44. package/src/types/auth.ts +0 -73
  45. package/src/types/organization.ts +0 -12
  46. package/src/types/scalekit.ts +0 -50
  47. package/src/types/user.ts +0 -21
  48. package/src/user.ts +0 -829
  49. package/src/webauthn.ts +0 -99
  50. package/tests/README.md +0 -25
  51. package/tests/connection.test.ts +0 -42
  52. package/tests/directory.test.ts +0 -46
  53. package/tests/domain.test.ts +0 -293
  54. package/tests/organization.test.ts +0 -81
  55. package/tests/passwordless.test.ts +0 -108
  56. package/tests/permission.test.ts +0 -399
  57. package/tests/role.test.ts +0 -323
  58. package/tests/scalekit.test.ts +0 -104
  59. package/tests/setup.ts +0 -34
  60. package/tests/users.test.ts +0 -168
  61. package/tests/utils/test-data.ts +0 -490
  62. package/tsconfig.json +0 -19
package/src/role.ts DELETED
@@ -1,463 +0,0 @@
1
- import type { MessageShape } from "@bufbuild/protobuf";
2
- import { create } from "@bufbuild/protobuf";
3
- import { EmptySchema } from "@bufbuild/protobuf/wkt";
4
- import type { Client } from "@connectrpc/connect";
5
- import GrpcConnect from "./connect";
6
- import CoreClient from "./core";
7
- import { RolesService } from "./pkg/grpc/scalekit/v1/roles/roles_pb";
8
- import {
9
- CreateRoleRequest,
10
- CreateRoleResponse,
11
- UpdateRoleRequest,
12
- UpdateRoleResponse,
13
- GetRoleRequest,
14
- GetRoleResponse,
15
- ListRolesRequest,
16
- ListRolesResponse,
17
- DeleteRoleRequest,
18
- CreateOrganizationRoleRequest,
19
- CreateOrganizationRoleResponse,
20
- UpdateOrganizationRoleRequest,
21
- UpdateOrganizationRoleResponse,
22
- GetOrganizationRoleRequest,
23
- GetOrganizationRoleResponse,
24
- ListOrganizationRolesRequest,
25
- ListOrganizationRolesResponse,
26
- DeleteOrganizationRoleRequest,
27
- DeleteRoleRequestSchema,
28
- DeleteOrganizationRoleRequestSchema,
29
- GetRoleUsersCountRequest,
30
- GetRoleUsersCountResponse,
31
- GetOrganizationRoleUsersCountRequest,
32
- GetOrganizationRoleUsersCountResponse,
33
- UpdateDefaultOrganizationRolesRequest,
34
- UpdateDefaultOrganizationRolesResponse,
35
- DeleteOrganizationRoleBaseRequest,
36
- CreateRole,
37
- UpdateRole,
38
- CreateOrganizationRole,
39
- } from "./pkg/grpc/scalekit/v1/roles/roles_pb";
40
-
41
- /**
42
- * Client for managing roles at both environment and organization levels.
43
- *
44
- * Roles define sets of permissions that control user access to resources and operations.
45
- * This client provides comprehensive role management including role hierarchies, permission
46
- * inheritance, and both environment-wide and organization-specific roles.
47
- *
48
- * **Environment Roles**: Available across your entire Scalekit environment, shared by all organizations
49
- * **Organization Roles**: Scoped to specific organizations for multi-tenant isolation. These are additional custom roles
50
- * that are only applicable for that organization beyond the Environment Roles that are applicable for all organizations.
51
- *
52
- * @example
53
- * const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
54
- * const roleClient = scalekitClient.role;
55
- *
56
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Role API Documentation}
57
- */
58
- export default class RoleClient {
59
- private client: Client<typeof RolesService>;
60
-
61
- constructor(
62
- private readonly grpcConnect: GrpcConnect,
63
- private readonly coreClient: CoreClient
64
- ) {
65
- this.client = this.grpcConnect.createClient(RolesService);
66
- }
67
-
68
- /**
69
- * Creates a new environment-level role with specified permissions.
70
- *
71
- * Environment roles are available across all organizations in your environment. Use this to
72
- * establish foundational access control structures, create role hierarchies, or define granular
73
- * permission sets that can be reused across organizations.
74
- *
75
- * @param {CreateRole} role - Role creation object containing:
76
- * - name: Unique role identifier (alphanumeric with underscores, 1-64 chars)
77
- * - displayName: Human-readable name for display
78
- * - description: Purpose and scope of the role
79
- * - permissions: Array of permission strings
80
- * - baseRole?: Optional parent role for permission inheritance
81
- *
82
- * @returns {Promise<CreateRoleResponse>} The created role with metadata
83
- *
84
- * @example
85
- * // Create a basic role
86
- * const response = await scalekitClient.role.createRole({
87
- * name: 'content_editor',
88
- * displayName: 'Content Editor',
89
- * description: 'Can create and edit content',
90
- * permissions: ['content:read', 'content:write', 'content:edit']
91
- * });
92
- *
93
- * @example
94
- * // Create role with inheritance
95
- * await scalekitClient.role.createRole({
96
- * name: 'senior_editor',
97
- * displayName: 'Senior Editor',
98
- * description: 'Editor with publishing rights',
99
- * baseRole: 'content_editor',
100
- * permissions: ['content:publish', 'content:delete']
101
- * });
102
- *
103
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Create Role API}
104
- */
105
- async createRole(role: CreateRole): Promise<CreateRoleResponse> {
106
- return this.coreClient.connectExec(this.client.createRole, { role });
107
- }
108
-
109
- /**
110
- * Retrieves complete information for a specific environment role.
111
- *
112
- * @param {string} roleName - Unique role identifier (alphanumeric with underscores, 1-64 chars)
113
- *
114
- * @returns {Promise<GetRoleResponse>} Role details including permissions and inheritance
115
- *
116
- * @example
117
- * const response = await scalekitClient.role.getRole('content_editor');
118
- * console.log('Role:', response.role.displayName);
119
- * console.log('Permissions:', response.role.permissions);
120
- *
121
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Get Role API}
122
- */
123
- async getRole(roleName: string): Promise<GetRoleResponse> {
124
- return this.coreClient.connectExec(this.client.getRole, { roleName });
125
- }
126
-
127
- /**
128
- * Lists all environment-level roles available in your Scalekit environment.
129
- *
130
- * @returns {Promise<ListRolesResponse>} Array of all roles with their metadata
131
- *
132
- * @example
133
- * const response = await scalekitClient.role.listRoles();
134
- * response.roles.forEach(role => {
135
- * console.log(`${role.displayName}: ${role.permissions.length} permissions`);
136
- * });
137
- *
138
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | List Roles API}
139
- */
140
- async listRoles(): Promise<ListRolesResponse> {
141
- return this.coreClient.connectExec(this.client.listRoles, {});
142
- }
143
-
144
- /**
145
- * Updates an existing environment role's properties and permissions.
146
- *
147
- * Only specified fields are updated. The new permission list replaces existing permissions.
148
- *
149
- * @param {string} roleName - Role to update
150
- * @param {UpdateRole} role - Updated role properties
151
- *
152
- * @returns {Promise<UpdateRoleResponse>} Updated role details
153
- *
154
- * @example
155
- * await scalekitClient.role.updateRole('content_editor', {
156
- * displayName: 'Content Editor (Updated)',
157
- * permissions: ['content:read', 'content:write', 'content:edit', 'content:review']
158
- * });
159
- *
160
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Update Role API}
161
- */
162
- async updateRole(
163
- roleName: string,
164
- role: UpdateRole
165
- ): Promise<UpdateRoleResponse> {
166
- return this.coreClient.connectExec(this.client.updateRole, {
167
- roleName,
168
- role,
169
- });
170
- }
171
-
172
- /**
173
- * Deletes an environment role and reassigns its users to another role.
174
- *
175
- * Cannot delete if dependent roles exist. Users must be reassigned before deletion.
176
- * This operation is irreversible.
177
- *
178
- * @param {string} roleName - Role to delete
179
- * @param {string} [reassignRoleName] - Target role for user migration
180
- *
181
- * @returns {Promise<MessageShape<typeof EmptySchema>>} Empty response on success
182
- *
183
- * @example
184
- * await scalekitClient.role.deleteRole('old_role', 'new_role');
185
- *
186
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Delete Role API}
187
- */
188
- async deleteRole(
189
- roleName: string,
190
- reassignRoleName?: string
191
- ): Promise<MessageShape<typeof EmptySchema>> {
192
- const request = create(DeleteRoleRequestSchema, {
193
- roleName,
194
- reassignRoleName,
195
- });
196
-
197
- return this.coreClient.connectExec(this.client.deleteRole, request);
198
- }
199
-
200
- /**
201
- * Gets the number of users assigned to an environment role.
202
- *
203
- * Useful for capacity planning, security auditing, and impact assessment before role changes.
204
- *
205
- * @param {string} roleName - Role to count users for
206
- *
207
- * @returns {Promise<GetRoleUsersCountResponse>} Total user count (direct and inherited)
208
- *
209
- * @example
210
- * const response = await scalekitClient.role.getRoleUsersCount('admin');
211
- * console.log(`${response.count} users have admin role`);
212
- *
213
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Get Role User Count API}
214
- */
215
- async getRoleUsersCount(
216
- roleName: string
217
- ): Promise<GetRoleUsersCountResponse> {
218
- return this.coreClient.connectExec(this.client.getRoleUsersCount, {
219
- roleName,
220
- });
221
- }
222
-
223
- // Organization Role CRUD Methods
224
-
225
- /**
226
- * Creates a new organization-specific role with custom permissions.
227
- *
228
- * Organization roles are scoped to a specific organization for multi-tenant isolation.
229
- * Use this for organization-specific access control and compartmentalized role management.
230
- *
231
- * @param {string} orgId - Organization identifier (format: "org_...")
232
- * @param {CreateOrganizationRole} role - Role configuration containing:
233
- * - name: Unique role identifier within the organization
234
- * - displayName: Human-readable name
235
- * - description: Purpose and scope
236
- * - permissions: Organization-specific permission array
237
- * - baseRole?: Parent role for inheritance
238
- *
239
- * @returns {Promise<CreateOrganizationRoleResponse>} Created organization role
240
- *
241
- * @example
242
- * await scalekitClient.role.createOrganizationRole('org_123456', {
243
- * name: 'department_lead',
244
- * displayName: 'Department Lead',
245
- * description: 'Manages department members',
246
- * permissions: ['dept:members:read', 'dept:members:invite']
247
- * });
248
- *
249
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Create Organization Role API}
250
- */
251
- async createOrganizationRole(
252
- orgId: string,
253
- role: CreateOrganizationRole
254
- ): Promise<CreateOrganizationRoleResponse> {
255
- return this.coreClient.connectExec(this.client.createOrganizationRole, {
256
- orgId,
257
- role,
258
- });
259
- }
260
-
261
- /**
262
- * Retrieves details for a specific organization role.
263
- *
264
- * @param {string} orgId - Organization identifier
265
- * @param {string} roleName - Role name to retrieve
266
- *
267
- * @returns {Promise<GetOrganizationRoleResponse>} Organization role details
268
- *
269
- * @example
270
- * const response = await scalekitClient.role.getOrganizationRole(
271
- * 'org_123456',
272
- * 'department_lead'
273
- * );
274
- * console.log('Permissions:', response.role.permissions);
275
- *
276
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Get Organization Role API}
277
- */
278
- async getOrganizationRole(
279
- orgId: string,
280
- roleName: string
281
- ): Promise<GetOrganizationRoleResponse> {
282
- return this.coreClient.connectExec(this.client.getOrganizationRole, {
283
- orgId,
284
- roleName,
285
- });
286
- }
287
-
288
- /**
289
- * Lists all roles available to an organization (environment + organization-specific).
290
- *
291
- * Returns both environment-level roles and organization-scoped roles.
292
- *
293
- * @param {string} orgId - Organization identifier
294
- *
295
- * @returns {Promise<ListOrganizationRolesResponse>} Array of available roles
296
- *
297
- * @example
298
- * const response = await scalekitClient.role.listOrganizationRoles('org_123456');
299
- * response.roles.forEach(role => {
300
- * console.log(`${role.displayName} (${role.scope})`);
301
- * });
302
- *
303
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | List Organization Roles API}
304
- */
305
- async listOrganizationRoles(
306
- orgId: string
307
- ): Promise<ListOrganizationRolesResponse> {
308
- return this.coreClient.connectExec(this.client.listOrganizationRoles, {
309
- orgId,
310
- });
311
- }
312
-
313
- /**
314
- * Updates an organization role's properties and permissions.
315
- *
316
- * Only specified fields are updated. New permissions replace existing ones.
317
- *
318
- * @param {string} orgId - Organization identifier
319
- * @param {string} roleName - Role to update
320
- * @param {UpdateRole} role - Updated role properties
321
- *
322
- * @returns {Promise<UpdateOrganizationRoleResponse>} Updated role
323
- *
324
- * @example
325
- * await scalekitClient.role.updateOrganizationRole('org_123456', 'department_lead', {
326
- * permissions: ['dept:members:read', 'dept:members:invite', 'dept:members:remove']
327
- * });
328
- *
329
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Update Organization Role API}
330
- */
331
- async updateOrganizationRole(
332
- orgId: string,
333
- roleName: string,
334
- role: UpdateRole
335
- ): Promise<UpdateOrganizationRoleResponse> {
336
- return this.coreClient.connectExec(this.client.updateOrganizationRole, {
337
- orgId,
338
- roleName,
339
- role,
340
- });
341
- }
342
-
343
- /**
344
- * Deletes an organization role and reassigns its users.
345
- *
346
- * Cannot delete if dependent roles exist. Users must be reassigned. Operation is irreversible.
347
- *
348
- * @param {string} orgId - Organization identifier
349
- * @param {string} roleName - Role to delete
350
- * @param {string} [reassignRoleName] - Target role for user migration
351
- *
352
- * @returns {Promise<MessageShape<typeof EmptySchema>>} Empty response on success
353
- *
354
- * @example
355
- * await scalekitClient.role.deleteOrganizationRole(
356
- * 'org_123456',
357
- * 'old_role',
358
- * 'new_role'
359
- * );
360
- *
361
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Delete Organization Role API}
362
- */
363
- async deleteOrganizationRole(
364
- orgId: string,
365
- roleName: string,
366
- reassignRoleName?: string
367
- ): Promise<MessageShape<typeof EmptySchema>> {
368
- const request = create(DeleteOrganizationRoleRequestSchema, {
369
- orgId,
370
- roleName,
371
- reassignRoleName,
372
- });
373
-
374
- return this.coreClient.connectExec(
375
- this.client.deleteOrganizationRole,
376
- request
377
- );
378
- }
379
-
380
- /**
381
- * Gets the number of users assigned to an organization role.
382
- *
383
- * @param {string} orgId - Organization identifier
384
- * @param {string} roleName - Role to count users for
385
- *
386
- * @returns {Promise<GetOrganizationRoleUsersCountResponse>} User count
387
- *
388
- * @example
389
- * const response = await scalekitClient.role.getOrganizationRoleUsersCount(
390
- * 'org_123456',
391
- * 'admin'
392
- * );
393
- * console.log(`${response.count} admins in this organization`);
394
- *
395
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Get Organization Role User Count API}
396
- */
397
- async getOrganizationRoleUsersCount(
398
- orgId: string,
399
- roleName: string
400
- ): Promise<GetOrganizationRoleUsersCountResponse> {
401
- return this.coreClient.connectExec(
402
- this.client.getOrganizationRoleUsersCount,
403
- {
404
- orgId,
405
- roleName,
406
- }
407
- );
408
- }
409
-
410
- /**
411
- * Sets the default role automatically assigned to new organization members.
412
- * This is the role that is by default assigned to every new user added to this organization.
413
- *
414
- * Affects all new user invitations and memberships within the organization.
415
- *
416
- * @param {string} orgId - Organization identifier
417
- * @param {string} defaultMemberRole - Role name to assign by default
418
- *
419
- * @returns {Promise<UpdateDefaultOrganizationRolesResponse>} Updated configuration
420
- *
421
- * @example
422
- * await scalekitClient.role.updateDefaultOrganizationRoles('org_123456', 'member');
423
- *
424
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Update Default Organization Roles API}
425
- */
426
- async updateDefaultOrganizationRoles(
427
- orgId: string,
428
- defaultMemberRole: string
429
- ): Promise<UpdateDefaultOrganizationRolesResponse> {
430
- return this.coreClient.connectExec(
431
- this.client.updateDefaultOrganizationRoles,
432
- {
433
- orgId,
434
- defaultMemberRole,
435
- }
436
- );
437
- }
438
-
439
- /**
440
- * Removes a role's inheritance relationship, eliminating inherited permissions from base role.
441
- *
442
- * Role retains only directly assigned permissions after removal. This action cannot be undone.
443
- *
444
- * @param {string} orgId - Organization identifier
445
- * @param {string} roleName - Role to remove inheritance from
446
- *
447
- * @returns {Promise<MessageShape<typeof EmptySchema>>} Empty response on success
448
- *
449
- * @example
450
- * await scalekitClient.role.deleteOrganizationRoleBase('org_123456', 'custom_role');
451
- *
452
- * @see {@link https://docs.scalekit.com/apis/#tag/roles | Delete Organization Role Base API}
453
- */
454
- async deleteOrganizationRoleBase(
455
- orgId: string,
456
- roleName: string
457
- ): Promise<MessageShape<typeof EmptySchema>> {
458
- return this.coreClient.connectExec(this.client.deleteOrganizationRoleBase, {
459
- orgId,
460
- roleName,
461
- });
462
- }
463
- }