@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.
- package/README.md +5 -5
- package/{reference.md → REFERENCE.md} +530 -748
- package/lib/auth.d.ts +9 -6
- package/lib/auth.js +4 -20
- package/lib/auth.js.map +1 -1
- package/lib/connect.d.ts +3 -3
- package/lib/connect.js +1 -2
- package/lib/connect.js.map +1 -1
- package/lib/connection.d.ts +2 -2
- package/lib/connection.js +4 -4
- package/lib/connection.js.map +1 -1
- package/lib/core.js +2 -2
- package/lib/core.js.map +1 -1
- package/lib/directory.d.ts +2 -2
- package/lib/directory.js +7 -7
- package/lib/directory.js.map +1 -1
- package/lib/domain.d.ts +6 -5
- package/lib/domain.js +4 -5
- package/lib/domain.js.map +1 -1
- package/lib/errors/base-exception.d.ts +1 -1
- package/lib/errors/base-exception.js +1 -1
- package/lib/errors/base-exception.js.map +1 -1
- package/lib/organization.d.ts +10 -9
- package/lib/organization.js +11 -9
- package/lib/organization.js.map +1 -1
- package/lib/passwordless.d.ts +2 -2
- package/lib/passwordless.js +8 -7
- package/lib/passwordless.js.map +1 -1
- package/lib/permission.d.ts +6 -5
- package/lib/permission.js +10 -11
- package/lib/permission.js.map +1 -1
- package/lib/pkg/grpc/buf/validate/validate_pb.d.ts +7 -0
- package/lib/pkg/grpc/buf/validate/validate_pb.js +25 -0
- package/lib/pkg/grpc/buf/validate/validate_pb.js.map +1 -0
- package/lib/pkg/grpc/google/api/annotations_pb.d.ts +7 -0
- package/lib/pkg/grpc/google/api/annotations_pb.js +25 -0
- package/lib/pkg/grpc/google/api/annotations_pb.js.map +1 -0
- package/lib/pkg/grpc/google/api/field_behavior_pb.d.ts +7 -0
- package/lib/pkg/grpc/google/api/field_behavior_pb.js +25 -0
- package/lib/pkg/grpc/google/api/field_behavior_pb.js.map +1 -0
- package/lib/pkg/grpc/google/api/visibility_pb.d.ts +7 -0
- package/lib/pkg/grpc/google/api/visibility_pb.js +25 -0
- package/lib/pkg/grpc/google/api/visibility_pb.js.map +1 -0
- package/lib/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.d.ts +7 -0
- package/lib/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.js +25 -0
- package/lib/pkg/grpc/protoc-gen-openapiv2/options/annotations_pb.js.map +1 -0
- package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.d.ts +48 -42
- package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.js +27 -263
- package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.d.ts +371 -325
- package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js +132 -835
- package/lib/pkg/grpc/scalekit/v1/auth/auth_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/auth/passwordless_pb.d.ts +113 -87
- package/lib/pkg/grpc/scalekit/v1/auth/passwordless_pb.js +45 -201
- package/lib/pkg/grpc/scalekit/v1/auth/passwordless_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.d.ts +262 -265
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js +92 -938
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.d.ts +162 -157
- package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js +42 -313
- package/lib/pkg/grpc/scalekit/v1/commons/commons_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.d.ts +1488 -1459
- package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js +353 -2362
- package/lib/pkg/grpc/scalekit/v1/connections/connections_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.d.ts +520 -483
- package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.js +224 -1555
- package/lib/pkg/grpc/scalekit/v1/directories/directories_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/domains/domains_pb.d.ts +219 -191
- package/lib/pkg/grpc/scalekit/v1/domains/domains_pb.js +96 -553
- package/lib/pkg/grpc/scalekit/v1/domains/domains_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.d.ts +76 -102
- package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.js +37 -393
- package/lib/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/options/options_pb.d.ts +36 -26
- package/lib/pkg/grpc/scalekit/v1/options/options_pb.js +20 -69
- package/lib/pkg/grpc/scalekit/v1/options/options_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.d.ts +447 -400
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js +163 -1238
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/roles/roles_pb.d.ts +622 -556
- package/lib/pkg/grpc/scalekit/v1/roles/roles_pb.js +201 -1718
- package/lib/pkg/grpc/scalekit/v1/roles/roles_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/sessions/sessions_pb.d.ts +135 -132
- package/lib/pkg/grpc/scalekit/v1/sessions/sessions_pb.js +55 -518
- package/lib/pkg/grpc/scalekit/v1/sessions/sessions_pb.js.map +1 -1
- package/lib/pkg/grpc/scalekit/v1/users/users_pb.d.ts +445 -413
- package/lib/pkg/grpc/scalekit/v1/users/users_pb.js +142 -1490
- package/lib/pkg/grpc/scalekit/v1/users/users_pb.js.map +1 -1
- package/lib/role.d.ts +8 -7
- package/lib/role.js +14 -14
- package/lib/role.js.map +1 -1
- package/lib/scalekit.d.ts +0 -4
- package/lib/scalekit.js +0 -4
- package/lib/scalekit.js.map +1 -1
- package/lib/session.js +15 -24
- package/lib/session.js.map +1 -1
- package/lib/user.d.ts +6 -5
- package/lib/user.js +17 -20
- package/lib/user.js.map +1 -1
- package/lib/webauthn.js +6 -5
- package/lib/webauthn.js.map +1 -1
- package/package.json +12 -10
- package/.github/dependabot.yml +0 -10
- package/.nvmrc +0 -1
- package/buf.gen.yaml +0 -24
- package/jest.config.js +0 -15
- package/lib/connected-accounts.d.ts +0 -119
- package/lib/connected-accounts.js +0 -241
- package/lib/connected-accounts.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.d.ts +0 -19
- package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.js +0 -27
- package/lib/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.d.ts +0 -118
- package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js +0 -126
- package/lib/pkg/grpc/scalekit/v1/auth/auth_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/auth/passwordless_connect.d.ts +0 -37
- package/lib/pkg/grpc/scalekit/v1/auth/passwordless_connect.js +0 -45
- package/lib/pkg/grpc/scalekit/v1/auth/passwordless_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.d.ts +0 -82
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js +0 -90
- package/lib/pkg/grpc/scalekit/v1/auth/webauthn_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.d.ts +0 -87
- package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.js +0 -95
- package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.d.ts +0 -718
- package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.js +0 -893
- package/lib/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.d.ts +0 -172
- package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js +0 -180
- package/lib/pkg/grpc/scalekit/v1/connections/connections_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.d.ts +0 -154
- package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.js +0 -162
- package/lib/pkg/grpc/scalekit/v1/directories/directories_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/domains/domains_connect.d.ts +0 -73
- package/lib/pkg/grpc/scalekit/v1/domains/domains_connect.js +0 -81
- package/lib/pkg/grpc/scalekit/v1/domains/domains_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.d.ts +0 -171
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.js +0 -179
- package/lib/pkg/grpc/scalekit/v1/organizations/organizations_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/roles/roles_connect.d.ts +0 -250
- package/lib/pkg/grpc/scalekit/v1/roles/roles_connect.js +0 -258
- package/lib/pkg/grpc/scalekit/v1/roles/roles_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/sessions/sessions_connect.d.ts +0 -46
- package/lib/pkg/grpc/scalekit/v1/sessions/sessions_connect.js +0 -54
- package/lib/pkg/grpc/scalekit/v1/sessions/sessions_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/tools/tools_connect.d.ts +0 -75
- package/lib/pkg/grpc/scalekit/v1/tools/tools_connect.js +0 -83
- package/lib/pkg/grpc/scalekit/v1/tools/tools_connect.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.d.ts +0 -431
- package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.js +0 -627
- package/lib/pkg/grpc/scalekit/v1/tools/tools_pb.js.map +0 -1
- package/lib/pkg/grpc/scalekit/v1/users/users_connect.d.ts +0 -173
- package/lib/pkg/grpc/scalekit/v1/users/users_connect.js +0 -181
- package/lib/pkg/grpc/scalekit/v1/users/users_connect.js.map +0 -1
- package/lib/tools.d.ts +0 -75
- package/lib/tools.js +0 -127
- package/lib/tools.js.map +0 -1
- package/src/auth.ts +0 -99
- package/src/connect.ts +0 -33
- package/src/connected-accounts.ts +0 -358
- package/src/connection.ts +0 -267
- package/src/constants/user.ts +0 -22
- package/src/core.ts +0 -139
- package/src/directory.ts +0 -431
- package/src/domain.ts +0 -272
- package/src/errors/base-exception.ts +0 -262
- package/src/errors/index.ts +0 -3
- package/src/errors/specific-exceptions.ts +0 -88
- package/src/index.ts +0 -10
- package/src/organization.ts +0 -568
- package/src/passwordless.ts +0 -138
- package/src/permission.ts +0 -310
- package/src/pkg/grpc/scalekit/v1/auditlogs/auditlogs_connect.ts +0 -26
- package/src/pkg/grpc/scalekit/v1/auditlogs/auditlogs_pb.ts +0 -342
- package/src/pkg/grpc/scalekit/v1/auth/auth_connect.ts +0 -125
- package/src/pkg/grpc/scalekit/v1/auth/auth_pb.ts +0 -1213
- package/src/pkg/grpc/scalekit/v1/auth/passwordless_connect.ts +0 -44
- package/src/pkg/grpc/scalekit/v1/auth/passwordless_pb.ts +0 -336
- package/src/pkg/grpc/scalekit/v1/auth/webauthn_connect.ts +0 -89
- package/src/pkg/grpc/scalekit/v1/auth/webauthn_pb.ts +0 -1263
- package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +0 -573
- package/src/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_connect.ts +0 -94
- package/src/pkg/grpc/scalekit/v1/connected_accounts/connected_accounts_pb.ts +0 -1294
- package/src/pkg/grpc/scalekit/v1/connections/connections_connect.ts +0 -179
- package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +0 -3846
- package/src/pkg/grpc/scalekit/v1/directories/directories_connect.ts +0 -161
- package/src/pkg/grpc/scalekit/v1/directories/directories_pb.ts +0 -2119
- package/src/pkg/grpc/scalekit/v1/domains/domains_connect.ts +0 -80
- package/src/pkg/grpc/scalekit/v1/domains/domains_pb.ts +0 -855
- package/src/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.ts +0 -524
- package/src/pkg/grpc/scalekit/v1/options/options_pb.ts +0 -230
- package/src/pkg/grpc/scalekit/v1/organizations/organizations_connect.ts +0 -178
- package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +0 -1766
- package/src/pkg/grpc/scalekit/v1/roles/roles_connect.ts +0 -257
- package/src/pkg/grpc/scalekit/v1/roles/roles_pb.ts +0 -2395
- package/src/pkg/grpc/scalekit/v1/sessions/sessions_connect.ts +0 -53
- package/src/pkg/grpc/scalekit/v1/sessions/sessions_pb.ts +0 -749
- package/src/pkg/grpc/scalekit/v1/tools/tools_connect.ts +0 -82
- package/src/pkg/grpc/scalekit/v1/tools/tools_pb.ts +0 -847
- package/src/pkg/grpc/scalekit/v1/users/users_connect.ts +0 -180
- package/src/pkg/grpc/scalekit/v1/users/users_pb.ts +0 -2151
- package/src/role.ts +0 -461
- package/src/scalekit.ts +0 -809
- package/src/session.ts +0 -337
- package/src/tools.ts +0 -166
- package/src/types/auth.ts +0 -73
- package/src/types/organization.ts +0 -12
- package/src/types/scalekit.ts +0 -50
- package/src/types/user.ts +0 -21
- package/src/user.ts +0 -825
- package/src/webauthn.ts +0 -98
- package/tests/README.md +0 -25
- package/tests/connected-accounts.test.ts +0 -472
- package/tests/connection.test.ts +0 -42
- package/tests/directory.test.ts +0 -46
- package/tests/domain.test.ts +0 -293
- package/tests/organization.test.ts +0 -81
- package/tests/passwordless.test.ts +0 -108
- package/tests/permission.test.ts +0 -399
- package/tests/role.test.ts +0 -323
- package/tests/scalekit.test.ts +0 -104
- package/tests/setup.ts +0 -34
- package/tests/tools.test.ts +0 -239
- package/tests/users.test.ts +0 -168
- package/tests/utils/test-data.ts +0 -481
- package/tsconfig.json +0 -19
package/src/core.ts
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { Code, ConnectError } from "@connectrpc/connect";
|
|
2
|
-
import axios, { Axios, AxiosError, AxiosResponse, HttpStatusCode } from "axios";
|
|
3
|
-
import { JWK } from "jose";
|
|
4
|
-
import os from "os";
|
|
5
|
-
import QueryString from "qs";
|
|
6
|
-
import { GrantType } from "./types/scalekit";
|
|
7
|
-
import { TokenResponse } from "./types/auth";
|
|
8
|
-
import {
|
|
9
|
-
ScalekitException,
|
|
10
|
-
ScalekitServerException,
|
|
11
|
-
} from "./errors/base-exception";
|
|
12
|
-
|
|
13
|
-
export const headers = {
|
|
14
|
-
"user-agent": "user-agent",
|
|
15
|
-
"x-sdk-version": "x-sdk-version",
|
|
16
|
-
"x-api-version": "x-api-version",
|
|
17
|
-
authorization: "authorization",
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const tokenEndpoint = "oauth/token";
|
|
21
|
-
const jwksEndpoint = "keys";
|
|
22
|
-
export default class CoreClient {
|
|
23
|
-
public keys: JWK[] = [];
|
|
24
|
-
public accessToken: string | null = null;
|
|
25
|
-
public axios: Axios;
|
|
26
|
-
public sdkVersion = `Scalekit-Node/2.2.0-beta.1`;
|
|
27
|
-
public apiVersion = "20260123";
|
|
28
|
-
public userAgent = `${this.sdkVersion} Node/${process.version} (${
|
|
29
|
-
process.platform
|
|
30
|
-
}; ${os.arch()})`;
|
|
31
|
-
constructor(
|
|
32
|
-
readonly envUrl: string,
|
|
33
|
-
readonly clientId: string,
|
|
34
|
-
readonly clientSecret: string
|
|
35
|
-
) {
|
|
36
|
-
this.axios = axios.create({ baseURL: envUrl });
|
|
37
|
-
this.axios.interceptors.request.use((config) => {
|
|
38
|
-
config.headers[headers["user-agent"]] = this.userAgent;
|
|
39
|
-
config.headers[headers["x-sdk-version"]] = this.sdkVersion;
|
|
40
|
-
config.headers[headers["x-api-version"]] = this.apiVersion;
|
|
41
|
-
if (this.accessToken) {
|
|
42
|
-
config.headers[headers.authorization] = `Bearer ${this.accessToken}`;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return config;
|
|
46
|
-
});
|
|
47
|
-
// removing token creation at the time of constructor and instead letting the retry functionality handle generating a token whenever required.
|
|
48
|
-
//this.authenticateClient();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
private async authenticateClient() {
|
|
52
|
-
const res = await this.authenticate(
|
|
53
|
-
QueryString.stringify({
|
|
54
|
-
grant_type: GrantType.ClientCredentials,
|
|
55
|
-
client_id: this.clientId,
|
|
56
|
-
client_secret: this.clientSecret,
|
|
57
|
-
})
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
this.accessToken = res.data.access_token;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Authenticate with the code
|
|
64
|
-
* @param {string} data Data to authenticate
|
|
65
|
-
* @returns {Promise<AxiosResponse<TokenResponse>>} Returns access token and id token
|
|
66
|
-
*/
|
|
67
|
-
async authenticate(data: string): Promise<AxiosResponse<TokenResponse, any>> {
|
|
68
|
-
return this.axios.post<TokenResponse>(tokenEndpoint, data, {
|
|
69
|
-
headers: {
|
|
70
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Get the JWKS from the server and store it in the client instance
|
|
77
|
-
* @returns {Promise<void>} Returns nothing
|
|
78
|
-
*/
|
|
79
|
-
async getJwks(): Promise<void> {
|
|
80
|
-
if (this.keys.length) {
|
|
81
|
-
return Promise.resolve();
|
|
82
|
-
}
|
|
83
|
-
const {
|
|
84
|
-
data: { keys },
|
|
85
|
-
} = await this.axios.get<{ keys: JWK[] }>(jwksEndpoint);
|
|
86
|
-
this.keys = keys;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Execute a function with error handling and retry logic
|
|
91
|
-
* @param fn Function to execute
|
|
92
|
-
* @param data Data to pass to the function
|
|
93
|
-
* @param retryLeft Number of retries left
|
|
94
|
-
* @returns {Promise<TResponse>} Returns the response
|
|
95
|
-
*/
|
|
96
|
-
async connectExec<TRequest, TResponse>(
|
|
97
|
-
fn: (request: TRequest) => Promise<TResponse>,
|
|
98
|
-
data: TRequest,
|
|
99
|
-
retryLeft: number = 1
|
|
100
|
-
): Promise<TResponse> {
|
|
101
|
-
try {
|
|
102
|
-
const res = await fn(data);
|
|
103
|
-
return res;
|
|
104
|
-
} catch (error) {
|
|
105
|
-
// Handle gRPC Connect errors
|
|
106
|
-
if (error instanceof ConnectError) {
|
|
107
|
-
if (retryLeft > 0) {
|
|
108
|
-
const serverException = new ScalekitServerException(error);
|
|
109
|
-
if (serverException.httpStatus === 401) {
|
|
110
|
-
await this.authenticateClient();
|
|
111
|
-
return this.connectExec(fn, data, retryLeft - 1);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
throw ScalekitServerException.promote(error);
|
|
115
|
-
}
|
|
116
|
-
// Handle HTTP/Axios errors
|
|
117
|
-
if (error instanceof AxiosError) {
|
|
118
|
-
if (error.response) {
|
|
119
|
-
if (retryLeft > 0) {
|
|
120
|
-
const serverException = new ScalekitServerException(error.response);
|
|
121
|
-
if (serverException.httpStatus === 401) {
|
|
122
|
-
await this.authenticateClient();
|
|
123
|
-
return this.connectExec(fn, data, retryLeft - 1);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
throw ScalekitServerException.promote(error.response);
|
|
127
|
-
} else {
|
|
128
|
-
throw new ScalekitException(error);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
// Handle existing ScalekitException instances
|
|
132
|
-
if (error instanceof ScalekitException) {
|
|
133
|
-
throw error;
|
|
134
|
-
}
|
|
135
|
-
// Handle generic errors
|
|
136
|
-
throw new ScalekitException(error);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
package/src/directory.ts
DELETED
|
@@ -1,431 +0,0 @@
|
|
|
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
|
-
/**
|
|
16
|
-
* Client for managing SCIM directory synchronization.
|
|
17
|
-
*
|
|
18
|
-
* Directories represent SCIM connections that automatically sync users and groups from an
|
|
19
|
-
* organization's identity provider (Okta, Azure AD, Google Workspace, etc.) to your application.
|
|
20
|
-
* Use this client to retrieve synchronized user/group data, manage directory settings, and
|
|
21
|
-
* monitor sync status.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* const scalekitClient = new ScalekitClient(envUrl, clientId, clientSecret);
|
|
25
|
-
* const directoryClient = scalekitClient.directory;
|
|
26
|
-
*
|
|
27
|
-
* @see {@link https://docs.scalekit.com/apis/#tag/directory | Directory API Documentation}
|
|
28
|
-
* @see {@link https://docs.scalekit.com/directory/scim/quickstart/ | SCIM Directory Sync Guide}
|
|
29
|
-
*/
|
|
30
|
-
export default class DirectoryClient {
|
|
31
|
-
private client: PromiseClient<typeof DirectoryService>;
|
|
32
|
-
constructor(
|
|
33
|
-
private readonly grpcConncet: GrpcConnect,
|
|
34
|
-
private readonly coreClient: CoreClient
|
|
35
|
-
) {
|
|
36
|
-
this.client = this.grpcConncet.createClient(DirectoryService);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Retrieves all SCIM directories configured for an organization.
|
|
41
|
-
*
|
|
42
|
-
* Lists all directory sync connections that have been set up for the organization. Each directory
|
|
43
|
-
* represents a SCIM integration with an identity provider (Okta, Azure AD, Google Workspace, etc.)
|
|
44
|
-
* that automatically syncs users and groups. Use this to view directory configurations, check sync
|
|
45
|
-
* status, and manage directory integrations.
|
|
46
|
-
*
|
|
47
|
-
* @param {string} organizationId - The organization ID to list directories for (format: "org_...")
|
|
48
|
-
*
|
|
49
|
-
* @returns {Promise<ListDirectoriesResponse>} Response containing:
|
|
50
|
-
* - directories: Array of directory objects with:
|
|
51
|
-
* - id: Unique directory identifier
|
|
52
|
-
* - organizationId: Parent organization ID
|
|
53
|
-
* - provider: Identity provider name (e.g., "okta", "azure_ad", "google")
|
|
54
|
-
* - enabled: Whether directory sync is active
|
|
55
|
-
* - status: Current synchronization status
|
|
56
|
-
* - lastSyncTime: When the last sync occurred
|
|
57
|
-
* - userCount: Number of synced users
|
|
58
|
-
* - groupCount: Number of synced groups
|
|
59
|
-
*
|
|
60
|
-
* @throws {Error} If the organization is not found
|
|
61
|
-
*
|
|
62
|
-
* @example
|
|
63
|
-
* // List all directories for an organization
|
|
64
|
-
* const response = await scalekitClient.directory.listDirectories('org_123456');
|
|
65
|
-
*
|
|
66
|
-
* console.log(`Found ${response.directories.length} directories`);
|
|
67
|
-
* response.directories.forEach(dir => {
|
|
68
|
-
* console.log(`- ${dir.provider}: ${dir.enabled ? 'Active' : 'Inactive'}`);
|
|
69
|
-
* console.log(` Users: ${dir.userCount}, Groups: ${dir.groupCount}`);
|
|
70
|
-
* });
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* // Check if organization has any active directories
|
|
74
|
-
* const response = await scalekitClient.directory.listDirectories('org_123456');
|
|
75
|
-
* const hasActiveDirectory = response.directories.some(dir => dir.enabled);
|
|
76
|
-
*
|
|
77
|
-
* if (hasActiveDirectory) {
|
|
78
|
-
* console.log('Directory sync is enabled for this organization');
|
|
79
|
-
* } else {
|
|
80
|
-
* console.log('No active directory sync');
|
|
81
|
-
* }
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* @see {@link https://docs.scalekit.com/apis/#tag/directory | List Directories API}
|
|
85
|
-
* @see {@link getDirectory} - Get details of a specific directory
|
|
86
|
-
* @see {@link enableDirectory} - Enable directory sync
|
|
87
|
-
* @see {@link disableDirectory} - Disable directory sync
|
|
88
|
-
*/
|
|
89
|
-
async listDirectories(
|
|
90
|
-
organizationId: string
|
|
91
|
-
): Promise<ListDirectoriesResponse> {
|
|
92
|
-
return this.coreClient.connectExec(this.client.listDirectories, {
|
|
93
|
-
organizationId,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Retrieves comprehensive details about a specific SCIM directory.
|
|
99
|
-
*
|
|
100
|
-
* Fetches complete configuration and status information for a directory, including provider settings,
|
|
101
|
-
* synchronization status, user/group counts, and metadata. Use this to view directory configuration,
|
|
102
|
-
* monitor sync health, verify setup, or display directory details in admin interfaces.
|
|
103
|
-
*
|
|
104
|
-
* @param {string} organizationId - The organization ID that owns the directory (format: "org_...")
|
|
105
|
-
* @param {string} directoryId - The directory identifier to retrieve (format: "dir_...")
|
|
106
|
-
*
|
|
107
|
-
* @returns {Promise<GetDirectoryResponse>} Response containing:
|
|
108
|
-
* - directory: Complete directory object with:
|
|
109
|
-
* - id: Unique directory identifier
|
|
110
|
-
* - organizationId: Parent organization ID
|
|
111
|
-
* - provider: Identity provider name (e.g., "okta", "azure_ad", "google")
|
|
112
|
-
* - enabled: Whether directory sync is active
|
|
113
|
-
* - status: Current synchronization status
|
|
114
|
-
* - scimBaseUrl: SCIM endpoint URL
|
|
115
|
-
* - scimToken: Authentication token (masked)
|
|
116
|
-
* - lastSyncTime: Timestamp of last successful sync
|
|
117
|
-
* - nextSyncTime: Scheduled time for next sync
|
|
118
|
-
* - userCount: Number of synced users
|
|
119
|
-
* - groupCount: Number of synced groups
|
|
120
|
-
* - createTime: When directory was created
|
|
121
|
-
* - updateTime: When directory was last updated
|
|
122
|
-
*
|
|
123
|
-
* @throws {Error} If the organization or directory is not found
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* // Get directory details
|
|
127
|
-
* const response = await scalekitClient.directory.getDirectory(
|
|
128
|
-
* 'org_123456',
|
|
129
|
-
* 'dir_abc123'
|
|
130
|
-
* );
|
|
131
|
-
*
|
|
132
|
-
* const dir = response.directory;
|
|
133
|
-
* console.log('Provider:', dir.provider);
|
|
134
|
-
* console.log('Status:', dir.enabled ? 'Active' : 'Inactive');
|
|
135
|
-
* console.log('Last sync:', dir.lastSyncTime);
|
|
136
|
-
* console.log('Users:', dir.userCount);
|
|
137
|
-
* console.log('Groups:', dir.groupCount);
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* @see {@link https://docs.scalekit.com/apis/#tag/directory | Get Directory API}
|
|
141
|
-
* @see {@link getPrimaryDirectoryByOrganizationId} - List the first directory in an Organization.
|
|
142
|
-
* - Useful utility API if you don't know the directory ID but only have an organizationID.
|
|
143
|
-
* @see {@link listDirectoryUsers} - List users in this directory
|
|
144
|
-
* @see {@link listDirectoryGroups} - List groups in this directory
|
|
145
|
-
*/
|
|
146
|
-
async getDirectory(
|
|
147
|
-
organizationId: string,
|
|
148
|
-
directoryId: string
|
|
149
|
-
): Promise<GetDirectoryResponse> {
|
|
150
|
-
return this.coreClient.connectExec(this.client.getDirectory, {
|
|
151
|
-
organizationId,
|
|
152
|
-
id: directoryId,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Retrieves the primary (first) directory for an organization.
|
|
158
|
-
*
|
|
159
|
-
* This is a convenience method that fetches the first directory from the organization's list
|
|
160
|
-
* of directories. Most organizations have a single directory, making this useful for quickly
|
|
161
|
-
* accessing directory data without needing to know the specific directory ID. If the organization
|
|
162
|
-
* has multiple directories, this returns the first one.
|
|
163
|
-
*
|
|
164
|
-
* @param {string} organizationId - The organization ID to get the primary directory for (format: "org_...")
|
|
165
|
-
*
|
|
166
|
-
* @returns {Promise<Directory>} The first directory object for the organization
|
|
167
|
-
*
|
|
168
|
-
* @throws {Error} When the organization has no directories configured
|
|
169
|
-
*
|
|
170
|
-
* @example
|
|
171
|
-
* // Get primary directory for an organization
|
|
172
|
-
* try {
|
|
173
|
-
* const directory = await scalekitClient.directory.getPrimaryDirectoryByOrganizationId('org_123456');
|
|
174
|
-
*
|
|
175
|
-
* console.log('Primary Directory:', directory.provider);
|
|
176
|
-
* console.log('Users:', directory.userCount);
|
|
177
|
-
* console.log('Groups:', directory.groupCount);
|
|
178
|
-
* } catch (error) {
|
|
179
|
-
* console.log('No directory configured for this organization');
|
|
180
|
-
* }
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @see {@link listDirectories} - List all directories for an organization
|
|
184
|
-
* @see {@link getDirectory} - Get a specific directory by ID
|
|
185
|
-
* @see {@link listDirectoryUsers} - List users in the directory
|
|
186
|
-
*/
|
|
187
|
-
async getPrimaryDirectoryByOrganizationId(
|
|
188
|
-
organizationId: string
|
|
189
|
-
): Promise<Directory> {
|
|
190
|
-
const directories = await this.listDirectories(organizationId);
|
|
191
|
-
if (!directories || directories.directories.length === 0) {
|
|
192
|
-
return Promise.reject("directory does not exist for organization");
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return directories.directories[0];
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Lists users synchronized from an identity provider via SCIM directory sync.
|
|
200
|
-
*
|
|
201
|
-
* Retrieves all users that have been synced from the organization's IdP to your application.
|
|
202
|
-
* This includes user profile information, group memberships, and sync status. Use this to
|
|
203
|
-
* display organization users, implement user search, or track provisioning/deprovisioning.
|
|
204
|
-
*
|
|
205
|
-
* @param {string} organizationId - The organization ID
|
|
206
|
-
* @param {string} directoryId - The directory ID
|
|
207
|
-
* @param {object} [options] - Optional filtering and pagination parameters
|
|
208
|
-
* @param {number} [options.pageSize] - Number of users per page (max: 100)
|
|
209
|
-
* @param {string} [options.pageToken] - Token for next page from previous response
|
|
210
|
-
* @param {boolean} [options.includeDetail] - Include full user profile details
|
|
211
|
-
* @param {string} [options.directoryGroupId] - Filter users by group membership
|
|
212
|
-
* @param {string} [options.updatedAfter] - ISO 8601 timestamp to fetch only users updated after this time
|
|
213
|
-
*
|
|
214
|
-
* @returns {Promise<ListDirectoryUsersResponse>} Response containing:
|
|
215
|
-
* - users: Array of directory user objects with profiles and attributes
|
|
216
|
-
* - nextPageToken: Token for retrieving the next page
|
|
217
|
-
* - totalSize: Total number of users in the directory
|
|
218
|
-
*
|
|
219
|
-
* @example
|
|
220
|
-
* // List all directory users with pagination
|
|
221
|
-
* const response = await scalekitClient.directory.listDirectoryUsers(
|
|
222
|
-
* 'org_123456',
|
|
223
|
-
* 'dir_abc123',
|
|
224
|
-
* { pageSize: 50 }
|
|
225
|
-
* );
|
|
226
|
-
*
|
|
227
|
-
* console.log(`Found ${response.totalSize} users`);
|
|
228
|
-
* response.users.forEach(user => {
|
|
229
|
-
* console.log(`- ${user.email} (${user.firstName} ${user.lastName})`);
|
|
230
|
-
* });
|
|
231
|
-
*
|
|
232
|
-
* @see {@link https://docs.scalekit.com/apis/#tag/directory | List Directory Users API}
|
|
233
|
-
* @see {@link listDirectoryGroups} - List directory groups
|
|
234
|
-
* @see {@link listDirectories} - List all directories for an organization
|
|
235
|
-
*/
|
|
236
|
-
async listDirectoryUsers(
|
|
237
|
-
organizationId: string,
|
|
238
|
-
directoryId: string,
|
|
239
|
-
options?: {
|
|
240
|
-
pageSize?: number;
|
|
241
|
-
pageToken?: string;
|
|
242
|
-
includeDetail?: boolean;
|
|
243
|
-
directoryGroupId?: string;
|
|
244
|
-
updatedAfter?: string;
|
|
245
|
-
}
|
|
246
|
-
): Promise<ListDirectoryUsersResponse> {
|
|
247
|
-
let requestOptions = {};
|
|
248
|
-
if (options) {
|
|
249
|
-
requestOptions = {
|
|
250
|
-
...options,
|
|
251
|
-
...(options.updatedAfter && {
|
|
252
|
-
updatedAfter: Timestamp.fromDate(new Date(options.updatedAfter)),
|
|
253
|
-
}),
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
return this.coreClient.connectExec(this.client.listDirectoryUsers, {
|
|
258
|
-
organizationId,
|
|
259
|
-
directoryId,
|
|
260
|
-
...requestOptions,
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Retrieves groups synchronized from an identity provider via SCIM directory sync.
|
|
266
|
-
*
|
|
267
|
-
* Fetches all groups that have been synced from the organization's IdP to your application.
|
|
268
|
-
* Groups typically represent teams, departments, or organizational units. Use this to display
|
|
269
|
-
* group hierarchies, implement group-based access control, manage group memberships, or track
|
|
270
|
-
* organizational structure changes.
|
|
271
|
-
*
|
|
272
|
-
* @param {string} organizationId - The organization ID (format: "org_...")
|
|
273
|
-
* @param {string} directoryId - The directory ID (format: "dir_...")
|
|
274
|
-
* @param {object} [options] - Optional filtering and pagination parameters
|
|
275
|
-
* @param {number} [options.pageSize] - Number of groups per page (max: 30, default: 10)
|
|
276
|
-
* @param {string} [options.pageToken] - Token for next page from previous response
|
|
277
|
-
* @param {boolean} [options.includeDetail] - Include full group details and member lists
|
|
278
|
-
* @param {string} [options.updatedAfter] - ISO 8601 timestamp to fetch only groups updated after this time
|
|
279
|
-
*
|
|
280
|
-
* @returns {Promise<ListDirectoryGroupsResponse>} Response containing:
|
|
281
|
-
* - groups: Array of directory group objects with:
|
|
282
|
-
* - id: Group identifier
|
|
283
|
-
* - displayName: Group name
|
|
284
|
-
* - description: Group description
|
|
285
|
-
* - members: Array of member user IDs (when includeDetail is true)
|
|
286
|
-
* - attributes: Custom group attributes
|
|
287
|
-
* - updateTime: When the group was last updated
|
|
288
|
-
* - nextPageToken: Token for retrieving the next page
|
|
289
|
-
* - totalSize: Total number of groups in the directory
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* // List all directory groups with pagination
|
|
293
|
-
* const response = await scalekitClient.directory.listDirectoryGroups(
|
|
294
|
-
* 'org_123456',
|
|
295
|
-
* 'dir_abc123',
|
|
296
|
-
* { pageSize: 30 }
|
|
297
|
-
* );
|
|
298
|
-
*
|
|
299
|
-
* console.log(`Found ${response.totalSize} groups`);
|
|
300
|
-
* response.groups.forEach(group => {
|
|
301
|
-
* console.log(`- ${group.displayName}`);
|
|
302
|
-
* if (group.description) console.log(` ${group.description}`);
|
|
303
|
-
* });
|
|
304
|
-
*
|
|
305
|
-
* @example
|
|
306
|
-
* // Get groups with full member details
|
|
307
|
-
* const response = await scalekitClient.directory.listDirectoryGroups(
|
|
308
|
-
* 'org_123456',
|
|
309
|
-
* 'dir_abc123',
|
|
310
|
-
* { includeDetail: true }
|
|
311
|
-
* );
|
|
312
|
-
*
|
|
313
|
-
* response.groups.forEach(group => {
|
|
314
|
-
* console.log(`${group.displayName}: ${group.members?.length || 0} members`);
|
|
315
|
-
* });
|
|
316
|
-
*
|
|
317
|
-
* @see {@link https://docs.scalekit.com/apis/#tag/directory | List Directory Groups API}
|
|
318
|
-
* @see {@link listDirectoryUsers} - List directory users
|
|
319
|
-
* @see {@link getDirectory} - Get directory details
|
|
320
|
-
*/
|
|
321
|
-
async listDirectoryGroups(
|
|
322
|
-
organizationId: string,
|
|
323
|
-
directoryId: string,
|
|
324
|
-
options?: {
|
|
325
|
-
pageSize?: number;
|
|
326
|
-
pageToken?: string;
|
|
327
|
-
includeDetail?: boolean;
|
|
328
|
-
updatedAfter?: string;
|
|
329
|
-
}
|
|
330
|
-
): Promise<ListDirectoryGroupsResponse> {
|
|
331
|
-
let requestOptions = {};
|
|
332
|
-
if (options) {
|
|
333
|
-
requestOptions = {
|
|
334
|
-
...options,
|
|
335
|
-
...(options.updatedAfter && {
|
|
336
|
-
updatedAfter: Timestamp.fromDate(new Date(options.updatedAfter)),
|
|
337
|
-
}),
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return this.coreClient.connectExec(this.client.listDirectoryGroups, {
|
|
342
|
-
organizationId,
|
|
343
|
-
directoryId,
|
|
344
|
-
...requestOptions,
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Enables SCIM directory synchronization for an organization.
|
|
350
|
-
*
|
|
351
|
-
* Activates automatic user and group synchronization from the organization's identity provider.
|
|
352
|
-
* Once enabled, users and groups from the IdP will be synced to your application, and any changes
|
|
353
|
-
* in the IdP (additions, updates, deletions) will be automatically reflected. This is essential
|
|
354
|
-
* for implementing automated user provisioning and deprovisioning.
|
|
355
|
-
*
|
|
356
|
-
* @param {string} organizationId - The organization ID (format: "org_...")
|
|
357
|
-
* @param {string} directoryId - The directory ID to enable (format: "dir_...")
|
|
358
|
-
*
|
|
359
|
-
* @returns {Promise<ToggleDirectoryResponse>} Response containing:
|
|
360
|
-
* - directory: The updated directory object with enabled status set to true
|
|
361
|
-
*
|
|
362
|
-
* @throws {Error} If the organization or directory is not found
|
|
363
|
-
* @throws {Error} If the directory configuration is incomplete or invalid
|
|
364
|
-
*
|
|
365
|
-
* @example
|
|
366
|
-
* // Enable directory sync
|
|
367
|
-
* const response = await scalekitClient.directory.enableDirectory(
|
|
368
|
-
* 'org_123456',
|
|
369
|
-
* 'dir_abc123'
|
|
370
|
-
* );
|
|
371
|
-
*
|
|
372
|
-
* console.log('Directory enabled:', response.directory.enabled); // true
|
|
373
|
-
* console.log('Sync will start automatically');
|
|
374
|
-
*
|
|
375
|
-
* @see {@link https://docs.scalekit.com/apis/#tag/directory | Enable Directory API}
|
|
376
|
-
* @see {@link disableDirectory} - Disable directory sync
|
|
377
|
-
* @see {@link getDirectory} - Check directory status
|
|
378
|
-
* @see {@link listDirectoryUsers} - View synced users after enabling
|
|
379
|
-
*/
|
|
380
|
-
async enableDirectory(
|
|
381
|
-
organizationId: string,
|
|
382
|
-
directoryId: string
|
|
383
|
-
): Promise<ToggleDirectoryResponse> {
|
|
384
|
-
return this.coreClient.connectExec(this.client.enableDirectory, {
|
|
385
|
-
organizationId,
|
|
386
|
-
id: directoryId,
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Disables SCIM directory synchronization for an organization.
|
|
392
|
-
*
|
|
393
|
-
* Stops automatic user and group synchronization from the organization's identity provider.
|
|
394
|
-
* When disabled, no new updates will be received from the IdP, but existing synced users and
|
|
395
|
-
* groups remain in your application. This is useful for temporarily pausing sync during maintenance,
|
|
396
|
-
* troubleshooting, or when migrating to a different directory provider. Does not delete existing data.
|
|
397
|
-
*
|
|
398
|
-
* @param {string} organizationId - The organization ID (format: "org_...")
|
|
399
|
-
* @param {string} directoryId - The directory ID to disable (format: "dir_...")
|
|
400
|
-
*
|
|
401
|
-
* @returns {Promise<ToggleDirectoryResponse>} Response containing:
|
|
402
|
-
* - directory: The updated directory object with enabled status set to false
|
|
403
|
-
*
|
|
404
|
-
* @throws {Error} If the organization or directory is not found
|
|
405
|
-
*
|
|
406
|
-
* @example
|
|
407
|
-
* // Disable directory sync
|
|
408
|
-
* const response = await scalekitClient.directory.disableDirectory(
|
|
409
|
-
* 'org_123456',
|
|
410
|
-
* 'dir_abc123'
|
|
411
|
-
* );
|
|
412
|
-
*
|
|
413
|
-
* console.log('Directory disabled:', !response.directory.enabled); // true
|
|
414
|
-
* console.log('Existing users and groups are preserved');
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
* @see {@link https://docs.scalekit.com/apis/#tag/directory | Disable Directory API}
|
|
418
|
-
* @see {@link enableDirectory} - Enable directory sync
|
|
419
|
-
* @see {@link getDirectory} - Check directory status
|
|
420
|
-
* @see {@link listDirectories} - List all directories
|
|
421
|
-
*/
|
|
422
|
-
async disableDirectory(
|
|
423
|
-
organizationId: string,
|
|
424
|
-
directoryId: string
|
|
425
|
-
): Promise<ToggleDirectoryResponse> {
|
|
426
|
-
return this.coreClient.connectExec(this.client.disableDirectory, {
|
|
427
|
-
organizationId,
|
|
428
|
-
id: directoryId,
|
|
429
|
-
});
|
|
430
|
-
}
|
|
431
|
-
}
|