@scalekit-sdk/node 2.1.6 → 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 (92) 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 +407 -40
  18. package/lib/organization.js +433 -49
  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/organizations/organizations_connect.d.ts +6 -6
  45. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.js +5 -5
  46. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.d.ts +19 -30
  47. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js +22 -31
  48. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js.map +1 -1
  49. package/lib/pkg/grpc/scalekit/v1/users/users_pb.d.ts +2 -2
  50. package/lib/pkg/grpc/scalekit/v1/users/users_pb.js +1 -1
  51. package/lib/pkg/grpc/scalekit/v1/users/users_pb.js.map +1 -1
  52. package/lib/role.d.ts +252 -56
  53. package/lib/role.js +262 -62
  54. package/lib/role.js.map +1 -1
  55. package/lib/scalekit.d.ts +323 -54
  56. package/lib/scalekit.js +354 -76
  57. package/lib/scalekit.js.map +1 -1
  58. package/lib/session.d.ts +235 -22
  59. package/lib/session.js +237 -24
  60. package/lib/session.js.map +1 -1
  61. package/lib/types/organization.d.ts +3 -0
  62. package/lib/user.d.ts +571 -53
  63. package/lib/user.js +598 -89
  64. package/lib/user.js.map +1 -1
  65. package/lib/webauthn.d.ts +33 -0
  66. package/lib/webauthn.js +80 -0
  67. package/lib/webauthn.js.map +1 -0
  68. package/package.json +2 -2
  69. package/src/auth.ts +53 -19
  70. package/src/connection.ts +237 -62
  71. package/src/core.ts +39 -33
  72. package/src/directory.ts +356 -98
  73. package/src/domain.ts +215 -68
  74. package/src/organization.ts +506 -105
  75. package/src/permission.ts +234 -88
  76. package/src/pkg/grpc/scalekit/v1/auth/auth_connect.ts +3 -3
  77. package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +24 -24
  78. package/src/pkg/grpc/scalekit/v1/auth/webauthn_connect.ts +89 -0
  79. package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +1263 -0
  80. package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +217 -0
  81. package/src/pkg/grpc/scalekit/v1/connections/connections_connect.ts +1 -10
  82. package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +42 -129
  83. package/src/pkg/grpc/scalekit/v1/organizations/organizations_connect.ts +6 -6
  84. package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +28 -43
  85. package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +3 -3
  86. package/src/role.ts +336 -136
  87. package/src/scalekit.ts +478 -149
  88. package/src/session.ts +266 -63
  89. package/src/types/organization.ts +4 -0
  90. package/src/user.ts +675 -168
  91. package/src/webauthn.ts +98 -0
  92. package/tests/organization.test.ts +16 -0
