@scalekit-sdk/node 2.2.0-beta.1 → 2.2.1

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 (226) hide show
  1. package/README.md +5 -5
  2. package/{reference.md → REFERENCE.md} +530 -748
  3. package/lib/auth.d.ts +9 -6
  4. package/lib/auth.js +4 -20
  5. package/lib/auth.js.map +1 -1
  6. package/lib/connect.d.ts +3 -3
  7. package/lib/connect.js +1 -2
  8. package/lib/connect.js.map +1 -1
  9. package/lib/connection.d.ts +2 -2
  10. package/lib/connection.js +4 -4
  11. package/lib/connection.js.map +1 -1
  12. package/lib/core.js +2 -2
  13. package/lib/core.js.map +1 -1
  14. package/lib/directory.d.ts +2 -2
  15. package/lib/directory.js +7 -7
  16. package/lib/directory.js.map +1 -1
  17. package/lib/domain.d.ts +6 -5
  18. package/lib/domain.js +4 -5
  19. package/lib/domain.js.map +1 -1
  20. package/lib/errors/base-exception.d.ts +1 -1
  21. package/lib/errors/base-exception.js +1 -1
  22. package/lib/errors/base-exception.js.map +1 -1
  23. package/lib/organization.d.ts +10 -9
  24. package/lib/organization.js +11 -9
  25. package/lib/organization.js.map +1 -1
  26. package/lib/passwordless.d.ts +2 -2
  27. package/lib/passwordless.js +8 -7
  28. package/lib/passwordless.js.map +1 -1
  29. package/lib/permission.d.ts +6 -5
  30. package/lib/permission.js +10 -11
  31. package/lib/permission.js.map +1 -1
  32. package/lib/pkg/grpc/buf/validate/validate_pb.d.ts +7 -0
  33. package/lib/pkg/grpc/buf/validate/validate_pb.js +25 -0
  34. package/lib/pkg/grpc/buf/validate/validate_pb.js.map +1 -0
  35. package/lib/pkg/grpc/google/api/annotations_pb.d.ts +7 -0
  36. package/lib/pkg/grpc/google/api/annotations_pb.js +25 -0
  37. package/lib/pkg/grpc/google/api/annotations_pb.js.map +1 -0
  38. package/lib/pkg/grpc/google/api/field_behavior_pb.d.ts +7 -0
  39. package/lib/pkg/grpc/google/api/field_behavior_pb.js +25 -0
  40. package/lib/pkg/grpc/google/api/field_behavior_pb.js.map +1 -0
  41. package/lib/pkg/grpc/google/api/visibility_pb.d.ts +7 -0
  42. package/lib/pkg/grpc/google/api/visibility_pb.js +25 -0
  43. package/lib/pkg/grpc/google/api/visibility_pb.js.map +1 -0
  44. package/lib/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.d.ts +7 -0
  45. package/lib/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.js +25 -0
  46. package/lib/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.js.map +1 -0
  47. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.d.ts +48 -42
  48. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.js +27 -263
  49. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.js.map +1 -1
  50. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.d.ts +371 -325
  51. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js +132 -835
  52. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js.map +1 -1
  53. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_pb.d.ts +113 -87
  54. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_pb.js +45 -201
  55. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_pb.js.map +1 -1
  56. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.d.ts +262 -265
  57. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js +92 -938
  58. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js.map +1 -1
  59. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.d.ts +162 -157
  60. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js +42 -313
  61. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js.map +1 -1
  62. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.d.ts +1488 -1459
  63. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js +353 -2362
  64. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js.map +1 -1
  65. package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.d.ts +520 -483
  66. package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.js +224 -1555
  67. package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.js.map +1 -1
  68. package/lib/pkg/grpc/scalekit/v1/domains/domains_pb.d.ts +219 -191
  69. package/lib/pkg/grpc/scalekit/v1/domains/domains_pb.js +96 -553
  70. package/lib/pkg/grpc/scalekit/v1/domains/domains_pb.js.map +1 -1
  71. package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.d.ts +76 -102
  72. package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.js +37 -393
  73. package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.js.map +1 -1
  74. package/lib/pkg/grpc/scalekit/v1/options/options_pb.d.ts +36 -26
  75. package/lib/pkg/grpc/scalekit/v1/options/options_pb.js +20 -69
  76. package/lib/pkg/grpc/scalekit/v1/options/options_pb.js.map +1 -1
  77. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.d.ts +447 -400
  78. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js +163 -1238
  79. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js.map +1 -1
  80. package/lib/pkg/grpc/scalekit/v1/roles/roles_pb.d.ts +622 -556
  81. package/lib/pkg/grpc/scalekit/v1/roles/roles_pb.js +201 -1718
  82. package/lib/pkg/grpc/scalekit/v1/roles/roles_pb.js.map +1 -1
  83. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_pb.d.ts +135 -132
  84. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_pb.js +55 -518
  85. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_pb.js.map +1 -1
  86. package/lib/pkg/grpc/scalekit/v1/users/users_pb.d.ts +445 -413
  87. package/lib/pkg/grpc/scalekit/v1/users/users_pb.js +142 -1490
  88. package/lib/pkg/grpc/scalekit/v1/users/users_pb.js.map +1 -1
  89. package/lib/role.d.ts +8 -7
  90. package/lib/role.js +14 -14
  91. package/lib/role.js.map +1 -1
  92. package/lib/scalekit.d.ts +0 -4
  93. package/lib/scalekit.js +0 -4
  94. package/lib/scalekit.js.map +1 -1
  95. package/lib/session.js +15 -24
  96. package/lib/session.js.map +1 -1
  97. package/lib/user.d.ts +6 -5
  98. package/lib/user.js +17 -20
  99. package/lib/user.js.map +1 -1
  100. package/lib/webauthn.js +6 -5
  101. package/lib/webauthn.js.map +1 -1
  102. package/package.json +12 -10
  103. package/.github/dependabot.yml +0 -10
  104. package/.nvmrc +0 -1
  105. package/buf.gen.yaml +0 -24
  106. package/jest.config.js +0 -15
  107. package/lib/connected-accounts.d.ts +0 -119
  108. package/lib/connected-accounts.js +0 -241
  109. package/lib/connected-accounts.js.map +0 -1
  110. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.d.ts +0 -19
  111. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.js +0 -27
  112. package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.js.map +0 -1
  113. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.d.ts +0 -118
  114. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js +0 -126
  115. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js.map +0 -1
  116. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_connect.d.ts +0 -37
  117. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_connect.js +0 -45
  118. package/lib/pkg/grpc/scalekit/v1/auth/passwordless_connect.js.map +0 -1
  119. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.d.ts +0 -82
  120. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js +0 -90
  121. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js.map +0 -1
  122. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.d.ts +0 -87
  123. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.js +0 -95
  124. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.js.map +0 -1
  125. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.d.ts +0 -718
  126. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.js +0 -893
  127. package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.js.map +0 -1
  128. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.d.ts +0 -172
  129. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js +0 -180
  130. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js.map +0 -1
  131. package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.d.ts +0 -154
  132. package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.js +0 -162
  133. package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.js.map +0 -1
  134. package/lib/pkg/grpc/scalekit/v1/domains/domains_connect.d.ts +0 -73
  135. package/lib/pkg/grpc/scalekit/v1/domains/domains_connect.js +0 -81
  136. package/lib/pkg/grpc/scalekit/v1/domains/domains_connect.js.map +0 -1
  137. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.d.ts +0 -171
  138. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.js +0 -179
  139. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.js.map +0 -1
  140. package/lib/pkg/grpc/scalekit/v1/roles/roles_connect.d.ts +0 -250
  141. package/lib/pkg/grpc/scalekit/v1/roles/roles_connect.js +0 -258
  142. package/lib/pkg/grpc/scalekit/v1/roles/roles_connect.js.map +0 -1
  143. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_connect.d.ts +0 -46
  144. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_connect.js +0 -54
  145. package/lib/pkg/grpc/scalekit/v1/sessions/sessions_connect.js.map +0 -1
  146. package/lib/pkg/grpc/scalekit/v1/tools/tools_connect.d.ts +0 -75
  147. package/lib/pkg/grpc/scalekit/v1/tools/tools_connect.js +0 -83
  148. package/lib/pkg/grpc/scalekit/v1/tools/tools_connect.js.map +0 -1
  149. package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.d.ts +0 -431
  150. package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.js +0 -627
  151. package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.js.map +0 -1
  152. package/lib/pkg/grpc/scalekit/v1/users/users_connect.d.ts +0 -173
  153. package/lib/pkg/grpc/scalekit/v1/users/users_connect.js +0 -181
  154. package/lib/pkg/grpc/scalekit/v1/users/users_connect.js.map +0 -1
  155. package/lib/tools.d.ts +0 -75
  156. package/lib/tools.js +0 -127
  157. package/lib/tools.js.map +0 -1
  158. package/src/auth.ts +0 -99
  159. package/src/connect.ts +0 -33
  160. package/src/connected-accounts.ts +0 -358
  161. package/src/connection.ts +0 -267
  162. package/src/constants/user.ts +0 -22
  163. package/src/core.ts +0 -139
  164. package/src/directory.ts +0 -431
  165. package/src/domain.ts +0 -272
  166. package/src/errors/base-exception.ts +0 -262
  167. package/src/errors/index.ts +0 -3
  168. package/src/errors/specific-exceptions.ts +0 -88
  169. package/src/index.ts +0 -10
  170. package/src/organization.ts +0 -568
  171. package/src/passwordless.ts +0 -138
  172. package/src/permission.ts +0 -310
  173. package/src/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.ts +0 -26
  174. package/src/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.ts +0 -342
  175. package/src/pkg/grpc/scalekit/v1/auth/auth_connect.ts +0 -125
  176. package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +0 -1213
  177. package/src/pkg/grpc/scalekit/v1/auth/passwordless_connect.ts +0 -44
  178. package/src/pkg/grpc/scalekit/v1/auth/passwordless_pb.ts +0 -336
  179. package/src/pkg/grpc/scalekit/v1/auth/webauthn_connect.ts +0 -89
  180. package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +0 -1263
  181. package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +0 -573
  182. package/src/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.ts +0 -94
  183. package/src/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.ts +0 -1294
  184. package/src/pkg/grpc/scalekit/v1/connections/connections_connect.ts +0 -179
  185. package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +0 -3846
  186. package/src/pkg/grpc/scalekit/v1/directories/directories_connect.ts +0 -161
  187. package/src/pkg/grpc/scalekit/v1/directories/directories_pb.ts +0 -2119
  188. package/src/pkg/grpc/scalekit/v1/domains/domains_connect.ts +0 -80
  189. package/src/pkg/grpc/scalekit/v1/domains/domains_pb.ts +0 -855
  190. package/src/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.ts +0 -524
  191. package/src/pkg/grpc/scalekit/v1/options/options_pb.ts +0 -230
  192. package/src/pkg/grpc/scalekit/v1/organizations/organizations_connect.ts +0 -178
  193. package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +0 -1766
  194. package/src/pkg/grpc/scalekit/v1/roles/roles_connect.ts +0 -257
  195. package/src/pkg/grpc/scalekit/v1/roles/roles_pb.ts +0 -2395
  196. package/src/pkg/grpc/scalekit/v1/sessions/sessions_connect.ts +0 -53
  197. package/src/pkg/grpc/scalekit/v1/sessions/sessions_pb.ts +0 -749
  198. package/src/pkg/grpc/scalekit/v1/tools/tools_connect.ts +0 -82
  199. package/src/pkg/grpc/scalekit/v1/tools/tools_pb.ts +0 -847
  200. package/src/pkg/grpc/scalekit/v1/users/users_connect.ts +0 -180
  201. package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +0 -2151
  202. package/src/role.ts +0 -461
  203. package/src/scalekit.ts +0 -809
  204. package/src/session.ts +0 -337
  205. package/src/tools.ts +0 -166
  206. package/src/types/auth.ts +0 -73
  207. package/src/types/organization.ts +0 -12
  208. package/src/types/scalekit.ts +0 -50
  209. package/src/types/user.ts +0 -21
  210. package/src/user.ts +0 -825
  211. package/src/webauthn.ts +0 -98
  212. package/tests/README.md +0 -25
  213. package/tests/connected-accounts.test.ts +0 -472
  214. package/tests/connection.test.ts +0 -42
  215. package/tests/directory.test.ts +0 -46
  216. package/tests/domain.test.ts +0 -293
  217. package/tests/organization.test.ts +0 -81
  218. package/tests/passwordless.test.ts +0 -108
  219. package/tests/permission.test.ts +0 -399
  220. package/tests/role.test.ts +0 -323
  221. package/tests/scalekit.test.ts +0 -104
  222. package/tests/setup.ts +0 -34
  223. package/tests/tools.test.ts +0 -239
  224. package/tests/users.test.ts +0 -168
  225. package/tests/utils/test-data.ts +0 -481
  226. package/tsconfig.json +0 -19
