@scalekit-sdk/node 2.1.7 → 2.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/buf.gen.yaml +1 -0
  2. package/lib/auth.d.ts +41 -9
  3. package/lib/auth.js +44 -12
  4. package/lib/auth.js.map +1 -1
  5. package/lib/connection.d.ts +195 -21
  6. package/lib/connection.js +197 -23
  7. package/lib/connection.js.map +1 -1
  8. package/lib/core.d.ts +2 -2
  9. package/lib/core.js +13 -12
  10. package/lib/core.js.map +1 -1
  11. package/lib/directory.d.ts +293 -40
  12. package/lib/directory.js +308 -44
  13. package/lib/directory.js.map +1 -1
  14. package/lib/domain.d.ts +166 -18
  15. package/lib/domain.js +178 -29
  16. package/lib/domain.js.map +1 -1
  17. package/lib/organization.d.ts +404 -44
  18. package/lib/organization.js +419 -54
  19. package/lib/organization.js.map +1 -1
  20. package/lib/permission.d.ts +179 -35
  21. package/lib/permission.js +190 -38
  22. package/lib/permission.js.map +1 -1
  23. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.d.ts +3 -3
  24. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js +2 -2
  25. package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js.map +1 -1
  26. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.d.ts +16 -16
  27. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js +21 -21
  28. package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js.map +1 -1
  29. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.d.ts +82 -0
  30. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js +90 -0
  31. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js.map +1 -0
  32. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.d.ts +647 -0
  33. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js +993 -0
  34. package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js.map +1 -0
  35. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.d.ts +142 -0
  36. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js +165 -1
  37. package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js.map +1 -1
  38. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.d.ts +1 -10
  39. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js +0 -9
  40. package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js.map +1 -1
  41. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.d.ts +28 -63
  42. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js +9 -90
  43. package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js.map +1 -1
  44. package/lib/pkg/grpc/scalekit/v1/users/users_pb.d.ts +2 -2
  45. package/lib/pkg/grpc/scalekit/v1/users/users_pb.js +1 -1
  46. package/lib/pkg/grpc/scalekit/v1/users/users_pb.js.map +1 -1
  47. package/lib/role.d.ts +252 -56
  48. package/lib/role.js +262 -62
  49. package/lib/role.js.map +1 -1
  50. package/lib/scalekit.d.ts +323 -54
  51. package/lib/scalekit.js +354 -76
  52. package/lib/scalekit.js.map +1 -1
  53. package/lib/session.d.ts +235 -22
  54. package/lib/session.js +237 -24
  55. package/lib/session.js.map +1 -1
  56. package/lib/user.d.ts +571 -53
  57. package/lib/user.js +598 -89
  58. package/lib/user.js.map +1 -1
  59. package/lib/webauthn.d.ts +33 -0
  60. package/lib/webauthn.js +80 -0
  61. package/lib/webauthn.js.map +1 -0
  62. package/package.json +2 -2
  63. package/src/auth.ts +53 -19
  64. package/src/connection.ts +237 -62
  65. package/src/core.ts +39 -33
  66. package/src/directory.ts +356 -98
  67. package/src/domain.ts +215 -68
  68. package/src/organization.ts +490 -112
  69. package/src/permission.ts +234 -88
  70. package/src/pkg/grpc/scalekit/v1/auth/auth_connect.ts +3 -3
  71. package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +24 -24
  72. package/src/pkg/grpc/scalekit/v1/auth/webauthn_connect.ts +89 -0
  73. package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +1263 -0
  74. package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +217 -0
  75. package/src/pkg/grpc/scalekit/v1/connections/connections_connect.ts +1 -10
  76. package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +42 -129
  77. package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +3 -3
  78. package/src/role.ts +336 -136
  79. package/src/scalekit.ts +478 -149
  80. package/src/session.ts +266 -63
  81. package/src/user.ts +675 -168
  82. package/src/webauthn.ts +98 -0
