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