@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.
Files changed (82) 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 +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 +215 -68
  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
package/src/core.ts CHANGED
@@ -1,18 +1,21 @@
1
- import { Code, ConnectError } from '@connectrpc/connect';
1
+ import { Code, ConnectError } from "@connectrpc/connect";
2
2
  import axios, { Axios, AxiosError, AxiosResponse, HttpStatusCode } from "axios";
3
- import { JWK } from 'jose';
3
+ import { JWK } from "jose";
4
4
  import os from "os";
5
5
  import QueryString from "qs";
6
- import { GrantType } from './types/scalekit';
7
- import { TokenResponse } from './types/auth';
8
- import { ScalekitException, ScalekitServerException } from './errors/base-exception';
6
+ import { GrantType } from "./types/scalekit";
7
+ import { TokenResponse } from "./types/auth";
8
+ import {
9
+ ScalekitException,
10
+ ScalekitServerException,
11
+ } from "./errors/base-exception";
9
12
 
10
13
  export const headers = {
11
14
  "user-agent": "user-agent",
12
15
  "x-sdk-version": "x-sdk-version",
13
16
  "x-api-version": "x-api-version",
14
- "authorization": "authorization"
15
- }
17
+ authorization: "authorization",
18
+ };
16
19
 
17
20
  const tokenEndpoint = "oauth/token";
18
21
  const jwksEndpoint = "keys";
