@scalekit-sdk/node 1.0.6 → 1.0.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 (41) hide show
  1. package/buf.gen.yaml +2 -1
  2. package/lib/core.js +1 -1
  3. package/lib/directory.d.ts +78 -0
  4. package/lib/directory.js +126 -0
  5. package/lib/directory.js.map +1 -0
  6. package/lib/index.d.ts +1 -0
  7. package/lib/index.js +2 -1
  8. package/lib/index.js.map +1 -1
  9. package/lib/organization.d.ts +8 -0
  10. package/lib/organization.js +20 -0
  11. package/lib/organization.js.map +1 -1
  12. package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.d.ts +118 -0
  13. package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.js +126 -0
  14. package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.js.map +1 -0
  15. package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.d.ts +960 -0
  16. package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.js +1429 -0
  17. package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.js.map +1 -0
  18. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.d.ts +10 -1
  19. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.js +9 -0
  20. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.js.map +1 -1
  21. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.d.ts +81 -0
  22. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js +113 -1
  23. package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js.map +1 -1
  24. package/lib/scalekit.d.ts +42 -1
  25. package/lib/scalekit.js +99 -5
  26. package/lib/scalekit.js.map +1 -1
  27. package/lib/types/auth.d.ts +6 -0
  28. package/lib/types/organization.d.ts +7 -0
  29. package/lib/types/organization.js +3 -0
  30. package/lib/types/organization.js.map +1 -0
  31. package/package.json +1 -1
  32. package/src/core.ts +1 -1
  33. package/src/directory.ts +173 -0
  34. package/src/index.ts +1 -0
  35. package/src/organization.ts +24 -1
  36. package/src/pkg/grpc/scalekit/v1/directories/directories_connect.ts +125 -0
  37. package/src/pkg/grpc/scalekit/v1/directories/directories_pb.ts +1838 -0
  38. package/src/pkg/grpc/scalekit/v1/organizations/organizations_connect.ts +10 -1
  39. package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +155 -0
  40. package/src/scalekit.ts +78 -3
  41. package/src/types/organization.ts +8 -0
package/lib/scalekit.js CHANGED
@@ -35,16 +35,20 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
+ const crypto_1 = __importDefault(require("crypto"));
38
39
  const jose = __importStar(require("jose"));
39
40
  const qs_1 = __importDefault(require("qs"));
40
41
  const connect_1 = __importDefault(require("./connect"));
41
42
  const connection_1 = __importDefault(require("./connection"));
42
43
  const user_1 = require("./constants/user");
43
44
  const core_1 = __importDefault(require("./core"));
45
+ const directory_1 = __importDefault(require("./directory"));
44
46
  const domain_1 = __importDefault(require("./domain"));
45
47
  const organization_1 = __importDefault(require("./organization"));
46
48
  const scalekit_1 = require("./types/scalekit");
47
49
  const authorizeEndpoint = "oauth/authorize";
50
+ const WEBHOOK_TOLERANCE_IN_SECONDS = 5 * 60; // 5 minutes
51
+ const WEBHOOK_SIGNATURE_VERSION = "v1";
48
52
  /**
49
53
  * To initiate scalekit
50
54
  * @param {string} envUrl The environment url
@@ -61,6 +65,7 @@ class ScalekitClient {
61
65
  this.organization = new organization_1.default(this.grpcConnect, this.coreClient);
62
66
  this.connection = new connection_1.default(this.grpcConnect, this.coreClient);
63
67
  this.domain = new domain_1.default(this.grpcConnect, this.coreClient);
68
+ this.directory = new directory_1.default(this.grpcConnect, this.coreClient);
64
69
  }
65
70
  /**
66
71
  * Returns the authorization url to initiate the authentication request.
@@ -118,6 +123,17 @@ class ScalekitClient {
118
123
  };
119
124
  });
120
125
  }
126
+ /**
127
+ * Get the idp initiated login claims
128
+ *
129
+ * @param {string} idpInitiatedLoginToken The idp_initiated_login query param from the URL
130
+ * @returns {object} Returns the idp initiated login claims
131
+ */
132
+ getIdpInitiatedLoginClaims(idpInitiatedLoginToken) {
133
+ return __awaiter(this, void 0, void 0, function* () {
134
+ return this.validateToken(idpInitiatedLoginToken);
135
+ });
136
+ }
121
137
  /**
122
138
  * Validates the access token.
123
139
  *
@@ -125,20 +141,98 @@ class ScalekitClient {
125
141
  * @return {Promise<boolean>} Returns true if the token is valid, false otherwise.
126
142
  */