package/src/domain.ts CHANGED
@@ -1,10 +1,28 @@
1
- import { PromiseClient } from '@connectrpc/connect';
2
- import GrpcConnect from './connect';
3
- import CoreClient from './core';
4
- import { DomainService } from './pkg/grpc/scalekit/v1/domains/domains_connect';
5
- import { CreateDomainResponse, GetDomainResponse, ListDomainResponse, DomainType } from './pkg/grpc/scalekit/v1/domains/domains_pb';
6
- import { Empty } from '@bufbuild/protobuf';
1
+ import { PromiseClient } from "@connectrpc/connect";
2
+ import GrpcConnect from "./connect";
3
+ import CoreClient from "./core";
4
+ import { DomainService } from "./pkg/grpc/scalekit/v1/domains/domains_connect";
5
+ import {
6
+ CreateDomainResponse,
7
+ GetDomainResponse,
8
+ ListDomainResponse,
9
+ DomainType,
10
+ } from "./pkg/grpc/scalekit/v1/domains/domains_pb";
11
+ import { Empty } from "@bufbuild/protobuf";
7
12
 
13
+ /**
14
+ * Client for managing domains for organizations.
15
+ *
16
+ * Domains enable automatic organization identification during SSO flows based on user email addresses.
17
+ * You can configure domains as ORGANIZATION_DOMAIN (for SSO routing) or ALLOWED_EMAIL_DOMAIN
18
+ * (for restricting which email domains can automatically join an organization).
19
+ *
20
+ * @example
21
+ * const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
22
+ * const domainClient = scalekitClient.domain;
23
+ *
24
+ * @see {@link https://docs.scalekit.com/apis/#tag/domains | Domain API Documentation}
25
+ */
8
26
  export default class DomainClient {
9
27
  private client: PromiseClient<typeof DomainService>;
10
28
  constructor(
@@ -15,89 +33,218 @@ export default class DomainClient {
15
33
  }
16
34
 
17
35
  /**
18
- * Create a domain for an organization with the given name. Optionally, you can provide an external id.
19
- * @param {string} organizationId The organization id
20
- * @param {string} name The domain name
21
- * @param {object} options The options to create a domain
22
- * @param {DomainType | string} options.domainType The type of domain (ALLOWED_EMAIL_DOMAIN or ORGANIZATION_DOMAIN)
23
- * @returns {Promise<CreateDomainResponse>} The created domain
24
- */
25
- async createDomain(organizationId: string, name: string, options?: { domainType?: DomainType | string }): Promise<CreateDomainResponse> {
36
+ * Adds a new domain configuration to an organization for SSO routing or user suggestions.
37
+ *
38
+ * Domains serve two purposes based on their type:
39
+ * - **ORGANIZATION_DOMAIN**: Used to identify the SSO connection for the organization. When users
40
+ * authenticate with email addresses from this domain, they're automatically routed to the
41
+ * organization's SSO provider.
42
+ * - **ALLOWED_EMAIL_DOMAIN**: Enables users to join the organization with automatic suggestions
43
+ * in the organization switcher during signup/login.
44
+ *
45
+ * Note: Public disposable domains (gmail.com, outlook.com, etc.) are automatically blocked for security.
46
+ *
47
+ * @param {string} organizationId - The organization ID (format: "org_...")
48
+ * @param {string} name - The domain name (e.g., "acme.com", "example.org")
49
+ * @param {object} [options] - Optional domain configuration
50
+ * @param {DomainType | string} [options.domainType] - Domain type: 'ALLOWED_EMAIL_DOMAIN' or 'ORGANIZATION_DOMAIN'
51
+ *
52
+ * @returns {Promise<CreateDomainResponse>} The created domain with ID and verification status
53
+ *
54
+ * @throws {Error} If domain type is invalid
55
+ * @throws {Error} If domain is a blocked public domain (gmail.com, etc.)
56
+ *
57
+ * @example
58
+ * // Add SSO routing domain
59
+ * const response = await scalekitClient.domain.createDomain(
60
+ * 'org_123456',
61
+ * 'acme.com',
62
+ * { domainType: 'ORGANIZATION_DOMAIN' }
63
+ * );
64
+ * console.log('Domain created:', response.domain.id);
65
+ * console.log('Verification required:', response.domain.verificationStatus);
66
+ *
67
+ * @example
68
+ * // Add allowed email domain for user suggestions
69
+ * await scalekitClient.domain.createDomain(
70
+ * 'org_123456',
71
+ * 'acme.io',
72
+ * { domainType: 'ALLOWED_EMAIL_DOMAIN' }
73
+ * );
74
+ *
75
+ * @example
76
+ * // Create domain with default type
77
+ * await scalekitClient.domain.createDomain('org_123456', 'company.com');
78
+ *
79
+ * @example
80
+ * // Configure multiple domains for an organization
81
+ * const domains = ['acme.com', 'acme.io', 'acme.net'];
82
+ * for (const domain of domains) {
83
+ * await scalekitClient.domain.createDomain('org_123456', domain, {
84
+ * domainType: 'ORGANIZATION_DOMAIN'
85
+ * });
86
+ * }
87
+ *
88
+ * @see {@link https://docs.scalekit.com/apis/#tag/domains | Create Domain API}
89
+ * @see {@link listDomains} - List all domains for an organization
90
+ * @see {@link deleteDomain} - Remove a domain
91
+ */
92
+ async createDomain(
93
+ organizationId: string,
94
+ name: string,
95
+ options?: { domainType?: DomainType | string }
96
+ ): Promise<CreateDomainResponse> {
26
97
  let domainTypeValue: DomainType | undefined;
27
98
  if (options?.domainType) {
28
- if (typeof options.domainType === 'string') {
29
- domainTypeValue = DomainType[options.domainType as keyof typeof DomainType];
99
+ if (typeof options.domainType === "string") {
100
+ domainTypeValue =
101
+ DomainType[options.domainType as keyof typeof DomainType];
30
102
  if (domainTypeValue === undefined) {
31
- throw new Error('Invalid domain type');
103
+ throw new Error("Invalid domain type");
32
104
  }
33
105
  } else {
34
106
  domainTypeValue = options.domainType;
35
107
  }
36
108
  }
37
109
 
38
- return this.coreClient.connectExec(
39
- this.client.createDomain,
40
- {
41
- identities: {
42
- case: 'organizationId',
43
- value: organizationId
44
- },
45
- domain: {
46
- domain: name,
47
- ...(domainTypeValue && { domainType: domainTypeValue })
48
- }
49
- }
50
- )
110
+ return this.coreClient.connectExec(this.client.createDomain, {
111
+ identities: {
112
+ case: "organizationId",
113
+ value: organizationId,
114
+ },
115
+ domain: {
116
+ domain: name,
117
+ ...(domainTypeValue && { domainType: domainTypeValue }),
118
+ },
119
+ });
51
120
  }
52
121
 
53
122
  /**
54
- * Get a specific domain by ID for an organization
55
- * @param organizationId The organization id
56
- * @param domainId The domain id
57
- * @returns {Promise<GetDomainResponse>} The domain details
123
+ * Retrieves detailed information about a specific domain configuration.
124
+ *
125
+ * Returns complete domain details including the domain name, type (ORGANIZATION_DOMAIN or
126
+ * ALLOWED_EMAIL_DOMAIN), verification status, and when it was created/updated. Use this to
127
+ * check domain configuration status or verification requirements.
128
+ *
129
+ * @param {string} organizationId - The organization ID (format: "org_...")
130
+ * @param {string} domainId - The domain ID (format: "domain_...")
131
+ *
132
+ * @returns {Promise<GetDomainResponse>} Complete domain configuration and status
133
+ *
134
+ * @example
135
+ * // Check domain verification status
136
+ * const response = await scalekitClient.domain.getDomain(
137
+ * 'org_123456',
138
+ * 'domain_abc123'
139
+ * );
140
+ * console.log('Domain:', response.domain.domain);
141
+ * console.log('Type:', response.domain.domainType);
142
+ * console.log('Verified:', response.domain.verificationStatus);
143
+ *
144
+ * @example
145
+ * // Verify domain configuration after creation
146
+ * const created = await scalekitClient.domain.createDomain(
147
+ * 'org_123456',
148
+ * 'acme.com',
149
+ * { domainType: 'ORGANIZATION_DOMAIN' }
150
+ * );
151
+ *
152
+ * // Later, check if domain has been verified
153
+ * const domain = await scalekitClient.domain.getDomain(
154
+ * 'org_123456',
155
+ * created.domain.id
156
+ * );
157
+ * if (domain.domain.verificationStatus === 'VERIFIED') {
158
+ * console.log('Domain is ready for SSO routing');
159
+ * }
160
+ *
161
+ * @see {@link https://docs.scalekit.com/apis/#tag/domains | Get Domain API}
162
+ * @see {@link createDomain} - Add a new domain
163
+ * @see {@link listDomains} - List all domains for an organization
58
164
  */
59
- async getDomain(organizationId: string, domainId: string): Promise<GetDomainResponse> {
60
- return this.coreClient.connectExec(
61
- this.client.getDomain,
62
- {
63
- id: domainId,
64
- identities: {
65
- case: 'organizationId',
66
- value: organizationId
67
- }
68
- }
69
- );
165
+ async getDomain(
166
+ organizationId: string,
167
+ domainId: string
168
+ ): Promise<GetDomainResponse> {
169
+ return this.coreClient.connectExec(this.client.getDomain, {
170
+ id: domainId,
171
+ identities: {
172
+ case: "organizationId",
173
+ value: organizationId,
174
+ },
175
+ });
70
176
  }
71
177
 
72
178
  /**
73
- * List domains for an organization
74
- * @param organizationId The organization id
75
- * @returns {Promise<ListDomainResponse>} The list of domains for the organization
179
+ * Retrieves all domain configurations for an organization.
180
+ *
181
+ * Returns a complete list of domains configured for the organization, including both
182
+ * ORGANIZATION_DOMAIN (for SSO routing) and ALLOWED_EMAIL_DOMAIN (for user suggestions).
183
+ * Each domain includes its verification status, type, and configuration details.
184
+ *
185
+ * Use this to audit domain configuration, check which domains are verified, or display
186
+ * domain settings in an admin dashboard.
187
+ *
188
+ * @param {string} organizationId - The organization ID (format: "org_...")
189
+ *
190
+ * @returns {Promise<ListDomainResponse>} List of all domains with their configurations
191
+ *
192
+ * @example
193
+ * // List all domains for an organization
194
+ * const response = await scalekitClient.domain.listDomains('org_123456');
195
+ * console.log(`Found ${response.domains.length} domains`);
196
+ * response.domains.forEach(domain => {
197
+ * console.log(`- ${domain.domain} (${domain.domainType}): ${domain.verificationStatus}`);
198
+ * });
199
+ *
200
+ * @example
201
+ * // Check which domains are verified for SSO
202
+ * const response = await scalekitClient.domain.listDomains('org_123456');
203
+ * const verifiedSSODomains = response.domains.filter(
204
+ * d => d.domainType === 'ORGANIZATION_DOMAIN' && d.verificationStatus === 'VERIFIED'
205
+ * );
206
+ * console.log('Verified SSO domains:', verifiedSSODomains.map(d => d.domain));
207
+ * @see {@link https://docs.scalekit.com/apis/#tag/domains | List Domains API}
208
+ * @see {@link createDomain} - Add a new domain
209
+ * @see {@link getDomain} - Get details for a specific domain
210
+ * @see {@link deleteDomain} - Remove a domain
76
211
  */
77
212
  async listDomains(organizationId: string): Promise<ListDomainResponse> {
78
- return this.coreClient.connectExec(
79
- this.client.listDomains,
80
- {
81
- identities: {
82
- case: 'organizationId',
83
- value: organizationId
84
- }
213
+ return this.coreClient.connectExec(this.client.listDomains, {
214
+ identities: {
215
+ case: "organizationId",
216
+ value: organizationId,
85
217
  },
86
- );
218
+ });
87
219
  }
88
220
 
221
+ /**
222
+ * Deletes a domain from an organization.
223
+ *
224
+ * Removes the domain configuration from the organization. Users with email addresses from
225
+ * this domain will no longer be automatically routed to this organization's SSO connection.
226
+ *
227
+ * @param {string} organizationId - The organization ID
228
+ * @param {string} domainId - The domain ID to delete
229
+ *
230
+ * @returns {Promise<Empty>} Empty response on successful deletion
231
+ *
232
+ * @example
233
+ * // Remove a domain from an organization
234
+ * await scalekitClient.domain.deleteDomain('org_123456', 'domain_abc123');
235
+ * console.log('Domain deleted successfully');
236
+ *
237
+ * @see {@link https://docs.scalekit.com/apis/#tag/domains | Delete Domain API}
238
+ * @see {@link createDomain} - Add a new domain
239
+ * @see {@link listDomains} - List all domains for an organization
240
+ */
89
241
  async deleteDomain(organizationId: string, domainId: string): Promise<Empty> {
90
- return this.coreClient.connectExec(
91
- this.client.deleteDomain,
92
- {
93
- id: domainId,
94
- identities: {
95
- case: 'organizationId',
96
- value: organizationId
97
- }
98
- }
99
- );
242
+ return this.coreClient.connectExec(this.client.deleteDomain, {
243
+ id: domainId,
244
+ identities: {
245
+ case: "organizationId",
246
+ value: organizationId,
247
+ },
248
+ });
100
249
  }
101
-
102
250
  }
103
-