@@ -20,9 +23,11 @@ export default class CoreClient {
20
23
  public keys: JWK[] = [];
21
24
  public accessToken: string | null = null;
22
25
  public axios: Axios;
23
- public sdkVersion = `Scalekit-Node/2.1.7`;
24
- public apiVersion = "20250830";
25
- public userAgent = `${this.sdkVersion} Node/${process.version} (${process.platform}; ${os.arch()})`;
26
+ public sdkVersion = `Scalekit-Node/2.1.8`;
27
+ public apiVersion = "20251215";
28
+ public userAgent = `${this.sdkVersion} Node/${process.version} (${
29
+ process.platform
30
+ }; ${os.arch()})`;
26
31
  constructor(
27
32
  readonly envUrl: string,
28
33
  readonly clientId: string,
@@ -30,24 +35,27 @@ export default class CoreClient {
30
35
  ) {
31
36
  this.axios = axios.create({ baseURL: envUrl });
32
37
  this.axios.interceptors.request.use((config) => {
33
- config.headers[headers['user-agent']] = this.userAgent;
34
- config.headers[headers['x-sdk-version']] = this.sdkVersion;
35
- config.headers[headers['x-api-version']] = this.apiVersion;
38
+ config.headers[headers["user-agent"]] = this.userAgent;
39
+ config.headers[headers["x-sdk-version"]] = this.sdkVersion;
40
+ config.headers[headers["x-api-version"]] = this.apiVersion;
36
41
  if (this.accessToken) {
37
42
  config.headers[headers.authorization] = `Bearer ${this.accessToken}`;
38
43
  }
39
44
 
40
45
  return config;
41
46
  });
42
- this.authenticateClient();
47
+ // removing token creation at the time of constructor and instead letting the retry functionality handle generating a token whenever required.
48
+ //this.authenticateClient();
43
49
  }
44
50
 
45
51
  private async authenticateClient() {
46
- const res = await this.authenticate(QueryString.stringify({
47
- grant_type: GrantType.ClientCredentials,
48
- client_id: this.clientId,
49
- client_secret: this.clientSecret
50
- }))
52
+ const res = await this.authenticate(
53
+ QueryString.stringify({
54
+ grant_type: GrantType.ClientCredentials,
55
+ client_id: this.clientId,
56
+ client_secret: this.clientSecret,
57
+ })
58
+ );
51
59
 
52
60
  this.accessToken = res.data.access_token;
53
61
  }
@@ -57,26 +65,24 @@ export default class CoreClient {
57
65
  * @returns {Promise<AxiosResponse<TokenResponse>>} Returns access token and id token
58
66
  */
59
67
  async authenticate(data: string): Promise<AxiosResponse<TokenResponse, any>> {
60
- return this.axios.post<TokenResponse>(
61
- tokenEndpoint,
62
- data,
63
- {
64
- headers: {
65
- "Content-Type": "application/x-www-form-urlencoded"
66
- }
67
- }
68
- )
68
+ return this.axios.post<TokenResponse>(tokenEndpoint, data, {
69
+ headers: {
70
+ "Content-Type": "application/x-www-form-urlencoded",
71
+ },
72
+ });
69
73
  }
70
74
 
71
75
  /**
72
76
  * Get the JWKS from the server and store it in the client instance
73
- * @returns {Promise<void>} Returns nothing
77
+ * @returns {Promise<void>} Returns nothing
74
78
  */
75
79
  async getJwks(): Promise<void> {
76
80
  if (this.keys.length) {
77
81
  return Promise.resolve();
78
82
  }
79
- const { data: { keys } } = await this.axios.get<{ keys: JWK[] }>(jwksEndpoint);
83
+ const {
84
+ data: { keys },
85
+ } = await this.axios.get<{ keys: JWK[] }>(jwksEndpoint);
80
86
  this.keys = keys;
81
87
  }
82
88
 
@@ -90,13 +96,13 @@ export default class CoreClient {
90
96
  async connectExec<TRequest, TResponse>(
91
97
  fn: (request: TRequest) => Promise<TResponse>,
92
98
  data: TRequest,
93
- retryLeft: number = 1,
99
+ retryLeft: number = 1
94
100
  ): Promise<TResponse> {
95
101
  try {
96
102
  const res = await fn(data);
97
103
  return res;
98
104
  } catch (error) {
99
- // Handle gRPC Connect errors
105
+ // Handle gRPC Connect errors
100
106
  if (error instanceof ConnectError) {
101
107
  if (retryLeft > 0) {
102
108
  const serverException = new ScalekitServerException(error);
@@ -130,4 +136,4 @@ export default class CoreClient {
130
136
  throw new ScalekitException(error);
131
137
  }
132
138
  }
133
- }
139
+ }
package/src/directory.ts CHANGED
@@ -1,17 +1,32 @@
1
- import { Timestamp } from '@bufbuild/protobuf';
2
- import { PromiseClient } from '@connectrpc/connect';
3
- import GrpcConnect from './connect';
4
- import CoreClient from './core';
5
- import { DirectoryService } from './pkg/grpc/scalekit/v1/directories/directories_connect';
1
+ import { Timestamp } from "@bufbuild/protobuf";
2
+ import { PromiseClient } from "@connectrpc/connect";
3
+ import GrpcConnect from "./connect";
4
+ import CoreClient from "./core";
5
+ import { DirectoryService } from "./pkg/grpc/scalekit/v1/directories/directories_connect";
6
6
  import {
7
7
  GetDirectoryResponse,
8
8
  Directory,
9
9
  ListDirectoriesResponse,
10
10
  ListDirectoryGroupsResponse,
11
11
  ListDirectoryUsersResponse,
12
- ToggleDirectoryResponse
13
- } from './pkg/grpc/scalekit/v1/directories/directories_pb';
12
+ ToggleDirectoryResponse,
13
+ } from "./pkg/grpc/scalekit/v1/directories/directories_pb";
14
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
+ */
15
30
  export default class DirectoryClient {
16
31
  private client: PromiseClient<typeof DirectoryService>;
17
32
  constructor(
@@ -22,65 +37,211 @@ export default class DirectoryClient {
22
37
  }
23
38
 
24
39
  /**
25
- * List directories for an organization
26
- * @param {string} organizationId The organization id
27
- * @returns {Promise<ListDirectoriesResponse>} Returns the list of directories
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
28
88
  */
29
- async listDirectories(organizationId: string): Promise<ListDirectoriesResponse> {
30
- return this.coreClient.connectExec(
31
- this.client.listDirectories,
32
- { organizationId }
33
- )
89
+ async listDirectories(
90
+ organizationId: string
91
+ ): Promise<ListDirectoriesResponse> {
92
+ return this.coreClient.connectExec(this.client.listDirectories, {
93
+ organizationId,
94
+ });
34
95
  }
35
96
 
36
97
  /**
37
- * Get a directory for an organization
38
- * @param {string} organizationId The organization id
39
- * @param {string} directoryId The directory id
40
- * @returns {Promise<GetDirectoryResponse>} Returns the directory
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
41
145
  */
42
- async getDirectory(organizationId: string, directoryId: string): Promise<GetDirectoryResponse> {
43
- return this.coreClient.connectExec(
44
- this.client.getDirectory,
45
- { organizationId, id: directoryId }
46
- )
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
+ });
47
154
  }
48
155
 
49
156
  /**
50
- * Get a directory for an organization
51
- * @param {string} organizationId The organization id
52
- * @returns {Promise<Directory>} Returns the directory
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
53
186
  */
54
- async getPrimaryDirectoryByOrganizationId(organizationId: string): Promise<Directory> {
187
+ async getPrimaryDirectoryByOrganizationId(
188
+ organizationId: string
189
+ ): Promise<Directory> {
55
190
  const directories = await this.listDirectories(organizationId);
56
191
  if (!directories || directories.directories.length === 0) {
57
- return Promise.reject('directory does not exist for organization');
192
+ return Promise.reject("directory does not exist for organization");
58
193
  }
59
194
 
60
195
  return directories.directories[0];
61
196
  }
62
197
 
63
198
  /**
64
- * List users in a directory for an organization
65
- * @param {string} organizationId The organization id
66
- * @param {string} directoryId The directory id
67
- * @param {object} options The options to list directory users
68
- * @param {number} options.pageSize The page size
69
- * @param {string} options.pageToken The page token
70
- * @param {boolean} options.includeDetail Include detail
71
- * @param {string} options.directoryGroupId The directory group id
72
- * @param {string} options.updatedAfter The updated after
73
- * @returns {Promise<ListDirectoryUsersResponse>} Returns the list of directory users
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
74
235
  */
75
236
  async listDirectoryUsers(
76
237
  organizationId: string,
77
238
  directoryId: string,
78
239
  options?: {
79
- pageSize?: number,
80
- pageToken?: string,
81
- includeDetail?: boolean,
82
- directoryGroupId?: string,
83
- updatedAfter?: string,
240
+ pageSize?: number;
241
+ pageToken?: string;
242
+ includeDetail?: boolean;
243
+ directoryGroupId?: string;
244
+ updatedAfter?: string;
84
245
  }
85
246
  ): Promise<ListDirectoryUsersResponse> {
86
247
  let requestOptions = {};
@@ -88,40 +249,83 @@ export default class DirectoryClient {
88
249
  requestOptions = {
89
250
  ...options,
90
251
  ...(options.updatedAfter && {
91
- updatedAfter: Timestamp.fromDate(new Date(options.updatedAfter))
92
- })
93
- }
252
+ updatedAfter: Timestamp.fromDate(new Date(options.updatedAfter)),
253
+ }),
254
+ };
94
255
  }
95
256
 
96
- return this.coreClient.connectExec(
97
- this.client.listDirectoryUsers,
98
- {
99
- organizationId,
100
- directoryId,
101
- ...requestOptions,
102
- }
103
- )
257
+ return this.coreClient.connectExec(this.client.listDirectoryUsers, {
258
+ organizationId,
259
+ directoryId,
260
+ ...requestOptions,
261
+ });
104
262
  }
105
263
 
106
264
  /**
107
- * List groups in a directory for an organization
108
- * @param {string} organizationId The organization id
109
- * @param {string} directoryId The directory id
110
- * @param {object} options The options to list directory groups
111
- * @param {number} options.pageSize The page size
112
- * @param {string} options.pageToken The page token
113
- * @param {boolean} options.includeDetail Include detail
114
- * @param {string} options.updatedAfter The updated after
115
- * @returns {Promise<ListDirectoryGroupsResponse>} Returns the list of directory groups
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
116
320
  */
117
321
  async listDirectoryGroups(
118
322
  organizationId: string,
119
323
  directoryId: string,
120
324
  options?: {
121
- pageSize?: number,
122
- pageToken?: string,
123
- includeDetail?: boolean,
124
- updatedAfter?: string,
325
+ pageSize?: number;
326
+ pageToken?: string;
327
+ includeDetail?: boolean;
328
+ updatedAfter?: string;
125
329
  }
126
330
  ): Promise<ListDirectoryGroupsResponse> {
127
331
  let requestOptions = {};
@@ -129,45 +333,99 @@ export default class DirectoryClient {
129
333
  requestOptions = {
130
334
  ...options,
131
335
  ...(options.updatedAfter && {
132
- updatedAfter: Timestamp.fromDate(new Date(options.updatedAfter))
133
- })
134
- }
336
+ updatedAfter: Timestamp.fromDate(new Date(options.updatedAfter)),
337
+ }),
338
+ };
135
339
  }
136
340
 
137
- return this.coreClient.connectExec(
138
- this.client.listDirectoryGroups,
139
- {
140
- organizationId,
141
- directoryId,
142
- ...requestOptions,
143
- }
144
- )
341
+ return this.coreClient.connectExec(this.client.listDirectoryGroups, {
342
+ organizationId,
343
+ directoryId,
344
+ ...requestOptions,
345
+ });
145
346
  }
146
347
 
147
348
  /**
148
- * Enable a directory for an organization
149
- * @param {string} organizationId The organization id
150
- * @param {string} directoryId The directory id
151
- * @returns {Promise<ToggleDirectoryResponse>} Returns the directory enable response
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
152
379
  */
153
- async enableDirectory(organizationId: string, directoryId: string): Promise<ToggleDirectoryResponse> {
154
- return this.coreClient.connectExec(
155
- this.client.enableDirectory,
156
- { organizationId, id: directoryId }
157
- )
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
+ });
158
388
  }
159
389
 
160
390
  /**
161
- * Disable a directory for an organization
162
- * @param {string} organizationId The organization id
163
- * @param {string} directoryId The directory id
164
- * @returns {Promise<ToggleDirectoryResponse>} Returns the directory disable response
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
165
421
  */
166
- async disableDirectory(organizationId: string, directoryId: string): Promise<ToggleDirectoryResponse> {
167
- return this.coreClient.connectExec(
168
- this.client.disableDirectory,
169
- { organizationId, id: directoryId }
170
- )
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
+ });
171
430
  }
172
431
  }
173
-