@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
@@ -1,10 +1,35 @@
1
- import { Empty, PartialMessage } from '@bufbuild/protobuf';
2
- import { PromiseClient } from '@connectrpc/connect';
3
- import GrpcConnect from './connect';
4
- import CoreClient from './core';
5
- import { OrganizationService } from './pkg/grpc/scalekit/v1/organizations/organizations_connect';
6
- import { CreateOrganizationResponse, GetOrganizationResponse, Link, ListOrganizationsResponse, OrganizationUserManagementSettings as OrganizationUserManagementSettingsMessage, UpdateOrganization, UpdateOrganizationResponse } from './pkg/grpc/scalekit/v1/organizations/organizations_pb';
7
- import { OrganizationSettings, OrganizationUserManagementSettingsInput } from './types/organization';
1
+ import { Empty, PartialMessage } from "@bufbuild/protobuf";
2
+ import { PromiseClient } from "@connectrpc/connect";
3
+ import GrpcConnect from "./connect";
4
+ import CoreClient from "./core";
5
+ import { OrganizationService } from "./pkg/grpc/scalekit/v1/organizations/organizations_connect";
6
+ import {
7
+ CreateOrganizationResponse,
8
+ GetOrganizationResponse,
9
+ Link,
10
+ ListOrganizationsResponse,
11
+ OrganizationUserManagementSettings as OrganizationUserManagementSettingsMessage,
12
+ UpdateOrganization,
13
+ UpdateOrganizationResponse,
14
+ } from "./pkg/grpc/scalekit/v1/organizations/organizations_pb";
15
+ import {
16
+ OrganizationSettings,
17
+ OrganizationUserManagementSettingsInput,
18
+ } from "./types/organization";
19
+
20
+ /**
21
+ * Client for managing organizations (tenants) in your Scalekit application.
22
+ *
23
+ * Organizations represent your B2B customers or tenants. Each organization can have
24
+ * its own SSO connection, users, and settings. Use this client to perform CRUD
25
+ * operations on organizations and manage organization-level configurations.
26
+ *
27
+ * @example
28
+ * const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
29
+ * const orgClient = scalekitClient.organization;
30
+ *
31
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | Organization API Documentation}
32
+ */
8
33
  export default class OrganizationClient {
9
34
  private client: PromiseClient<typeof OrganizationService>;
10
35
  constructor(
@@ -14,165 +39,519 @@ export default class OrganizationClient {
14
39
  this.client = this.grpcConncet.createClient(OrganizationService);
15
40
  }
16
41
 
17
- /**
18
- * Create an organization with the given name. Optionally, you can provide an external id.
19
- * @param {string} name The organization name
20
- * @param {object} options The options to create an organization
21
- * @param {string} options.externalId The external id
22
- * @returns {Promise<CreateOrganizationResponse>} The created organization
23
- */
24
- async createOrganization(name: string, options?: { externalId?: string }): Promise<CreateOrganizationResponse> {
25
- return this.coreClient.connectExec(
26
- this.client.createOrganization,
27
- {
28
- organization: {
29
- displayName: name,
30
- ...(options?.externalId && {
31
- externalId: options.externalId
32
- })
33
- }
34
- }
35
- )
42
+ /**
43
+ * Creates a new organization (tenant) in your Scalekit application.
44
+ *
45
+ * Organizations represent your B2B customers. Each organization can have its own
46
+ * SSO connections, users, and configuration. Use the external ID to map Scalekit
47
+ * organizations to your internal system's identifiers.
48
+ *
49
+ * @param {string} name - Display name for the organization (e.g., "Acme Corporation")
50
+ * @param {object} [options] - Optional configuration
51
+ * @param {string} [options.externalId] - Your system's unique identifier for this organization.
52
+ * Useful for mapping to your internal database.
53
+ *
54
+ * @returns {Promise<CreateOrganizationResponse>} The created organization with:
55
+ * - id: Scalekit's unique organization identifier
56
+ * - displayName: The organization's name
57
+ * - externalId: Unique Identifier of this organization as identified in your system. (if provided)
58
+ * - createTime: When the organization was created
59
+ * - updateTime: When the organization was last updated
60
+ *
61
+ * @example
62
+ * // Create a basic organization
63
+ * const org = await scalekitClient.organization.createOrganization('Acme Corp');
64
+ * console.log('Organization ID:', org.organization.id);
65
+ *
66
+ * @example
67
+ * // Create organization with external ID mapping
68
+ * const org = await scalekitClient.organization.createOrganization(
69
+ * 'Acme Corporation',
70
+ * { externalId: 'customer_12345' }
71
+ * );
72
+ * // Now you can look up this organization using either Scalekit ID or your external ID
73
+ *
74
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | Create Organization API}
75
+ * @see {@link getOrganization} - Retrieve organization by Scalekit ID
76
+ * @see {@link getOrganizationByExternalId} - Retrieve organization by your external ID
77
+ */
78
+ async createOrganization(
79
+ name: string,
80
+ options?: { externalId?: string }
81
+ ): Promise<CreateOrganizationResponse> {
82
+ return this.coreClient.connectExec(this.client.createOrganization, {
83
+ organization: {
84
+ displayName: name,
85
+ ...(options?.externalId && {
86
+ externalId: options.externalId,
87
+ }),
88
+ },
89
+ });
36
90
  }
37
91
 
38
92
  /**
39
- * List organizations with pagination
40
- * @param {object} options The options to list organizations
41
- * @param {number} options.pageSize The page size
42
- * @param {string} options.pageToken The page token
43
- * @returns {Promise<ListOrganizationResponse>} The list of organizations
93
+ * Retrieves a paginated list of all organizations in your Scalekit environment.
94
+ *
95
+ * This method returns all organizations with support for pagination. Use this to
96
+ * display a list of your B2B customers, search for organizations, or perform bulk operations.
97
+ *
98
+ * @param {object} [options] - Optional pagination parameters
99
+ * @param {number} [options.pageSize] - Number of organizations to return per page (default: 10, max: 100)
100
+ * @param {string} [options.pageToken] - Token for retrieving the next page of results.
101
+ * Obtained from the previous response's nextPageToken.
102
+ *
103
+ * @returns {Promise<ListOrganizationsResponse>} Response containing:
104
+ * - organizations: Array of organization objects
105
+ * - nextPageToken: Token for fetching the next page (empty if no more pages)
106
+ * - totalSize: Total number of organizations
107
+ *
108
+ * @example
109
+ * // List first page of organizations
110
+ * const response = await scalekitClient.organization.listOrganization({
111
+ * pageSize: 20
112
+ * });
113
+ *
114
+ * console.log('Organizations:', response.organizations);
115
+ * console.log('Total:', response.totalSize);
116
+ *
117
+ * @example
118
+ * // Paginate through all organizations
119
+ * let pageToken = undefined;
120
+ * let allOrgs = [];
121
+ *
122
+ * do {
123
+ * const response = await scalekitClient.organization.listOrganization({
124
+ * pageSize: 50,
125
+ * pageToken
126
+ * });
127
+ *
128
+ * allOrgs.push(...response.organizations);
129
+ * pageToken = response.nextPageToken;
130
+ * } while (pageToken);
131
+ *
132
+ * console.log('Fetched all organizations:', allOrgs.length);
133
+ *
134
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | List Organizations API}
135
+ * @see {@link getOrganization} - Get a specific organization by ID
44
136
  */
45
137
  async listOrganization(options?: {
46
- pageSize?: number,
47
- pageToken?: string
138
+ pageSize?: number;
139
+ pageToken?: string;
48
140
  }): Promise<ListOrganizationsResponse> {
49
141
  return this.coreClient.connectExec(
50
142
  this.client.listOrganization,
51
- options ? options : {},
52
- )
143
+ options ? options : {}
144
+ );
53
145
  }
54
146
 
55
147
  /**
56
- * Get an organization by id
57
- * @param {string} id The organization id
58
- * @returns {Promise<GetOrganizationResponse>} The organization
148
+ * Retrieves detailed information about a specific organization using its Scalekit ID.
149
+ *
150
+ * Use this method to fetch complete organization details including display name, region,
151
+ * metadata, settings, and configuration. This is useful for displaying organization info
152
+ * in your application or checking organization status.
153
+ *
154
+ * @param {string} id - The Scalekit-generated organization identifier (format: "org_...")
155
+ *
156
+ * @returns {Promise<GetOrganizationResponse>} Response containing:
157
+ * - organization: Complete organization object with:
158
+ * - id: Scalekit's unique identifier
159
+ * - displayName: Organization's display name
160
+ * - externalId: Your system's identifier (if set)
161
+ * - metadata: Custom metadata key-value pairs
162
+ * - createTime: When the organization was created
163
+ * - updateTime: When the organization was last updated
164
+ *
165
+ * @throws {Error} If the organization is not found or access is denied
166
+ *
167
+ * @example
168
+ * // Get organization details
169
+ * const response = await scalekitClient.organization.getOrganization('org_12345');
170
+ * const org = response.organization;
171
+ *
172
+ * console.log('Organization:', org.displayName);
173
+ * console.log('External ID:', org.externalId);
174
+ *
175
+ * @example
176
+ * // Check if organization exists before operations
177
+ * try {
178
+ * const response = await scalekitClient.organization.getOrganization(orgId);
179
+ * // Proceed with organization operations
180
+ * } catch (error) {
181
+ * console.error('Organization not found:', error);
182
+ * }
183
+ *
184
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | Get Organization API}
185
+ * @see {@link getOrganizationByExternalId} - Retrieve organization using your external ID
186
+ * @see {@link listOrganization} - List all organizations
59
187
  */
60
188
  async getOrganization(id: string): Promise<GetOrganizationResponse> {
61
- return this.coreClient.connectExec(
62
- this.client.getOrganization,
63
- { identities: { case: 'id', value: id } },
64
- )
189
+ return this.coreClient.connectExec(this.client.getOrganization, {
190
+ identities: { case: "id", value: id },
191
+ });
65
192
  }
66
193
 
67
194
  /**
68
- * Get an organization by external id
69
- * @param {string} externalId The external id
70
- * @returns {Promise<GetOrganizationResponse>} The organization
195
+ * Retrieves detailed information about an organization using your system's external identifier.
196
+ *
197
+ * This is particularly useful when you need to look up an organization using your own
198
+ * internal identifiers rather than Scalekit's ID. The external ID is typically set when
199
+ * creating or updating an organization to maintain a mapping between your system and Scalekit.
200
+ *
201
+ * @param {string} externalId - Your system's unique identifier for the organization
202
+ * (e.g., "customer_12345", "tenant_abc")
203
+ *
204
+ * @returns {Promise<GetOrganizationResponse>} Response containing:
205
+ * - organization: Complete organization object with all details
206
+ * (same structure as {@link getOrganization})
207
+ *
208
+ * @throws {Error} If no organization is found with the provided external ID
209
+ *
210
+ * @example
211
+ * // Retrieve organization using your internal customer ID
212
+ * const response = await scalekitClient.organization.getOrganizationByExternalId('customer_12345');
213
+ * const org = response.organization;
214
+ *
215
+ * console.log('Scalekit ID:', org.id);
216
+ * console.log('Organization:', org.displayName);
217
+ *
218
+ * @example
219
+ * // Use in API endpoints where you have your customer ID
220
+ * app.get('/api/customers/:customerId/sso', async (req, res) => {
221
+ * const { customerId } = req.params;
222
+ *
223
+ * try {
224
+ * const response = await scalekitClient.organization.getOrganizationByExternalId(customerId);
225
+ * res.json({ organization: response.organization });
226
+ * } catch (error) {
227
+ * res.status(404).json({ error: 'Organization not found' });
228
+ * }
229
+ * });
230
+ *
231
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | Get Organization API}
232
+ * @see {@link getOrganization} - Retrieve organization using Scalekit ID
233
+ * @see {@link createOrganization} - Create organization with external ID mapping
71
234
  */
72
- async getOrganizationByExternalId(externalId: string): Promise<GetOrganizationResponse> {
73
- return this.coreClient.connectExec(
74
- this.client.getOrganization,
75
- { identities: { case: 'externalId', value: externalId } },
76
- )
235
+ async getOrganizationByExternalId(
236
+ externalId: string
237
+ ): Promise<GetOrganizationResponse> {
238
+ return this.coreClient.connectExec(this.client.getOrganization, {
239
+ identities: { case: "externalId", value: externalId },
240
+ });
77
241
  }
78
242
 
79
243
  /**
80
- * Update an organization by id
81
- * @param {string} id The organization id
82
- * @param {PartialMessage<UpdateOrganization>} organization The organization to update
83
- * @returns {Promise<UpdateOrganizationResponse>} The updated organization
244
+ * Updates an organization's properties using its Scalekit ID.
245
+ *
246
+ * Use this method to modify an organization's display name, external ID, or custom metadata.
247
+ * Only the fields you specify in the update object will be changed; all other fields remain
248
+ * unchanged. Note that the region code cannot be modified once set.
249
+ *
250
+ * @param {string} id - The Scalekit organization identifier (format: "org_...")
251
+ * @param {PartialMessage<UpdateOrganization>} organization - Object containing fields to update:
252
+ * - displayName?: New display name for the organization
253
+ * - externalId?: New external ID to map to your system
254
+ * - metadata?: Custom key-value pairs for storing additional data
255
+ *
256
+ * @returns {Promise<UpdateOrganizationResponse>} Response containing:
257
+ * - organization: The updated organization object with all current values
258
+ *
259
+ * @throws {Error} If the organization is not found or update fails
260
+ *
261
+ * @example
262
+ * // Update organization display name
263
+ * const response = await scalekitClient.organization.updateOrganization('org_12345', {
264
+ * displayName: 'Acme Corporation (Updated)'
265
+ * });
266
+ *
267
+ * console.log('Updated:', response.organization.displayName);
268
+ *
269
+ * @example
270
+ * // Add external ID to existing organization
271
+ * await scalekitClient.organization.updateOrganization('org_12345', {
272
+ * externalId: 'customer_abc'
273
+ * });
274
+ *
275
+ * @example
276
+ * // Update multiple fields including metadata
277
+ * const response = await scalekitClient.organization.updateOrganization('org_12345', {
278
+ * displayName: 'Acme Corp',
279
+ * metadata: {
280
+ * industry: 'Technology',
281
+ * size: 'Enterprise',
282
+ * plan: 'Premium'
283
+ * }
284
+ * });
285
+ *
286
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | Update Organization API}
287
+ * @see {@link updateOrganizationByExternalId} - Update using your external ID
288
+ * @see {@link getOrganization} - Retrieve current organization details
84
289
  */
85
- async updateOrganization(id: string, organization: PartialMessage<UpdateOrganization>): Promise<UpdateOrganizationResponse> {
86
- return this.coreClient.connectExec(
87
- this.client.updateOrganization,
88
- {
89
- identities: { case: "id", value: id },
90
- organization
91
- },
92
- )
290
+ async updateOrganization(
291
+ id: string,
292
+ organization: PartialMessage<UpdateOrganization>
293
+ ): Promise<UpdateOrganizationResponse> {
294
+ return this.coreClient.connectExec(this.client.updateOrganization, {
295
+ identities: { case: "id", value: id },
296
+ organization,
297
+ });
93
298
  }
94
299
 
95
300
  /**
96
- * Update an organization by external id
97
- * @param {string} externalId The external id
98
- * @param {PartialMessage<UpdateOrganization>} organization The organization to update
99
- * @returns {Promise<UpdateOrganizationResponse>} The updated organization
301
+ * Updates an organization's properties using your system's external identifier.
302
+ *
303
+ * This method provides the same functionality as {@link updateOrganization} but allows you
304
+ * to reference the organization using your own internal identifier instead of Scalekit's ID.
305
+ * Only specified fields will be updated; all other fields remain unchanged.
306
+ *
307
+ * @param {string} externalId - Your system's unique identifier for the organization
308
+ * @param {PartialMessage<UpdateOrganization>} organization - Object containing fields to update:
309
+ * - displayName?: New display name for the organization
310
+ * - externalId?: New external ID (useful for migrating identifiers)
311
+ * - metadata?: Custom key-value pairs for storing additional data
312
+ *
313
+ * @returns {Promise<UpdateOrganizationResponse>} Response containing:
314
+ * - organization: The updated organization object with all current values
315
+ *
316
+ * @throws {Error} If no organization is found with the provided external ID
317
+ *
318
+ * @example
319
+ * // Update organization using your customer ID
320
+ * const response = await scalekitClient.organization.updateOrganizationByExternalId(
321
+ * 'customer_12345',
322
+ * { displayName: 'New Company Name' }
323
+ * );
324
+ *
325
+ * @example
326
+ * // Update metadata for reporting and analytics
327
+ * await scalekitClient.organization.updateOrganizationByExternalId('customer_12345', {
328
+ * metadata: {
329
+ * accountManager: 'john@example.com',
330
+ * renewalDate: '2025-12-31',
331
+ * tier: 'enterprise'
332
+ * }
333
+ * });
334
+ *
335
+ * @example
336
+ * // Use in API endpoints with your customer identifiers
337
+ * app.patch('/api/customers/:customerId', async (req, res) => {
338
+ * const { customerId } = req.params;
339
+ * const { name } = req.body;
340
+ *
341
+ * const response = await scalekitClient.organization.updateOrganizationByExternalId(
342
+ * customerId,
343
+ * { displayName: name }
344
+ * );
345
+ *
346
+ * res.json({ organization: response.organization });
347
+ * });
348
+ *
349
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | Update Organization API}
350
+ * @see {@link updateOrganization} - Update using Scalekit ID
351
+ * @see {@link getOrganizationByExternalId} - Retrieve organization by external ID
100
352
  */
101
- async updateOrganizationByExternalId(externalId: string, organization: PartialMessage<UpdateOrganization>): Promise<UpdateOrganizationResponse> {
102
- return this.coreClient.connectExec(
103
- this.client.updateOrganization,
104
- {
105
- identities: { case: "externalId", value: externalId, },
106
- organization
107
- },
108
- )
353
+ async updateOrganizationByExternalId(
354
+ externalId: string,
355
+ organization: PartialMessage<UpdateOrganization>
356
+ ): Promise<UpdateOrganizationResponse> {
357
+ return this.coreClient.connectExec(this.client.updateOrganization, {
358
+ identities: { case: "externalId", value: externalId },
359
+ organization,
360
+ });
109
361
  }
110
362
 
111
363
  /**
112
- * Delete an organization by id
113
- * @param {string} organizationId The organization id
114
- * @returns {Promise<Empty>} Returns nothing
364
+ * Permanently deletes an organization from your Scalekit environment.
365
+ *
366
+ * This operation removes the organization and all associated data including SSO connections,
367
+ * users, and settings. This action cannot be undone, so use with caution.
368
+ *
369
+ * @param {string} organizationId - The Scalekit organization identifier to delete
370
+ *
371
+ * @returns {Promise<Empty>} Empty response on successful deletion
372
+ *
373
+ * @throws {Error} If the organization is not found or deletion fails
374
+ *
375
+ * @example
376
+ * // Delete an organization
377
+ * await scalekitClient.organization.deleteOrganization('org_12345');
378
+ * console.log('Organization deleted successfully');
379
+ *
380
+ * @example
381
+ * // Delete with confirmation flow
382
+ * const confirmDelete = await askUserConfirmation(
383
+ * 'Are you sure you want to delete this organization? This cannot be undone.'
384
+ * );
385
+ *
386
+ * if (confirmDelete) {
387
+ * try {
388
+ * await scalekitClient.organization.deleteOrganization(orgId);
389
+ * console.log('Organization deleted');
390
+ * } catch (error) {
391
+ * console.error('Failed to delete organization:', error);
392
+ * }
393
+ * }
394
+ *
395
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | Delete Organization API}
396
+ * @see {@link getOrganization} - Check if organization exists before deletion
115
397
  */
116
398
  async deleteOrganization(organizationId: string): Promise<Empty> {
117
- return this.coreClient.connectExec(
118
- this.client.deleteOrganization,
119
- {
120
- identities: { case: "id", value: organizationId, },
121
- },
122
- )
399
+ return this.coreClient.connectExec(this.client.deleteOrganization, {
400
+ identities: { case: "id", value: organizationId },
401
+ });
123
402
  }
124
403
 
125
404
  /**
126
- * Generate admin portal link for an organization
127
- * @param organizationId The organization id
128
- * @returns {Promise<Link>} The admin portal link object with expiration time and location
405
+ * Creates a single use Admin Portal URL valid for 1 minute.
406
+ *
407
+ * Once the generated admin portal URL is accessed or rendered, a temporary session of 6 hours
408
+ * is created to allow the admin to update SSO/SCIM configuration.
409
+ *
410
+ *
411
+ * @param {string} organizationId - The Scalekit organization ID
412
+ *
413
+ * @returns {Promise<Link>} Link object containing:
414
+ * - location: The complete portal URL to redirect the admin to
415
+ * - expiresAt: Timestamp when the link expires (60 seconds from generation)
416
+ *
417
+ * @throws {Error} When the link generation fails
418
+ *
419
+ * @example
420
+ * // Generate admin portal link
421
+ * app.get('/admin/sso-settings', async (req, res) => {
422
+ * const organizationId = req.user.organizationId;
423
+ *
424
+ * try {
425
+ * const link = await scalekitClient.organization.generatePortalLink(organizationId);
426
+ *
427
+ * // Redirect the admin to the portal
428
+ * res.redirect(link.location);
429
+ * } catch (error) {
430
+ * console.error('Failed to generate portal link:', error);
431
+ * res.status(500).send('Unable to access admin portal');
432
+ * }
433
+ * });
434
+ *
435
+ *
436
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | Generate Portal Link API}
437
+ * @see {@link https://docs.scalekit.com/authenticate/sso/admin-portal/ | Admin Portal Guide}
129
438
  */
130
439
  async generatePortalLink(organizationId: string): Promise<Link> {
131
440
  const response = await this.coreClient.connectExec(
132
441
  this.client.generatePortalLink,
133
442
  {
134
- id: organizationId
135
- },
136
- )
443
+ id: organizationId,
444
+ }
445
+ );
137
446
  if (!response.link) {
138
- throw new Error('Error generating portal link');
447
+ throw new Error("Error generating portal link");
139
448
  }
140
449
 
141
- return response.link
450
+ return response.link;
142
451
  }
143
452
 
144
453
  /**
145
- * Update organization settings for an organization
146
- * @param organizationId The organization id
147
- * @param settings The organization settings
148
- * @returns {Promise<GetOrganizationResponse>} The updated organization
454
+ * Updates configuration settings and feature flags for an organization.
455
+ *
456
+ * Use this method to enable or disable organization-level features such as SSO configuration,
457
+ * directory synchronization, session management, and other organization-specific settings.
458
+ * This allows you to customize the capabilities available to each organization based on
459
+ * their subscription tier or requirements.
460
+ *
461
+ * @param {string} organizationId - The Scalekit organization identifier (format: "org_...")
462
+ * @param {OrganizationSettings} settings - Configuration settings object containing:
463
+ * - features: Array of feature objects, each with:
464
+ * - name: Feature identifier (e.g., "sso", "directory_sync")
465
+ * - enabled: Boolean flag to enable/disable the feature
466
+ *
467
+ * @returns {Promise<GetOrganizationResponse>} Response containing:
468
+ * - organization: Complete organization object with updated settings
469
+ *
470
+ * @throws {Error} If the organization is not found or settings update fails
471
+ *
472
+ * @example
473
+ * // Enable SSO and directory sync for an organization
474
+ * const response = await scalekitClient.organization.updateOrganizationSettings('org_12345', {
475
+ * features: [
476
+ * { name: 'sso', enabled: true },
477
+ * { name: 'directory_sync', enabled: true }
478
+ * ]
479
+ * });
480
+ *
481
+ * console.log('Settings updated:', response.organization.settings);
482
+ *
483
+ *
484
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | Update Organization Settings API}
485
+ * @see {@link getOrganization} - Retrieve current organization settings
486
+ * @see {@link upsertUserManagementSettings} - Update user management settings
149
487
  */
150
- async updateOrganizationSettings(organizationId: string, settings: OrganizationSettings): Promise<GetOrganizationResponse> {
488
+ async updateOrganizationSettings(
489
+ organizationId: string,
490
+ settings: OrganizationSettings
491
+ ): Promise<GetOrganizationResponse> {
151
492
  const request = {
152
493
  id: organizationId,
153
494
  settings: {
154
- features: settings.features.map(feature => ({
495
+ features: settings.features.map((feature) => ({
155
496
  name: feature.name,
156
- enabled: feature.enabled
157
- }))
158
- }
159
- }
160
-
497
+ enabled: feature.enabled,
498
+ })),
499
+ },
500
+ };
501
+
161
502
  return this.coreClient.connectExec(
162
503
  this.client.updateOrganizationSettings,
163
- request,
164
- )
504
+ request
505
+ );
165
506
  }
166
507
 
167
508
  /**
168
- * Upsert organization-level user management settings such as maximum allowed users.
169
- * @param organizationId The organization id
170
- * @param settings User management settings to apply
171
- * @returns {Promise<OrganizationUserManagementSettingsMessage | undefined>} The updated settings
509
+ * Creates or updates user management settings for an organization.
510
+ *
511
+ * This method allows you to configure user-related constraints and policies at the
512
+ * organization level, such as setting a maximum number of allowed users. This is
513
+ * useful for enforcing subscription limits, preventing overuse, or managing capacity.
514
+ * If settings already exist, they will be updated; otherwise, new settings are created.
515
+ *
516
+ * @param {string} organizationId - The Scalekit organization identifier (format: "org_...")
517
+ * @param {OrganizationUserManagementSettingsInput} settings - User management configuration:
518
+ * - maxAllowedUsers?: Maximum number of users allowed in the organization.
519
+ * Set to null or undefined to remove the limit.
520
+ *
521
+ * @returns {Promise<OrganizationUserManagementSettingsMessage | undefined>} The updated settings object containing:
522
+ * - maxAllowedUsers: The configured user limit (if set)
523
+ *
524
+ * @throws {Error} If the organization is not found or settings update fails
525
+ *
526
+ * @example
527
+ * // Set maximum user limit for an organization
528
+ * const settings = await scalekitClient.organization.upsertUserManagementSettings(
529
+ * 'org_12345',
530
+ * { maxAllowedUsers: 100 }
531
+ * );
532
+ *
533
+ * console.log('Max users allowed:', settings?.maxAllowedUsers);
534
+ *
535
+ * @example
536
+ * // Remove user limit (set to unlimited)
537
+ * await scalekitClient.organization.upsertUserManagementSettings('org_12345', {
538
+ * maxAllowedUsers: null
539
+ * });
540
+ *
541
+ * @see {@link https://docs.scalekit.com/apis/#tag/organizations | User Management Settings API}
542
+ * @see {@link getOrganization} - Retrieve current organization settings
543
+ * @see {@link updateOrganizationSettings} - Update other organization settings
172
544
  */
173
- async upsertUserManagementSettings(organizationId: string, settings: OrganizationUserManagementSettingsInput): Promise<OrganizationUserManagementSettingsMessage | undefined> {
174
- const requestSettings: PartialMessage<OrganizationUserManagementSettingsMessage> = {};
175
- if (settings.maxAllowedUsers !== undefined && settings.maxAllowedUsers !== null) {
545
+ async upsertUserManagementSettings(
546
+ organizationId: string,
547
+ settings: OrganizationUserManagementSettingsInput
548
+ ): Promise<OrganizationUserManagementSettingsMessage | undefined> {
549
+ const requestSettings: PartialMessage<OrganizationUserManagementSettingsMessage> =
550
+ {};
551
+ if (
552
+ settings.maxAllowedUsers !== undefined &&
553
+ settings.maxAllowedUsers !== null
554
+ ) {
176
555
  requestSettings.maxAllowedUsers = settings.maxAllowedUsers;
177
556
  }
178
557
 
@@ -187,4 +566,3 @@ export default class OrganizationClient {
187
566
  return response.settings;
188
567
  }
189
568
  }
190
-