@@ -1,568 +0,0 @@
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
- */
33
- export default class OrganizationClient {
34
- private client: PromiseClient<typeof OrganizationService>;
35
- constructor(
36
- private readonly grpcConncet: GrpcConnect,
37
- private readonly coreClient: CoreClient
38
- ) {
39
- this.client = this.grpcConncet.createClient(OrganizationService);
40
- }
41
-
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
- });
90
- }
91
-
92
- /**
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
136
- */
137
- async listOrganization(options?: {
138
- pageSize?: number;
139
- pageToken?: string;
140
- }): Promise<ListOrganizationsResponse> {
141
- return this.coreClient.connectExec(
142
- this.client.listOrganization,
143
- options ? options : {}
144
- );
145
- }
146
-
147
- /**
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
187
- */
188
- async getOrganization(id: string): Promise<GetOrganizationResponse> {
189
- return this.coreClient.connectExec(this.client.getOrganization, {
190
- identities: { case: "id", value: id },
191
- });
192
- }
193
-
194
- /**
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
234
- */
235
- async getOrganizationByExternalId(
236
- externalId: string
237
- ): Promise<GetOrganizationResponse> {
238
- return this.coreClient.connectExec(this.client.getOrganization, {
239
- identities: { case: "externalId", value: externalId },
240
- });
241
- }
242
-
243
- /**
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
289
- */
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
- });
298
- }
299
-
300
- /**
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
352
- */
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
- });
361
- }
362
-
363
- /**
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
397
- */
398
- async deleteOrganization(organizationId: string): Promise<Empty> {
399
- return this.coreClient.connectExec(this.client.deleteOrganization, {
400
- identities: { case: "id", value: organizationId },
401
- });
402
- }
403
-
404
- /**
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}
438
- */
439
- async generatePortalLink(organizationId: string): Promise<Link> {
440
- const response = await this.coreClient.connectExec(
441
- this.client.generatePortalLink,
442
- {
443
- id: organizationId,
444
- }
445
- );
446
- if (!response.link) {
447
- throw new Error("Error generating portal link");
448
- }
449
-
450
- return response.link;
451
- }
452
-
453
- /**
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
487
- */
488
- async updateOrganizationSettings(
489
- organizationId: string,
490
- settings: OrganizationSettings
491
- ): Promise<GetOrganizationResponse> {
492
- const request = {
493
- id: organizationId,
494
- settings: {
495
- features: settings.features.map((feature) => ({
496
- name: feature.name,
497
- enabled: feature.enabled,
498
- })),
499
- },
500
- };
501
-
502
- return this.coreClient.connectExec(
503
- this.client.updateOrganizationSettings,
504
- request
505
- );
506
- }
507
-
508
- /**
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
544
- */
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
- ) {
555
- requestSettings.maxAllowedUsers = settings.maxAllowedUsers;
556
- }
557
-
558
- const response = await this.coreClient.connectExec(
559
- this.client.upsertUserManagementSettings,
560
- {
561
- organizationId,
562
- settings: requestSettings,
563
- }
564
- );
565
-
566
- return response.settings;
567
- }
568
- }