@scalekit-sdk/node 2.1.7 → 2.1.9

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 (83) 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 +172 -19
  15. package/lib/domain.js +192 -31
  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 +231 -62
  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
  83. package/tests/domain.test.ts +54 -0
@@ -1,41 +1,196 @@
1
- import GrpcConnect from './connect';
2
- import CoreClient from './core';
3
- import { GetDirectoryResponse, Directory, ListDirectoriesResponse, ListDirectoryGroupsResponse, ListDirectoryUsersResponse, ToggleDirectoryResponse } from './pkg/grpc/scalekit/v1/directories/directories_pb';
1
+ import GrpcConnect from "./connect";
2
+ import CoreClient from "./core";
3
+ import { GetDirectoryResponse, Directory, ListDirectoriesResponse, ListDirectoryGroupsResponse, ListDirectoryUsersResponse, ToggleDirectoryResponse } from "./pkg/grpc/scalekit/v1/directories/directories_pb";
4
+ /**
5
+ * Client for managing SCIM directory synchronization.
6
+ *
7
+ * Directories represent SCIM connections that automatically sync users and groups from an
8
+ * organization's identity provider (Okta, Azure AD, Google Workspace, etc.) to your application.
9
+ * Use this client to retrieve synchronized user/group data, manage directory settings, and
10
+ * monitor sync status.
11
+ *
12
+ * @example
13
+ * const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
14
+ * const directoryClient = scalekitClient.directory;
15
+ *
16
+ * @see {@link https://docs.scalekit.com/apis/#tag/directory | Directory API Documentation}
17
+ * @see {@link https://docs.scalekit.com/directory/scim/quickstart/ | SCIM Directory Sync Guide}
18
+ */
4
19
  export default class DirectoryClient {
5
20
  private readonly grpcConncet;
6
21
  private readonly coreClient;
7
22
  private client;
8
23
  constructor(grpcConncet: GrpcConnect, coreClient: CoreClient);
9
24
  /**
10
- * List directories for an organization
11
- * @param {string} organizationId The organization id
12
- * @returns {Promise<ListDirectoriesResponse>} Returns the list of directories
25
+ * Retrieves all SCIM directories configured for an organization.
26
+ *
27
+ * Lists all directory sync connections that have been set up for the organization. Each directory
28
+ * represents a SCIM integration with an identity provider (Okta, Azure AD, Google Workspace, etc.)
29
+ * that automatically syncs users and groups. Use this to view directory configurations, check sync
30
+ * status, and manage directory integrations.
31
+ *
32
+ * @param {string} organizationId - The organization ID to list directories for (format: "org_...")
33
+ *
34
+ * @returns {Promise<ListDirectoriesResponse>} Response containing:
35
+ * - directories: Array of directory objects with:
36
+ * - id: Unique directory identifier
37
+ * - organizationId: Parent organization ID
38
+ * - provider: Identity provider name (e.g., "okta", "azure_ad", "google")
39
+ * - enabled: Whether directory sync is active
40
+ * - status: Current synchronization status
41
+ * - lastSyncTime: When the last sync occurred
42
+ * - userCount: Number of synced users
43
+ * - groupCount: Number of synced groups
44
+ *
45
+ * @throws {Error} If the organization is not found
46
+ *
47
+ * @example
48
+ * // List all directories for an organization
49
+ * const response = await scalekitClient.directory.listDirectories('org_123456');
50
+ *
51
+ * console.log(`Found ${response.directories.length} directories`);
52
+ * response.directories.forEach(dir => {
53
+ * console.log(`- ${dir.provider}: ${dir.enabled ? 'Active' : 'Inactive'}`);
54
+ * console.log(` Users: ${dir.userCount}, Groups: ${dir.groupCount}`);
55
+ * });
56
+ *
57
+ * @example
58
+ * // Check if organization has any active directories
59
+ * const response = await scalekitClient.directory.listDirectories('org_123456');
60
+ * const hasActiveDirectory = response.directories.some(dir => dir.enabled);
61
+ *
62
+ * if (hasActiveDirectory) {
63
+ * console.log('Directory sync is enabled for this organization');
64
+ * } else {
65
+ * console.log('No active directory sync');
66
+ * }
67
+ *
68
+ *
69
+ * @see {@link https://docs.scalekit.com/apis/#tag/directory | List Directories API}
70
+ * @see {@link getDirectory} - Get details of a specific directory
71
+ * @see {@link enableDirectory} - Enable directory sync
72
+ * @see {@link disableDirectory} - Disable directory sync
13
73
  */
14
74
  listDirectories(organizationId: string): Promise<ListDirectoriesResponse>;
15
75
  /**
16
- * Get a directory for an organization
17
- * @param {string} organizationId The organization id
18
- * @param {string} directoryId The directory id
19
- * @returns {Promise<GetDirectoryResponse>} Returns the directory
76
+ * Retrieves comprehensive details about a specific SCIM directory.
77
+ *
78
+ * Fetches complete configuration and status information for a directory, including provider settings,
79
+ * synchronization status, user/group counts, and metadata. Use this to view directory configuration,
80
+ * monitor sync health, verify setup, or display directory details in admin interfaces.
81
+ *
82
+ * @param {string} organizationId - The organization ID that owns the directory (format: "org_...")
83
+ * @param {string} directoryId - The directory identifier to retrieve (format: "dir_...")
84
+ *
85
+ * @returns {Promise<GetDirectoryResponse>} Response containing:
86
+ * - directory: Complete directory object with:
87
+ * - id: Unique directory identifier
88
+ * - organizationId: Parent organization ID
89
+ * - provider: Identity provider name (e.g., "okta", "azure_ad", "google")
90
+ * - enabled: Whether directory sync is active
91
+ * - status: Current synchronization status
92
+ * - scimBaseUrl: SCIM endpoint URL
93
+ * - scimToken: Authentication token (masked)
94
+ * - lastSyncTime: Timestamp of last successful sync
95
+ * - nextSyncTime: Scheduled time for next sync
96
+ * - userCount: Number of synced users
97
+ * - groupCount: Number of synced groups
98
+ * - createTime: When directory was created
99
+ * - updateTime: When directory was last updated
100
+ *
101
+ * @throws {Error} If the organization or directory is not found
102
+ *
103
+ * @example
104
+ * // Get directory details
105
+ * const response = await scalekitClient.directory.getDirectory(
106
+ * 'org_123456',
107
+ * 'dir_abc123'
108
+ * );
109
+ *
110
+ * const dir = response.directory;
111
+ * console.log('Provider:', dir.provider);
112
+ * console.log('Status:', dir.enabled ? 'Active' : 'Inactive');
113
+ * console.log('Last sync:', dir.lastSyncTime);
114
+ * console.log('Users:', dir.userCount);
115
+ * console.log('Groups:', dir.groupCount);
116
+ *
117
+ *
118
+ * @see {@link https://docs.scalekit.com/apis/#tag/directory | Get Directory API}
119
+ * @see {@link getPrimaryDirectoryByOrganizationId} - List the first directory in an Organization.
120
+ * - Useful utility API if you don't know the directory ID but only have an organizationID.
121
+ * @see {@link listDirectoryUsers} - List users in this directory
122
+ * @see {@link listDirectoryGroups} - List groups in this directory
20
123
  */
21
124
  getDirectory(organizationId: string, directoryId: string): Promise<GetDirectoryResponse>;
22
125
  /**
23
- * Get a directory for an organization
24
- * @param {string} organizationId The organization id
25
- * @returns {Promise<Directory>} Returns the directory
126
+ * Retrieves the primary (first) directory for an organization.
127
+ *
128
+ * This is a convenience method that fetches the first directory from the organization's list
129
+ * of directories. Most organizations have a single directory, making this useful for quickly
130
+ * accessing directory data without needing to know the specific directory ID. If the organization
131
+ * has multiple directories, this returns the first one.
132
+ *
133
+ * @param {string} organizationId - The organization ID to get the primary directory for (format: "org_...")
134
+ *
135
+ * @returns {Promise<Directory>} The first directory object for the organization
136
+ *
137
+ * @throws {Error} When the organization has no directories configured
138
+ *
139
+ * @example
140
+ * // Get primary directory for an organization
141
+ * try {
142
+ * const directory = await scalekitClient.directory.getPrimaryDirectoryByOrganizationId('org_123456');
143
+ *
144
+ * console.log('Primary Directory:', directory.provider);
145
+ * console.log('Users:', directory.userCount);
146
+ * console.log('Groups:', directory.groupCount);
147
+ * } catch (error) {
148
+ * console.log('No directory configured for this organization');
149
+ * }
150
+ *
151
+ *
152
+ * @see {@link listDirectories} - List all directories for an organization
153
+ * @see {@link getDirectory} - Get a specific directory by ID
154
+ * @see {@link listDirectoryUsers} - List users in the directory
26
155
  */
27
156
  getPrimaryDirectoryByOrganizationId(organizationId: string): Promise<Directory>;
28
157
  /**
29
- * List users in a directory for an organization
30
- * @param {string} organizationId The organization id
31
- * @param {string} directoryId The directory id
32
- * @param {object} options The options to list directory users
33
- * @param {number} options.pageSize The page size
34
- * @param {string} options.pageToken The page token
35
- * @param {boolean} options.includeDetail Include detail
36
- * @param {string} options.directoryGroupId The directory group id
37
- * @param {string} options.updatedAfter The updated after
38
- * @returns {Promise<ListDirectoryUsersResponse>} Returns the list of directory users
158
+ * Lists users synchronized from an identity provider via SCIM directory sync.
159
+ *
160
+ * Retrieves all users that have been synced from the organization's IdP to your application.
161
+ * This includes user profile information, group memberships, and sync status. Use this to
162
+ * display organization users, implement user search, or track provisioning/deprovisioning.
163
+ *
164
+ * @param {string} organizationId - The organization ID
165
+ * @param {string} directoryId - The directory ID
166
+ * @param {object} [options] - Optional filtering and pagination parameters
167
+ * @param {number} [options.pageSize] - Number of users per page (max: 100)
168
+ * @param {string} [options.pageToken] - Token for next page from previous response
169
+ * @param {boolean} [options.includeDetail] - Include full user profile details
170
+ * @param {string} [options.directoryGroupId] - Filter users by group membership
171
+ * @param {string} [options.updatedAfter] - ISO 8601 timestamp to fetch only users updated after this time
172
+ *
173
+ * @returns {Promise<ListDirectoryUsersResponse>} Response containing:
174
+ * - users: Array of directory user objects with profiles and attributes
175
+ * - nextPageToken: Token for retrieving the next page
176
+ * - totalSize: Total number of users in the directory
177
+ *
178
+ * @example
179
+ * // List all directory users with pagination
180
+ * const response = await scalekitClient.directory.listDirectoryUsers(
181
+ * 'org_123456',
182
+ * 'dir_abc123',
183
+ * { pageSize: 50 }
184
+ * );
185
+ *
186
+ * console.log(`Found ${response.totalSize} users`);
187
+ * response.users.forEach(user => {
188
+ * console.log(`- ${user.email} (${user.firstName} ${user.lastName})`);
189
+ * });
190
+ *
191
+ * @see {@link https://docs.scalekit.com/apis/#tag/directory | List Directory Users API}
192
+ * @see {@link listDirectoryGroups} - List directory groups
193
+ * @see {@link listDirectories} - List all directories for an organization
39
194
  */
40
195
  listDirectoryUsers(organizationId: string, directoryId: string, options?: {
41
196
  pageSize?: number;
@@ -45,15 +200,61 @@ export default class DirectoryClient {
45
200
  updatedAfter?: string;
46
201
  }): Promise<ListDirectoryUsersResponse>;
47
202
  /**
48
- * List groups in a directory for an organization
49
- * @param {string} organizationId The organization id
50
- * @param {string} directoryId The directory id
51
- * @param {object} options The options to list directory groups
52
- * @param {number} options.pageSize The page size
53
- * @param {string} options.pageToken The page token
54
- * @param {boolean} options.includeDetail Include detail
55
- * @param {string} options.updatedAfter The updated after
56
- * @returns {Promise<ListDirectoryGroupsResponse>} Returns the list of directory groups
203
+ * Retrieves groups synchronized from an identity provider via SCIM directory sync.
204
+ *
205
+ * Fetches all groups that have been synced from the organization's IdP to your application.
206
+ * Groups typically represent teams, departments, or organizational units. Use this to display
207
+ * group hierarchies, implement group-based access control, manage group memberships, or track
208
+ * organizational structure changes.
209
+ *
210
+ * @param {string} organizationId - The organization ID (format: "org_...")
211
+ * @param {string} directoryId - The directory ID (format: "dir_...")
212
+ * @param {object} [options] - Optional filtering and pagination parameters
213
+ * @param {number} [options.pageSize] - Number of groups per page (max: 30, default: 10)
214
+ * @param {string} [options.pageToken] - Token for next page from previous response
215
+ * @param {boolean} [options.includeDetail] - Include full group details and member lists
216
+ * @param {string} [options.updatedAfter] - ISO 8601 timestamp to fetch only groups updated after this time
217
+ *
218
+ * @returns {Promise<ListDirectoryGroupsResponse>} Response containing:
219
+ * - groups: Array of directory group objects with:
220
+ * - id: Group identifier
221
+ * - displayName: Group name
222
+ * - description: Group description
223
+ * - members: Array of member user IDs (when includeDetail is true)
224
+ * - attributes: Custom group attributes
225
+ * - updateTime: When the group was last updated
226
+ * - nextPageToken: Token for retrieving the next page
227
+ * - totalSize: Total number of groups in the directory
228
+ *
229
+ * @example
230
+ * // List all directory groups with pagination
231
+ * const response = await scalekitClient.directory.listDirectoryGroups(
232
+ * 'org_123456',
233
+ * 'dir_abc123',
234
+ * { pageSize: 30 }
235
+ * );
236
+ *
237
+ * console.log(`Found ${response.totalSize} groups`);
238
+ * response.groups.forEach(group => {
239
+ * console.log(`- ${group.displayName}`);
240
+ * if (group.description) console.log(` ${group.description}`);
241
+ * });
242
+ *
243
+ * @example
244
+ * // Get groups with full member details
245
+ * const response = await scalekitClient.directory.listDirectoryGroups(
246
+ * 'org_123456',
247
+ * 'dir_abc123',
248
+ * { includeDetail: true }
249
+ * );
250
+ *
251
+ * response.groups.forEach(group => {
252
+ * console.log(`${group.displayName}: ${group.members?.length || 0} members`);
253
+ * });
254
+ *
255
+ * @see {@link https://docs.scalekit.com/apis/#tag/directory | List Directory Groups API}
256
+ * @see {@link listDirectoryUsers} - List directory users
257
+ * @see {@link getDirectory} - Get directory details
57
258
  */
58
259
  listDirectoryGroups(organizationId: string, directoryId: string, options?: {
59
260
  pageSize?: number;
@@ -62,17 +263,69 @@ export default class DirectoryClient {
62
263
  updatedAfter?: string;
63
264
  }): Promise<ListDirectoryGroupsResponse>;
64
265
  /**
65
- * Enable a directory for an organization
66
- * @param {string} organizationId The organization id
67
- * @param {string} directoryId The directory id
68
- * @returns {Promise<ToggleDirectoryResponse>} Returns the directory enable response
266
+ * Enables SCIM directory synchronization for an organization.
267
+ *
268
+ * Activates automatic user and group synchronization from the organization's identity provider.
269
+ * Once enabled, users and groups from the IdP will be synced to your application, and any changes
270
+ * in the IdP (additions, updates, deletions) will be automatically reflected. This is essential
271
+ * for implementing automated user provisioning and deprovisioning.
272
+ *
273
+ * @param {string} organizationId - The organization ID (format: "org_...")
274
+ * @param {string} directoryId - The directory ID to enable (format: "dir_...")
275
+ *
276
+ * @returns {Promise<ToggleDirectoryResponse>} Response containing:
277
+ * - directory: The updated directory object with enabled status set to true
278
+ *
279
+ * @throws {Error} If the organization or directory is not found
280
+ * @throws {Error} If the directory configuration is incomplete or invalid
281
+ *
282
+ * @example
283
+ * // Enable directory sync
284
+ * const response = await scalekitClient.directory.enableDirectory(
285
+ * 'org_123456',
286
+ * 'dir_abc123'
287
+ * );
288
+ *
289
+ * console.log('Directory enabled:', response.directory.enabled); // true
290
+ * console.log('Sync will start automatically');
291
+ *
292
+ * @see {@link https://docs.scalekit.com/apis/#tag/directory | Enable Directory API}
293
+ * @see {@link disableDirectory} - Disable directory sync
294
+ * @see {@link getDirectory} - Check directory status
295
+ * @see {@link listDirectoryUsers} - View synced users after enabling
69
296
  */
70
297
  enableDirectory(organizationId: string, directoryId: string): Promise<ToggleDirectoryResponse>;
71
298
  /**
72
- * Disable a directory for an organization
73
- * @param {string} organizationId The organization id
74
- * @param {string} directoryId The directory id
75
- * @returns {Promise<ToggleDirectoryResponse>} Returns the directory disable response
299
+ * Disables SCIM directory synchronization for an organization.
300
+ *
301
+ * Stops automatic user and group synchronization from the organization's identity provider.
302
+ * When disabled, no new updates will be received from the IdP, but existing synced users and
303
+ * groups remain in your application. This is useful for temporarily pausing sync during maintenance,
304
+ * troubleshooting, or when migrating to a different directory provider. Does not delete existing data.
305
+ *
306
+ * @param {string} organizationId - The organization ID (format: "org_...")
307
+ * @param {string} directoryId - The directory ID to disable (format: "dir_...")
308
+ *
309
+ * @returns {Promise<ToggleDirectoryResponse>} Response containing:
310
+ * - directory: The updated directory object with enabled status set to false
311
+ *
312
+ * @throws {Error} If the organization or directory is not found
313
+ *
314
+ * @example
315
+ * // Disable directory sync
316
+ * const response = await scalekitClient.directory.disableDirectory(
317
+ * 'org_123456',
318
+ * 'dir_abc123'
319
+ * );
320
+ *
321
+ * console.log('Directory disabled:', !response.directory.enabled); // true
322
+ * console.log('Existing users and groups are preserved');
323
+ *
324
+ *
325
+ * @see {@link https://docs.scalekit.com/apis/#tag/directory | Disable Directory API}
326
+ * @see {@link enableDirectory} - Enable directory sync
327
+ * @see {@link getDirectory} - Check directory status
328
+ * @see {@link listDirectories} - List all directories
76
329
  */
77
330
  disableDirectory(organizationId: string, directoryId: string): Promise<ToggleDirectoryResponse>;
78
331
  }