package/lib/role.d.ts CHANGED
@@ -1,104 +1,300 @@
1
- import { Empty } from '@bufbuild/protobuf';
2
- import GrpcConnect from './connect';
3
- import CoreClient from './core';
4
- import { CreateRoleResponse, UpdateRoleResponse, GetRoleResponse, ListRolesResponse, CreateOrganizationRoleResponse, UpdateOrganizationRoleResponse, GetOrganizationRoleResponse, ListOrganizationRolesResponse, GetRoleUsersCountResponse, GetOrganizationRoleUsersCountResponse, UpdateDefaultOrganizationRolesResponse, CreateRole, UpdateRole, CreateOrganizationRole } from './pkg/grpc/scalekit/v1/roles/roles_pb';
1
+ import { Empty } from "@bufbuild/protobuf";
2
+ import GrpcConnect from "./connect";
3
+ import CoreClient from "./core";
4
+ import { CreateRoleResponse, UpdateRoleResponse, GetRoleResponse, ListRolesResponse, CreateOrganizationRoleResponse, UpdateOrganizationRoleResponse, GetOrganizationRoleResponse, ListOrganizationRolesResponse, GetRoleUsersCountResponse, GetOrganizationRoleUsersCountResponse, UpdateDefaultOrganizationRolesResponse, CreateRole, UpdateRole, CreateOrganizationRole } from "./pkg/grpc/scalekit/v1/roles/roles_pb";
5
+ /**
6
+ * Client for managing roles at both environment and organization levels.
7
+ *
8
+ * Roles define sets of permissions that control user access to resources and operations.
9
+ * This client provides comprehensive role management including role hierarchies, permission
10
+ * inheritance, and both environment-wide and organization-specific roles.
11
+ *
12
+ * **Environment Roles**: Available across your entire Scalekit environment, shared by all organizations
13
+ * **Organization Roles**: Scoped to specific organizations for multi-tenant isolation. These are additional custom roles
14
+ * that are only applicable for that organization beyond the Environment Roles that are applicable for all organizations.
15
+ *
16
+ * @example
17
+ * const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
18
+ * const roleClient = scalekitClient.role;
19
+ *
20
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Role API Documentation}
21
+ */
5
22
  export default class RoleClient {
6
23
  private readonly grpcConnect;
7
24
  private readonly coreClient;
8
25
  private client;
9
26
  constructor(grpcConnect: GrpcConnect, coreClient: CoreClient);
10
27
  /**
11
- * Create a new role
12
- * @param {CreateRole} role The role creation object
13
- * @returns {Promise<CreateRoleResponse>} The created role
28
+ * Creates a new environment-level role with specified permissions.
29
+ *
30
+ * Environment roles are available across all organizations in your environment. Use this to
31
+ * establish foundational access control structures, create role hierarchies, or define granular
32
+ * permission sets that can be reused across organizations.
33
+ *
34
+ * @param {CreateRole} role - Role creation object containing:
35
+ * - name: Unique role identifier (alphanumeric with underscores, 1-64 chars)
36
+ * - displayName: Human-readable name for display
37
+ * - description: Purpose and scope of the role
38
+ * - permissions: Array of permission strings
39
+ * - baseRole?: Optional parent role for permission inheritance
40
+ *
41
+ * @returns {Promise<CreateRoleResponse>} The created role with metadata
42
+ *
43
+ * @example
44
+ * // Create a basic role
45
+ * const response = await scalekitClient.role.createRole({
46
+ * name: 'content_editor',
47
+ * displayName: 'Content Editor',
48
+ * description: 'Can create and edit content',
49
+ * permissions: ['content:read', 'content:write', 'content:edit']
50
+ * });
51
+ *
52
+ * @example
53
+ * // Create role with inheritance
54
+ * await scalekitClient.role.createRole({
55
+ * name: 'senior_editor',
56
+ * displayName: 'Senior Editor',
57
+ * description: 'Editor with publishing rights',
58
+ * baseRole: 'content_editor',
59
+ * permissions: ['content:publish', 'content:delete']
60
+ * });
61
+ *
62
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Create Role API}
14
63
  */
15
64
  createRole(role: CreateRole): Promise<CreateRoleResponse>;
16
65
  /**
17
- * Get role by name
18
- * @param {string} roleName The role name
19
- * @returns {Promise<GetRoleResponse>} The role details
66
+ * Retrieves complete information for a specific environment role.
67
+ *
68
+ * @param {string} roleName - Unique role identifier (alphanumeric with underscores, 1-64 chars)
69
+ *
70
+ * @returns {Promise<GetRoleResponse>} Role details including permissions and inheritance
71
+ *
72
+ * @example
73
+ * const response = await scalekitClient.role.getRole('content_editor');
74
+ * console.log('Role:', response.role.displayName);
75
+ * console.log('Permissions:', response.role.permissions);
76
+ *
77
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Get Role API}
20
78
  */
21
79
  getRole(roleName: string): Promise<GetRoleResponse>;
22
80
  /**
23
- * List all roles
24
- * @returns {Promise<ListRolesResponse>} List of roles
81
+ * Lists all environment-level roles available in your Scalekit environment.
82
+ *
83
+ * @returns {Promise<ListRolesResponse>} Array of all roles with their metadata
84
+ *
85
+ * @example
86
+ * const response = await scalekitClient.role.listRoles();
87
+ * response.roles.forEach(role => {
88
+ * console.log(`${role.displayName}: ${role.permissions.length} permissions`);
89
+ * });
90
+ *
91
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | List Roles API}
25
92
  */
26
93
  listRoles(): Promise<ListRolesResponse>;
27
94
  /**
28
- * Update an existing role by name
29
- * @param {string} roleName The role name to update
30
- * @param {UpdateRole} role The role update object
31
- * @returns {Promise<UpdateRoleResponse>} The updated role
95
+ * Updates an existing environment role's properties and permissions.
96
+ *
97
+ * Only specified fields are updated. The new permission list replaces existing permissions.
98
+ *
99
+ * @param {string} roleName - Role to update
100
+ * @param {UpdateRole} role - Updated role properties
101
+ *
102
+ * @returns {Promise<UpdateRoleResponse>} Updated role details
103
+ *
104
+ * @example
105
+ * await scalekitClient.role.updateRole('content_editor', {
106
+ * displayName: 'Content Editor (Updated)',
107
+ * permissions: ['content:read', 'content:write', 'content:edit', 'content:review']
108
+ * });
109
+ *
110
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Update Role API}
32
111
  */
33
112
  updateRole(roleName: string, role: UpdateRole): Promise<UpdateRoleResponse>;
34
113
  /**
35
- * Delete role by name
36
- * @param {string} roleName The role name to be deleted
37
- * @param {string} [reassignRoleName] The role name to reassign users to when deleting this role
38
- * @returns {Promise<Empty>} Empty response
114
+ * Deletes an environment role and reassigns its users to another role.
115
+ *
116
+ * Cannot delete if dependent roles exist. Users must be reassigned before deletion.
117
+ * This operation is irreversible.
118
+ *
119
+ * @param {string} roleName - Role to delete
120
+ * @param {string} [reassignRoleName] - Target role for user migration
121
+ *
122
+ * @returns {Promise<Empty>} Empty response on success
123
+ *
124
+ * @example
125
+ * await scalekitClient.role.deleteRole('old_role', 'new_role');
126
+ *
127
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Delete Role API}
39
128
  */
40
129
  deleteRole(roleName: string, reassignRoleName?: string): Promise<Empty>;
41
130
  /**
42
- * Get the count of users associated with a role
43
- * @param {string} roleName The role name to get user count for
44
- * @returns {Promise<GetRoleUsersCountResponse>} The user count response
131
+ * Gets the number of users assigned to an environment role.
132
+ *
133
+ * Useful for capacity planning, security auditing, and impact assessment before role changes.
134
+ *
135
+ * @param {string} roleName - Role to count users for
136
+ *
137
+ * @returns {Promise<GetRoleUsersCountResponse>} Total user count (direct and inherited)
138
+ *
139
+ * @example
140
+ * const response = await scalekitClient.role.getRoleUsersCount('admin');
141
+ * console.log(`${response.count} users have admin role`);
142
+ *
143
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Get Role User Count API}
45
144
  */
46
145
  getRoleUsersCount(roleName: string): Promise<GetRoleUsersCountResponse>;
47
146
  /**
48
- * Create a new organization role
49
- * @param {string} orgId The organization ID
50
- * @param {CreateOrganizationRole} role The organization role creation object
51
- * @returns {Promise<CreateOrganizationRoleResponse>} The created organization role
147
+ * Creates a new organization-specific role with custom permissions.
148
+ *
149
+ * Organization roles are scoped to a specific organization for multi-tenant isolation.
150
+ * Use this for organization-specific access control and compartmentalized role management.
151
+ *
152
+ * @param {string} orgId - Organization identifier (format: "org_...")
153
+ * @param {CreateOrganizationRole} role - Role configuration containing:
154
+ * - name: Unique role identifier within the organization
155
+ * - displayName: Human-readable name
156
+ * - description: Purpose and scope
157
+ * - permissions: Organization-specific permission array
158
+ * - baseRole?: Parent role for inheritance
159
+ *
160
+ * @returns {Promise<CreateOrganizationRoleResponse>} Created organization role
161
+ *
162
+ * @example
163
+ * await scalekitClient.role.createOrganizationRole('org_123456', {
164
+ * name: 'department_lead',
165
+ * displayName: 'Department Lead',
166
+ * description: 'Manages department members',
167
+ * permissions: ['dept:members:read', 'dept:members:invite']
168
+ * });
169
+ *
170
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Create Organization Role API}
52
171
  */
53
172
  createOrganizationRole(orgId: string, role: CreateOrganizationRole): Promise<CreateOrganizationRoleResponse>;
54
173
  /**
55
- * Get organization role by name
56
- * @param {string} orgId The organization ID
57
- * @param {string} roleName The role name
58
- * @returns {Promise<GetOrganizationRoleResponse>} The organization role details
174
+ * Retrieves details for a specific organization role.
175
+ *
176
+ * @param {string} orgId - Organization identifier
177
+ * @param {string} roleName - Role name to retrieve
178
+ *
179
+ * @returns {Promise<GetOrganizationRoleResponse>} Organization role details
180
+ *
181
+ * @example
182
+ * const response = await scalekitClient.role.getOrganizationRole(
183
+ * 'org_123456',
184
+ * 'department_lead'
185
+ * );
186
+ * console.log('Permissions:', response.role.permissions);
187
+ *
188
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Get Organization Role API}
59
189
  */
60
190
  getOrganizationRole(orgId: string, roleName: string): Promise<GetOrganizationRoleResponse>;
61
191
  /**
62
- * List all organization roles
63
- * @param {string} orgId The organization ID
64
- * @returns {Promise<ListOrganizationRolesResponse>} List of organization roles
192
+ * Lists all roles available to an organization (environment + organization-specific).
193
+ *
194
+ * Returns both environment-level roles and organization-scoped roles.
195
+ *
196
+ * @param {string} orgId - Organization identifier
197
+ *
198
+ * @returns {Promise<ListOrganizationRolesResponse>} Array of available roles
199
+ *
200
+ * @example
201
+ * const response = await scalekitClient.role.listOrganizationRoles('org_123456');
202
+ * response.roles.forEach(role => {
203
+ * console.log(`${role.displayName} (${role.scope})`);
204
+ * });
205
+ *
206
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | List Organization Roles API}
65
207
  */
66
208
  listOrganizationRoles(orgId: string): Promise<ListOrganizationRolesResponse>;
67
209
  /**
68
- * Update an existing organization role by name
69
- * @param {string} orgId The organization ID
70
- * @param {string} roleName The role name to update
71
- * @param {UpdateRole} role The organization role update object
72
- * @returns {Promise<UpdateOrganizationRoleResponse>} The updated organization role
210
+ * Updates an organization role's properties and permissions.
211
+ *
212
+ * Only specified fields are updated. New permissions replace existing ones.
213
+ *
214
+ * @param {string} orgId - Organization identifier
215
+ * @param {string} roleName - Role to update
216
+ * @param {UpdateRole} role - Updated role properties
217
+ *
218
+ * @returns {Promise<UpdateOrganizationRoleResponse>} Updated role
219
+ *
220
+ * @example
221
+ * await scalekitClient.role.updateOrganizationRole('org_123456', 'department_lead', {
222
+ * permissions: ['dept:members:read', 'dept:members:invite', 'dept:members:remove']
223
+ * });
224
+ *
225
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Update Organization Role API}
73
226
  */
74
227
  updateOrganizationRole(orgId: string, roleName: string, role: UpdateRole): Promise<UpdateOrganizationRoleResponse>;
75
228
  /**
76
- * Delete organization role by name
77
- * @param {string} orgId The organization ID
78
- * @param {string} roleName The role name to be deleted
79
- * @param {string} [reassignRoleName] The role name to reassign users to when deleting this role
80
- * @returns {Promise<Empty>} Empty response
229
+ * Deletes an organization role and reassigns its users.
230
+ *
231
+ * Cannot delete if dependent roles exist. Users must be reassigned. Operation is irreversible.
232
+ *
233
+ * @param {string} orgId - Organization identifier
234
+ * @param {string} roleName - Role to delete
235
+ * @param {string} [reassignRoleName] - Target role for user migration
236
+ *
237
+ * @returns {Promise<Empty>} Empty response on success
238
+ *
239
+ * @example
240
+ * await scalekitClient.role.deleteOrganizationRole(
241
+ * 'org_123456',
242
+ * 'old_role',
243
+ * 'new_role'
244
+ * );
245
+ *
246
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Delete Organization Role API}
81
247
  */
82
248
  deleteOrganizationRole(orgId: string, roleName: string, reassignRoleName?: string): Promise<Empty>;
83
249
  /**
84
- * Get the count of users associated with an organization role
85
- * @param {string} orgId The organization ID
86
- * @param {string} roleName The role name to get user count for
87
- * @returns {Promise<GetOrganizationRoleUsersCountResponse>} The user count response
250
+ * Gets the number of users assigned to an organization role.
251
+ *
252
+ * @param {string} orgId - Organization identifier
253
+ * @param {string} roleName - Role to count users for
254
+ *
255
+ * @returns {Promise<GetOrganizationRoleUsersCountResponse>} User count
256
+ *
257
+ * @example
258
+ * const response = await scalekitClient.role.getOrganizationRoleUsersCount(
259
+ * 'org_123456',
260
+ * 'admin'
261
+ * );
262
+ * console.log(`${response.count} admins in this organization`);
263
+ *
264
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Get Organization Role User Count API}
88
265
  */
89
266
  getOrganizationRoleUsersCount(orgId: string, roleName: string): Promise<GetOrganizationRoleUsersCountResponse>;
90
267
  /**
91
- * Update default organization roles
92
- * @param {string} orgId The organization ID
93
- * @param {string} defaultMemberRole The default member role name
94
- * @returns {Promise<UpdateDefaultOrganizationRolesResponse>} The updated default roles response
268
+ * Sets the default role automatically assigned to new organization members.
269
+ * This is the role that is by default assigned to every new user added to this organization.
270
+ *
271
+ * Affects all new user invitations and memberships within the organization.
272
+ *
273
+ * @param {string} orgId - Organization identifier
274
+ * @param {string} defaultMemberRole - Role name to assign by default
275
+ *
276
+ * @returns {Promise<UpdateDefaultOrganizationRolesResponse>} Updated configuration
277
+ *
278
+ * @example
279
+ * await scalekitClient.role.updateDefaultOrganizationRoles('org_123456', 'member');
280
+ *
281
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Update Default Organization Roles API}
95
282
  */
96
283
  updateDefaultOrganizationRoles(orgId: string, defaultMemberRole: string): Promise<UpdateDefaultOrganizationRolesResponse>;
97
284
  /**
98
- * Delete organization role base relationship
99
- * @param {string} orgId The organization ID
100
- * @param {string} roleName The role name to remove base relationship for
101
- * @returns {Promise<Empty>} Empty response
285
+ * Removes a role's inheritance relationship, eliminating inherited permissions from base role.
286
+ *
287
+ * Role retains only directly assigned permissions after removal. This action cannot be undone.
288
+ *
289
+ * @param {string} orgId - Organization identifier
290
+ * @param {string} roleName - Role to remove inheritance from
291
+ *
292
+ * @returns {Promise<Empty>} Empty response on success
293
+ *
294
+ * @example
295
+ * await scalekitClient.role.deleteOrganizationRoleBase('org_123456', 'custom_role');
296
+ *
297
+ * @see {@link https://docs.scalekit.com/apis/#tag/roles | Delete Organization Role Base API}
102
298
  */
103
299
  deleteOrganizationRoleBase(orgId: string, roleName: string): Promise<Empty>;
104
300
  }