127
143
  validateAccessToken(token) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ try {
146
+ yield this.validateToken(token);
147
+ return true;
148
+ }
149
+ catch (_) {
150
+ return false;
151
+ }
152
+ });
153
+ }
154
+ /**
155
+ * Verifies the payload of the webhook
156
+ *
157
+ * @param {string} secret The secret
158
+ * @param {Record<string, string>} headers The headers
159
+ * @param {string} payload The payload
160
+ * @return {boolean} Returns true if the payload is valid.
161
+ */
162
+ verifyWebhookPayload(secret, headers, payload) {
163
+ const webhookId = headers['webhook-id'];
164
+ const webhookTimestamp = headers['webhook-timestamp'];
165
+ const webhookSignature = headers['webhook-signature'];
166
+ if (!webhookId || !webhookTimestamp || !webhookSignature) {
167
+ throw new Error("Missing required headers");
168
+ }
169
+ const timestamp = this.verifyTimestamp(webhookTimestamp);
170
+ const data = `${webhookId}.${Math.floor(timestamp.getTime() / 1000)}.${payload}`;
171
+ const secretBytes = Buffer.from(secret.split("_")[1], 'base64');
172
+ const computedSignature = this.computeSignature(secretBytes, data);
173
+ const receivedSignatures = webhookSignature.split(" ");
174
+ for (const versionedSignature of receivedSignatures) {
175
+ const [version, signature] = versionedSignature.split(",");
176
+ if (version !== WEBHOOK_SIGNATURE_VERSION) {
177
+ continue;
178
+ }
179
+ if (crypto_1.default.timingSafeEqual(Buffer.from(signature, 'base64'), Buffer.from(computedSignature, 'base64'))) {
180
+ return true;
181
+ }
182
+ }
183
+ throw new Error("Invalid Signature");
184
+ }
185
+ /**
186
+ * Validate token
187
+ *
188
+ * @param {string} token The token to be validated
189
+ * @return {Promise<T>} Returns the payload of the token
190
+ */
191
+ validateToken(token) {
128
192
  return __awaiter(this, void 0, void 0, function* () {
129
193
  yield this.coreClient.getJwks();
130
- const JWKS = jose.createLocalJWKSet({
194
+ const jwks = jose.createLocalJWKSet({
131
195
  keys: this.coreClient.keys
132
196
  });
133
197
  try {
134
- yield jose.jwtVerify(token, JWKS);
135
- return true;
198
+ const { payload } = yield jose.jwtVerify(token, jwks);
199
+ return payload;
136
200
  }
137
- catch (error) {
138
- return false;
201
+ catch (_) {
202
+ throw new Error("Invalid token");
139
203
  }
140
204
  });
141
205
  }
206
+ /**
207
+ * Verify the timestamp
208
+ *
209
+ * @param {string} timestampStr The timestamp string
210
+ * @return {Date} Returns the timestamp
211
+ */
212
+ verifyTimestamp(timestampStr) {
213
+ const now = Math.floor(Date.now() / 1000);
214
+ const timestamp = parseInt(timestampStr, 10);
215
+ if (isNaN(timestamp)) {
216
+ throw new Error("Invalid timestamp");
217
+ }
218
+ if (now - timestamp > WEBHOOK_TOLERANCE_IN_SECONDS) {
219
+ throw new Error("Message timestamp too old");
220
+ }
221
+ if (timestamp > now + WEBHOOK_TOLERANCE_IN_SECONDS) {
222
+ throw new Error("Message timestamp too new");
223
+ }
224
+ return new Date(timestamp * 1000);
225
+ }
226
+ /**
227
+ * Compute the signature
228
+ *
229
+ * @param {Buffer} secretBytes The secret bytes
230
+ * @param {string} data The data to be signed
231
+ * @return {string} Returns the signature
232
+ */
233
+ computeSignature(secretBytes, data) {
234
+ return crypto_1.default.createHmac('sha256', secretBytes).update(data).digest('base64');
235
+ }
142
236
  }
143
237
  exports.default = ScalekitClient;
144
238
  //# sourceMappingURL=scalekit.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scalekit.js","sourceRoot":"","sources":["../src/scalekit.ts"],"names":[],"mappings":";;;;;;;;;;;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,4BAA4B,EAAE,CAAC;YACnD,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACK,gBAAgB,CAAC,WAAmB,EAAE,IAAY;QACxD,OAAO,gBAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChF,CAAC;CACF;AA7OD,iCA6OC"}
@@ -59,3 +59,9 @@ export type TokenResponse = {
59
59
  id_token: string;
60
60
  expires_in: number;
61
61
  };
62
+ export type IdpInitiatedLoginClaims = {
63
+ connection_id: string;
64
+ organization_id: string;
65
+ login_hint: string;
66
+ relay_state?: string;
67
+ };
@@ -0,0 +1,7 @@
1
+ export type OrganizationSettings = {
2
+ features: Feature[];
3
+ };
4
+ export type Feature = {
5
+ name: string;
6
+ enabled: boolean;
7
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=organization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"organization.js","sourceRoot":"","sources":["../../src/types/organization.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.6",
2
+ "version": "1.0.8",
3
3
  "name": "@scalekit-sdk/node",
4
4
  "description": "Official Scalekit Node SDK",
5
5
  "main": "lib/index.js",
package/src/core.ts CHANGED
@@ -20,7 +20,7 @@ export default class CoreClient {
20
20
  public keys: JWK[] = [];
21
21
  public accessToken: string | null = null;
22
22
  public axios: Axios;
23
- public sdkVersion = `Scalekit-Node/1.0.6`;
23
+ public sdkVersion = `Scalekit-Node/1.0.8`;
24
24
  public apiVersion = "20240430";
25
25
  public userAgent = `${this.sdkVersion} Node/${process.version} (${process.platform}; ${os.arch()})`;
26
26
  constructor(
@@ -0,0 +1,173 @@
1
+ import { Timestamp } from '@bufbuild/protobuf';
2
+ import { PromiseClient } from '@connectrpc/connect';
3
+ import GrpcConnect from './connect';
4
+ import CoreClient from './core';
5
+ import { DirectoryService } from './pkg/grpc/scalekit/v1/directories/directories_connect';
6
+ import {
7
+ GetDirectoryResponse,
8
+ Directory,
9
+ ListDirectoriesResponse,
10
+ ListDirectoryGroupsResponse,
11
+ ListDirectoryUsersResponse,
12
+ ToggleDirectoryResponse
13
+ } from './pkg/grpc/scalekit/v1/directories/directories_pb';
14
+
15
+ export default class DirectoryClient {
16
+ private client: PromiseClient<typeof DirectoryService>;
17
+ constructor(
18
+ private readonly grpcConncet: GrpcConnect,
19
+ private readonly coreClient: CoreClient
20
+ ) {
21
+ this.client = this.grpcConncet.createClient(DirectoryService);
22
+ }
23
+
24
+ /**
25
+ * List directories for an organization
26
+ * @param {string} organizationId The organization id
27
+ * @returns {Promise<ListDirectoriesResponse>} Returns the list of directories
28
+ */
29
+ async listDirectories(organizationId: string): Promise<ListDirectoriesResponse> {
30
+ return this.coreClient.connectExec(
31
+ this.client.listDirectories,
32
+ { organizationId }
33
+ )
34
+ }
35
+
36
+ /**
37
+ * Get a directory for an organization
38
+ * @param {string} organizationId The organization id
39
+ * @param {string} directoryId The directory id
40
+ * @returns {Promise<GetDirectoryResponse>} Returns the directory
41
+ */
42
+ async getDirectory(organizationId: string, directoryId: string): Promise<GetDirectoryResponse> {
43
+ return this.coreClient.connectExec(
44
+ this.client.getDirectory,
45
+ { organizationId, id: directoryId }
46
+ )
47
+ }
48
+
49
+ /**
50
+ * Get a directory for an organization
51
+ * @param {string} organizationId The organization id
52
+ * @returns {Promise<Directory>} Returns the directory
53
+ */
54
+ async getPrimaryDirectoryByOrganizationId(organizationId: string): Promise<Directory> {
55
+ const directories = await this.listDirectories(organizationId);
56
+ if (!directories || directories.directories.length === 0) {
57
+ return Promise.reject('directory does not exist for organization');
58
+ }
59
+
60
+ return directories.directories[0];
61
+ }
62
+
63
+ /**
64
+ * List users in a directory for an organization
65
+ * @param {string} organizationId The organization id
66
+ * @param {string} directoryId The directory id
67
+ * @param {object} options The options to list directory users
68
+ * @param {number} options.pageSize The page size
69
+ * @param {string} options.pageToken The page token
70
+ * @param {boolean} options.includeDetail Include detail
71
+ * @param {string} options.directoryGroupId The directory group id
72
+ * @param {string} options.updatedAfter The updated after
73
+ * @returns {Promise<ListDirectoryUsersResponse>} Returns the list of directory users
74
+ */
75
+ async listDirectoryUsers(
76
+ organizationId: string,
77
+ directoryId: string,
78
+ options?: {
79
+ pageSize?: number,
80
+ pageToken?: string,
81
+ includeDetail?: boolean,
82
+ directoryGroupId?: string,
83
+ updatedAfter?: string,
84
+ }
85
+ ): Promise<ListDirectoryUsersResponse> {
86
+ let requestOptions = {};
87
+ if (options) {
88
+ requestOptions = {
89
+ ...options,
90
+ ...(options.updatedAfter && {
91
+ updatedAfter: Timestamp.fromDate(new Date(options.updatedAfter))
92
+ })
93
+ }
94
+ }
95
+
96
+ return this.coreClient.connectExec(
97
+ this.client.listDirectoryUsers,
98
+ {
99
+ organizationId,
100
+ directoryId,
101
+ ...requestOptions,
102
+ }
103
+ )
104
+ }
105
+
106
+ /**
107
+ * List groups in a directory for an organization
108
+ * @param {string} organizationId The organization id
109
+ * @param {string} directoryId The directory id
110
+ * @param {object} options The options to list directory groups
111
+ * @param {number} options.pageSize The page size
112
+ * @param {string} options.pageToken The page token
113
+ * @param {boolean} options.includeDetail Include detail
114
+ * @param {string} options.updatedAfter The updated after
115
+ * @returns {Promise<ListDirectoryGroupsResponse>} Returns the list of directory groups
116
+ */
117
+ async listDirectoryGroups(
118
+ organizationId: string,
119
+ directoryId: string,
120
+ options?: {
121
+ pageSize?: number,
122
+ pageToken?: string,
123
+ includeDetail?: boolean,
124
+ updatedAfter?: string,
125
+ }
126
+ ): Promise<ListDirectoryGroupsResponse> {
127
+ let requestOptions = {};
128
+ if (options) {
129
+ requestOptions = {
130
+ ...options,
131
+ ...(options.updatedAfter && {
132
+ updatedAfter: Timestamp.fromDate(new Date(options.updatedAfter))
133
+ })
134
+ }
135
+ }
136
+
137
+ return this.coreClient.connectExec(
138
+ this.client.listDirectoryGroups,
139
+ {
140
+ organizationId,
141
+ directoryId,
142
+ ...requestOptions,
143
+ }
144
+ )
145
+ }
146
+
147
+ /**
148
+ * Enable a directory for an organization
149
+ * @param {string} organizationId The organization id
150
+ * @param {string} directoryId The directory id
151
+ * @returns {Promise<ToggleDirectoryResponse>} Returns the directory enable response
152
+ */
153
+ async enableDirectory(organizationId: string, directoryId: string): Promise<ToggleDirectoryResponse> {
154
+ return this.coreClient.connectExec(
155
+ this.client.enableDirectory,
156
+ { organizationId, id: directoryId }
157
+ )
158
+ }
159
+
160
+ /**
161
+ * Disable a directory for an organization
162
+ * @param {string} organizationId The organization id
163
+ * @param {string} directoryId The directory id
164
+ * @returns {Promise<ToggleDirectoryResponse>} Returns the directory disable response
165
+ */
166
+ async disableDirectory(organizationId: string, directoryId: string): Promise<ToggleDirectoryResponse> {
167
+ return this.coreClient.connectExec(
168
+ this.client.disableDirectory,
169
+ { organizationId, id: directoryId }
170
+ )
171
+ }
172
+ }
173
+
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import ScalekitClient from "./scalekit";
2
2
 
3
3
  export { ScalekitClient };
4
+ export { ScalekitClient as Scalekit };
4
5
  export default ScalekitClient;
5
6
 
6
7
  export * from "./types/scalekit";
@@ -4,7 +4,7 @@ import GrpcConnect from './connect';
4
4
  import CoreClient from './core';
5
5
  import { OrganizationService } from './pkg/grpc/scalekit/v1/organizations/organizations_connect';
6
6
  import { CreateOrganizationResponse, GetOrganizationResponse, Link, ListOrganizationsResponse, UpdateOrganization, UpdateOrganizationResponse } from './pkg/grpc/scalekit/v1/organizations/organizations_pb';
7
-
7
+ import { OrganizationSettings } from './types/organization';
8
8
  export default class OrganizationClient {
9
9
  private client: PromiseClient<typeof OrganizationService>;
10
10
  constructor(
@@ -172,5 +172,28 @@ export default class OrganizationClient {
172
172
  },
173
173
  )
174
174
  }
175
+
176
+ /**
177
+ * Update organization settings for an organization
178
+ * @param organizationId The organization id
179
+ * @param settings The organization settings
180
+ * @returns {Promise<GetOrganizationResponse>} The updated organization
181
+ */
182
+ async updateOrganizationSettings(organizationId: string, settings: OrganizationSettings): Promise<GetOrganizationResponse> {
183
+ const request = {
184
+ id: organizationId,
185
+ settings: {
186
+ features: settings.features.map(feature => ({
187
+ name: feature.name,
188
+ enabled: feature.enabled
189
+ }))
190
+ }
191
+ }
192
+
193
+ return this.coreClient.connectExec(
194
+ this.client.updateOrganizationSettings,
195
+ request,
196
+ )
197
+ }
175
198
  }
176
199
 
@@ -0,0 +1,125 @@
1
+ // @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts"
2
+ // @generated from file scalekit/v1/directories/directories.proto (package scalekit.v1.directories, syntax proto3)
3
+ /* eslint-disable */
4
+ // @ts-nocheck
5
+
6
+ import { AssignRolesRequest, AssignRolesResponse, CreateDirectoryRequest, CreateDirectoryResponse, CreateDirectorySecretRequest, CreateDirectorySecretResponse, GetDirectoryRequest, GetDirectoryResponse, ListDirectoriesRequest, ListDirectoriesResponse, ListDirectoryGroupsRequest, ListDirectoryGroupsResponse, ListDirectoryUsersRequest, ListDirectoryUsersResponse, RegenerateDirectorySecretRequest, RegenerateDirectorySecretResponse, ToggleDirectoryRequest, ToggleDirectoryResponse, UpdateAttributesRequest, UpdateAttributesResponse, UpdateDirectoryRequest, UpdateDirectoryResponse } from "./directories_pb.js";
7
+ import { MethodKind } from "@bufbuild/protobuf";
8
+
9
+ /**
10
+ * @generated from service scalekit.v1.directories.DirectoryService
11
+ */
12
+ export const DirectoryService = {
13
+ typeName: "scalekit.v1.directories.DirectoryService",
14
+ methods: {
15
+ /**
16
+ * @generated from rpc scalekit.v1.directories.DirectoryService.CreateDirectory
17
+ */
18
+ createDirectory: {
19
+ name: "CreateDirectory",
20
+ I: CreateDirectoryRequest,
21
+ O: CreateDirectoryResponse,
22
+ kind: MethodKind.Unary,
23
+ },
24
+ /**
25
+ * @generated from rpc scalekit.v1.directories.DirectoryService.UpdateDirectory
26
+ */
27
+ updateDirectory: {
28
+ name: "UpdateDirectory",
29
+ I: UpdateDirectoryRequest,
30
+ O: UpdateDirectoryResponse,
31
+ kind: MethodKind.Unary,
32
+ },
33
+ /**
34
+ * @generated from rpc scalekit.v1.directories.DirectoryService.AssignRoles
35
+ */
36
+ assignRoles: {
37
+ name: "AssignRoles",
38
+ I: AssignRolesRequest,
39
+ O: AssignRolesResponse,
40
+ kind: MethodKind.Unary,
41
+ },
42
+ /**
43
+ * @generated from rpc scalekit.v1.directories.DirectoryService.UpdateAttributes
44
+ */
45
+ updateAttributes: {
46
+ name: "UpdateAttributes",
47
+ I: UpdateAttributesRequest,
48
+ O: UpdateAttributesResponse,
49
+ kind: MethodKind.Unary,
50
+ },
51
+ /**
52
+ * @generated from rpc scalekit.v1.directories.DirectoryService.GetDirectory
53
+ */
54
+ getDirectory: {
55
+ name: "GetDirectory",
56
+ I: GetDirectoryRequest,
57
+ O: GetDirectoryResponse,
58
+ kind: MethodKind.Unary,
59
+ },
60
+ /**
61
+ * @generated from rpc scalekit.v1.directories.DirectoryService.ListDirectories
62
+ */
63
+ listDirectories: {
64
+ name: "ListDirectories",
65
+ I: ListDirectoriesRequest,
66
+ O: ListDirectoriesResponse,
67
+ kind: MethodKind.Unary,
68
+ },
69
+ /**
70
+ * @generated from rpc scalekit.v1.directories.DirectoryService.EnableDirectory
71
+ */
72
+ enableDirectory: {
73
+ name: "EnableDirectory",
74
+ I: ToggleDirectoryRequest,
75
+ O: ToggleDirectoryResponse,
76
+ kind: MethodKind.Unary,
77
+ },
78
+ /**
79
+ * @generated from rpc scalekit.v1.directories.DirectoryService.DisableDirectory
80
+ */
81
+ disableDirectory: {
82
+ name: "DisableDirectory",
83
+ I: ToggleDirectoryRequest,
84
+ O: ToggleDirectoryResponse,
85
+ kind: MethodKind.Unary,
86
+ },
87
+ /**
88
+ * @generated from rpc scalekit.v1.directories.DirectoryService.ListDirectoryUsers
89
+ */
90
+ listDirectoryUsers: {
91
+ name: "ListDirectoryUsers",
92
+ I: ListDirectoryUsersRequest,
93
+ O: ListDirectoryUsersResponse,
94
+ kind: MethodKind.Unary,
95
+ },
96
+ /**
97
+ * @generated from rpc scalekit.v1.directories.DirectoryService.ListDirectoryGroups
98
+ */
99
+ listDirectoryGroups: {
100
+ name: "ListDirectoryGroups",
101
+ I: ListDirectoryGroupsRequest,
102
+ O: ListDirectoryGroupsResponse,
103
+ kind: MethodKind.Unary,
104
+ },
105
+ /**
106
+ * @generated from rpc scalekit.v1.directories.DirectoryService.CreateDirectorySecret
107
+ */
108
+ createDirectorySecret: {
109
+ name: "CreateDirectorySecret",
110
+ I: CreateDirectorySecretRequest,
111
+ O: CreateDirectorySecretResponse,
112
+ kind: MethodKind.Unary,
113
+ },
114
+ /**
115
+ * @generated from rpc scalekit.v1.directories.DirectoryService.RegenerateDirectorySecret
116
+ */
117
+ regenerateDirectorySecret: {
118
+ name: "RegenerateDirectorySecret",
119
+ I: RegenerateDirectorySecretRequest,
120
+ O: RegenerateDirectorySecretResponse,
121
+ kind: MethodKind.Unary,
122
+ },
123
+ }
124
+ } as const;
125
+