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