@scalekit-sdk/node 1.0.3 → 1.0.5

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 (49) hide show
  1. package/.github/dependabot.yml +10 -0
  2. package/README.md +81 -11
  3. package/lib/connect.js +5 -4
  4. package/lib/connect.js.map +1 -1
  5. package/lib/connection.d.ts +17 -3
  6. package/lib/connection.js +36 -2
  7. package/lib/connection.js.map +1 -1
  8. package/lib/constants/user.d.ts +1 -1
  9. package/lib/core.d.ts +9 -5
  10. package/lib/core.js +27 -23
  11. package/lib/core.js.map +1 -1
  12. package/lib/domain.d.ts +1 -12
  13. package/lib/domain.js +0 -19
  14. package/lib/domain.js.map +1 -1
  15. package/lib/index.d.ts +4 -4
  16. package/lib/index.js +3 -3
  17. package/lib/index.js.map +1 -1
  18. package/lib/organization.d.ts +22 -4
  19. package/lib/organization.js +44 -7
  20. package/lib/organization.js.map +1 -1
  21. package/lib/scalekit.d.ts +12 -14
  22. package/lib/scalekit.js +18 -14
  23. package/lib/scalekit.js.map +1 -1
  24. package/lib/types/{user.d.ts → auth.d.ts} +5 -0
  25. package/lib/types/{user.js → auth.js} +1 -1
  26. package/lib/types/auth.js.map +1 -0
  27. package/lib/types/scalekit.d.ts +10 -9
  28. package/lib/types/scalekit.js.map +1 -1
  29. package/package.json +10 -11
  30. package/src/connect.ts +5 -5
  31. package/src/connection.ts +38 -15
  32. package/src/constants/user.ts +1 -1
  33. package/src/core.ts +32 -25
  34. package/src/domain.ts +0 -21
  35. package/src/index.ts +4 -4
  36. package/src/organization.ts +52 -5
  37. package/src/pkg/grpc/scalekit/v1/commons/commons_pb.ts +1 -1
  38. package/src/pkg/grpc/scalekit/v1/connections/connections_connect.ts +64 -1
  39. package/src/pkg/grpc/scalekit/v1/connections/connections_pb.ts +508 -156
  40. package/src/pkg/grpc/scalekit/v1/domains/domains_connect.ts +10 -1
  41. package/src/pkg/grpc/scalekit/v1/domains/domains_pb.ts +75 -1
  42. package/src/pkg/grpc/scalekit/v1/errdetails/errdetails_pb.ts +1 -1
  43. package/src/pkg/grpc/scalekit/v1/options/options_pb.ts +9 -1
  44. package/src/pkg/grpc/scalekit/v1/organizations/organizations_connect.ts +19 -1
  45. package/src/pkg/grpc/scalekit/v1/organizations/organizations_pb.ts +142 -1
  46. package/src/scalekit.ts +27 -17
  47. package/src/types/{user.ts → auth.ts} +6 -0
  48. package/src/types/scalekit.ts +11 -10
  49. package/lib/types/user.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"organization.js","sourceRoot":"","sources":["../src/organization.ts"],"names":[],"mappings":";;;;;;;;;;;AAIA,sGAAiG;AAGjG,MAAqB,kBAAkB;IAErC,YACmB,WAAwB,EACxB,UAAsB;QADtB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAY;QAEvC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,2CAAmB,CAAC,CAAC;IACnE,CAAC;IAED;;;;;;MAME;IACI,kBAAkB,CAAC,OAA8C;;YACrE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;YACrC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAC9B;gBACE,YAAY,EAAE;oBACZ,WAAW,EAAE,IAAI;oBACjB,UAAU,EAAE,UAAU;iBACvB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;;OAMG;IACG,gBAAgB,CAAC,OAGtB;;YACC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAC5B,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CACvB,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,eAAe,CAAC,EAAU;;YAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,I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IAAI,CAAA;QACtB,CAAC;KAAA;IAED;;;;OAIG;IACG,cAAc,CAAC,cAAsB;;YACzC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAChD,IAAI,CAAC,MAAM,CAAC,cAAc,EAC1B;gBACE,EAAE,EAAE,cAAc;aACnB,CACF,CAAA;YAED,OAAO,QAAQ,CAAC,KAAK,CAAA;QACvB,CAAC;KAAA;IAED;;;;;OAKG;IACG,gBAAgB,CAAC,cAAsB,EAAE,MAAc;;YAC3D,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAC5B;gBACE,EAAE,EAAE,cAAc;gBAClB,MAAM;aACP,CACF,CAAA;QACH,CAAC;KAAA;CACF;AAvKD,qCAuKC"}
package/lib/scalekit.d.ts CHANGED
@@ -1,18 +1,17 @@
1
1
  import ConnectionClient from './connection';
2
2
  import DomainClient from './domain';
3
3
  import OrganizationClient from './organization';
4
- import { AuthorizationUrlOptions, CodeAuthenticationOptions } from './types/scalekit';
5
- import { User } from './types/user';
4
+ import { AuthorizationUrlOptions, AuthenticationOptions, AuthenticationResponse } from './types/scalekit';
6
5
  /**
7
6
  * To initiate scalekit
8
7
  * @param {string} envUrl The environment url
9
8
  * @param {string} clientId The client id
10
9
  * @param {string} clientSecret The client secret
11
- * @returns {Scalekit} Returns the scalekit instance
10
+ * @returns {ScalekitClient} Returns the scalekit instance
12
11
  * @example
13
12
  * const scalekit = new Scalekit(envUrl, clientId, clientSecret);
14
13
  */
15
- export default class Scalekit {
14
+ export default class ScalekitClient {
16
15
  private readonly coreClient;
17
16
  private readonly grpcConnect;
18
17
  readonly organization: OrganizationClient;
@@ -30,6 +29,9 @@ export default class Scalekit {
30
29
  * @param {string} options.domainHint Domain hint parameter
31
30
  * @param {string} options.connectionId Connection id parameter
32
31
  * @param {string} options.organizationId Organization id parameter
32
+ * @param {string} options.provider Provider i.e. google, github, etc.
33
+ * @param {string} options.codeChallenge Code challenge parameter in case of PKCE
34
+ * @param {string} options.codeChallengeMethod Code challenge method parameter in case of PKCE
33
35
  *
34
36
  * @example
35
37
  * const scalekit = new Scalekit(envUrl, clientId, clientSecret);
@@ -39,17 +41,13 @@ export default class Scalekit {
39
41
  getAuthorizationUrl(redirectUri: string, options?: AuthorizationUrlOptions): string;
40
42
  /**
41
43
  * Authenticate with the code
42
- * @param {CodeAuthenticationOptions} options Code authentication options
43
- * @param {string} options.code Code
44
- * @param {string} options.redirectUri Redirect uri
45
- * @param {string} options.codeVerifier Code verifier
46
- * @returns {Promise<{ user: Partial<User>, idToken: string, accessToken: string }>} Returns user, id token and access token
44
+ * @param {string} code Code
45
+ * @param {string} redirectUri Redirect uri
46
+ * @param {AuthenticationOptions} options Code authentication options
47
+ * @param {string} options.codeVerifier Code verifier in case of PKCE
48
+ * @returns {Promise<AuthenticationResponse>} Returns user, id token and access token
47
49
  */
48
- authenticateWithCode(options: CodeAuthenticationOptions): Promise<{
49
- user: Partial<User>;
50
- idToken: string;
51
- accessToken: string;
52
- }>;
50
+ authenticateWithCode(code: string, redirectUri: string, options?: AuthenticationOptions): Promise<AuthenticationResponse>;
53
51
  /**
54
52
  * Validates the access token.
55
53
  *
package/lib/scalekit.js CHANGED
@@ -50,11 +50,11 @@ const authorizeEndpoint = "oauth/authorize";
50
50
  * @param {string} envUrl The environment url
51
51
  * @param {string} clientId The client id
52
52
  * @param {string} clientSecret The client secret
53
- * @returns {Scalekit} Returns the scalekit instance
53
+ * @returns {ScalekitClient} Returns the scalekit instance
54
54
  * @example
55
55
  * const scalekit = new Scalekit(envUrl, clientId, clientSecret);
56
56
  */
57
- class Scalekit {
57
+ class ScalekitClient {
58
58
  constructor(envUrl, clientId, clientSecret) {
59
59
  this.coreClient = new core_1.default(envUrl, clientId, clientSecret);
60
60
  this.grpcConnect = new connect_1.default(this.coreClient);
@@ -73,6 +73,9 @@ class Scalekit {
73
73
  * @param {string} options.domainHint Domain hint parameter
74
74
  * @param {string} options.connectionId Connection id parameter
75
75
  * @param {string} options.organizationId Organization id parameter
76
+ * @param {string} options.provider Provider i.e. google, github, etc.
77
+ * @param {string} options.codeChallenge Code challenge parameter in case of PKCE
78
+ * @param {string} options.codeChallengeMethod Code challenge method parameter in case of PKCE
76
79
  *
77
80
  * @example
78
81
  * const scalekit = new Scalekit(envUrl, clientId, clientSecret);
@@ -82,24 +85,24 @@ class Scalekit {
82
85
  getAuthorizationUrl(redirectUri, options) {
83
86
  var _a;
84
87
  const defaultOptions = {
85
- scopes: ['openid', 'profile']
88
+ scopes: ['openid', 'profile', 'email']
86
89
  };
87
90
  options = Object.assign(Object.assign({}, defaultOptions), options);
88
- const qs = qs_1.default.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ response_type: 'code', client_id: this.coreClient.clientId, redirect_uri: redirectUri, scope: (_a = options.scopes) === null || _a === void 0 ? void 0 : _a.join(" ") }, (options.state && { state: options.state })), (options.nonce && { nonce: options.nonce })), (options.loginHint && { login_hint: options.loginHint })), (options.domainHint && { domain_hint: options.domainHint })), (options.domainHint && { domain: options.domainHint })), (options.connectionId && { connection_id: options.connectionId })), (options.organizationId && { organization_id: options.organizationId })));
91
+ const qs = qs_1.default.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ response_type: 'code', client_id: this.coreClient.clientId, redirect_uri: redirectUri, scope: (_a = options.scopes) === null || _a === void 0 ? void 0 : _a.join(" ") }, (options.state && { state: options.state })), (options.nonce && { nonce: options.nonce })), (options.loginHint && { login_hint: options.loginHint })), (options.domainHint && { domain_hint: options.domainHint })), (options.domainHint && { domain: options.domainHint })), (options.connectionId && { connection_id: options.connectionId })), (options.organizationId && { organization_id: options.organizationId })), (options.codeChallenge && { code_challenge: options.codeChallenge })), (options.codeChallengeMethod && { code_challenge_method: options.codeChallengeMethod })));
89
92
  return `${this.coreClient.envUrl}/${authorizeEndpoint}?${qs}`;
90
93
  }
91
94
  /**
92
95
  * Authenticate with the code
93
- * @param {CodeAuthenticationOptions} options Code authentication options
94
- * @param {string} options.code Code
95
- * @param {string} options.redirectUri Redirect uri
96
- * @param {string} options.codeVerifier Code verifier
97
- * @returns {Promise<{ user: Partial<User>, idToken: string, accessToken: string }>} Returns user, id token and access token
96
+ * @param {string} code Code
97
+ * @param {string} redirectUri Redirect uri
98
+ * @param {AuthenticationOptions} options Code authentication options
99
+ * @param {string} options.codeVerifier Code verifier in case of PKCE
100
+ * @returns {Promise<AuthenticationResponse>} Returns user, id token and access token
98
101
  */
99
- authenticateWithCode(options) {
102
+ authenticateWithCode(code, redirectUri, options) {
100
103
  return __awaiter(this, void 0, void 0, function* () {
101
- const res = yield this.coreClient.authenticate(qs_1.default.stringify(Object.assign({ code: options.code, redirect_uri: options.redirectUri, grant_type: scalekit_1.GrantType.AuthorizationCode, client_id: this.coreClient.clientId, client_secret: this.coreClient.clientSecret }, (options.codeVerifier && { code_verifier: options.codeVerifier }))));
102
- const { id_token, access_token } = res.data;
104
+ const res = yield this.coreClient.authenticate(qs_1.default.stringify(Object.assign({ code: code, redirect_uri: redirectUri, grant_type: scalekit_1.GrantType.AuthorizationCode, client_id: this.coreClient.clientId, client_secret: this.coreClient.clientSecret }, ((options === null || options === void 0 ? void 0 : options.codeVerifier) && { code_verifier: options.codeVerifier }))));
105
+ const { id_token, access_token, expires_in } = res.data;
103
106
  const claims = jose.decodeJwt(id_token);
104
107
  const user = {};
105
108
  for (const [k, v] of Object.entries(claims)) {
@@ -110,7 +113,8 @@ class Scalekit {
110
113
  return {
111
114
  user,
112
115
  idToken: id_token,
113
- accessToken: access_token
116
+ accessToken: access_token,
117
+ expiresIn: expires_in
114
118
  };
115
119
  });
116
120
  }
@@ -136,5 +140,5 @@ class Scalekit {
136
140
  });
137
141
  }
138
142
  }
139
- exports.default = Scalekit;
143
+ exports.default = ScalekitClient;
140
144
  //# sourceMappingURL=scalekit.js.map
@@ -1 +1 @@
1
- {"version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IAAI,CAAC,SAAS,CAAe,QAAQ,CAAC,CAAC;YACtD,MAAM,IAAI,GAAS,EAAE,CAAC;YACtB,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC5C,IAAI,4BAAqB,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC7B,IAAI,CAAC,4BAAqB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;gBACrC,CAAC;YACH,CAAC;YAED,OAAO;gBACL,IAAI;gBACJ,OAAO,EAAE,QAAQ;gBACjB,WAAW,EAAE,YAAY;gBACzB,SAAS,EAAE,UAAU;aACtB,CAAA;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACG,mBAAmB,CAAC,KAAa;;YACrC,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;YAChC,MAAM,IAAI,GAAG,IAAI,CAAC,iBAAiB,CAAC;gBAClC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI;aAC3B,CAAC,CAAA;YACF,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;gBAClC,OAAO,IAAI,CAAC;YACd,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;KAAA;CACF;AA5ID,iCA4IC"}
@@ -54,3 +54,8 @@ export type IdTokenClaim = {
54
54
  identities: IdTokenClaimIdentity[];
55
55
  metadata: string | undefined;
56
56
  };
57
+ export type TokenResponse = {
58
+ access_token: string;
59
+ id_token: string;
60
+ expires_in: number;
61
+ };
@@ -1,3 +1,3 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=user.js.map
3
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":""}
@@ -1,3 +1,4 @@
1
+ import { User } from './auth';
1
2
  export declare enum GrantType {
2
3
  AuthorizationCode = "authorization_code",
3
4
  RefreshToken = "refresh_token",
@@ -11,16 +12,16 @@ export type AuthorizationUrlOptions = {
11
12
  nonce?: string;
12
13
  domainHint?: string;
13
14
  loginHint?: string;
15
+ codeChallenge?: string;
16
+ codeChallengeMethod?: string;
17
+ provider?: string;
14
18
  };
15
- export type CodeAuthenticationOptions = {
16
- code: string;
17
- redirectUri: string;
19
+ export type AuthenticationOptions = {
18
20
  codeVerifier?: string;
19
21
  };
20
- export type RefreshTokenAuthenticationOptions = {
21
- code: string;
22
- redirectUri: string;
23
- };
24
- export type AuthenticationOptions = {
25
- refreshToken: string;
22
+ export type AuthenticationResponse = {
23
+ user: User;
24
+ idToken: string;
25
+ accessToken: string;
26
+ expiresIn: number;
26
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"scalekit.js","sourceRoot":"","sources":["../../src/types/scalekit.ts"],"names":[],"mappings":";;;AAAA,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,qDAAwC,CAAA;IACxC,2CAA8B,CAAA;IAC9B,qDAAwC,CAAA;AAC1C,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB"}
1
+ {"version":3,"file":"scalekit.js","sourceRoot":"","sources":["../../src/types/scalekit.ts"],"names":[],"mappings":";;;AAEA,IAAY,SAIX;AAJD,WAAY,SAAS;IACnB,qDAAwC,CAAA;IACxC,2CAA8B,CAAA;IAC9B,qDAAwC,CAAA;AAC1C,CAAC,EAJW,SAAS,yBAAT,SAAS,QAIpB"}
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.3",
2
+ "version": "1.0.5",
3
3
  "name": "@scalekit-sdk/node",
4
4
  "description": "Official Scalekit Node SDK",
5
5
  "main": "lib/index.js",
@@ -25,25 +25,24 @@
25
25
  "dependencies": {
26
26
  "@connectrpc/connect": "^1.4.0",
27
27
  "@connectrpc/connect-node": "^1.4.0",
28
- "axios": "^1.6.8",
29
- "jose": "^5.2.4",
30
- "qs": "^6.12.1"
28
+ "axios": "^1.7.2",
29
+ "jose": "^5.6.3",
30
+ "qs": "^6.12.2"
31
31
  },
32
32
  "devDependencies": {
33
- "@bufbuild/buf": "^1.30.1",
34
- "@bufbuild/protobuf": "^1.8.0",
35
- "@bufbuild/protoc-gen-es": "^1.8.0",
33
+ "@bufbuild/buf": "^1.34.0",
34
+ "@bufbuild/protobuf": "^1.10.0",
35
+ "@bufbuild/protoc-gen-es": "^1.10.0",
36
36
  "@connectrpc/protoc-gen-connect-es": "^1.4.0",
37
- "@types/node": "^20.12.7",
37
+ "@types/node": "^20.14.10",
38
38
  "@types/qs": "^6.9.15",
39
- "typescript": "^5.4.5"
39
+ "typescript": "^5.5.3"
40
40
  },
41
41
  "bugs": {
42
42
  "url": "https://github.com/scalekit-inc/scalekit-sdk-node/issues"
43
43
  },
44
44
  "homepage": "https://github.com/scalekit-inc/scalekit-sdk-node#readme",
45
45
  "directories": {
46
- "example": "examples",
47
46
  "lib": "lib"
48
47
  }
49
- }
48
+ }
package/src/connect.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ServiceType } from '@bufbuild/protobuf';
2
2
  import { PromiseClient, Transport, createPromiseClient } from '@connectrpc/connect';
3
3
  import { createGrpcTransport } from '@connectrpc/connect-node';
4
- import CoreClient from './core';
4
+ import CoreClient, { headers } from './core';
5
5
 
6
6
  export default class GrpcConnect {
7
7
  private transport: Transport;
@@ -14,11 +14,11 @@ export default class GrpcConnect {
14
14
  interceptors: [
15
15
  (next) => {
16
16
  return (req) => {
17
- req.header.set("User-Agent", this.coreClient.userAgent)
18
- req.header.set("x-sdk-version", this.coreClient.sdkVersion)
19
- req.header.set("x-api-version", this.coreClient.apiVersion)
17
+ req.header.set(headers['user-agent'], this.coreClient.userAgent)
18
+ req.header.set(headers['x-sdk-version'], this.coreClient.sdkVersion)
19
+ req.header.set(headers['x-api-version'], this.coreClient.apiVersion)
20
20
  if (this.coreClient.accessToken) {
21
- req.header.set("Authorization", `Bearer ${this.coreClient.accessToken}`)
21
+ req.header.set(headers.authorization, `Bearer ${this.coreClient.accessToken}`)
22
22
  }
23
23
  return next(req)
24
24
  }
package/src/connection.ts CHANGED
@@ -2,7 +2,7 @@ import { PromiseClient } from '@connectrpc/connect';
2
2
  import GrpcConnect from './connect';
3
3
  import CoreClient from './core';
4
4
  import { ConnectionService } from './pkg/grpc/scalekit/v1/connections/connections_connect';
5
- import { GetConnectionResponse, ListConnectionsResponse } from './pkg/grpc/scalekit/v1/connections/connections_pb';
5
+ import { GetConnectionResponse, ToggleConnectionResponse, ListConnectionsResponse } from './pkg/grpc/scalekit/v1/connections/connections_pb';
6
6
 
7
7
  export default class ConnectionClient {
8
8
  private client: PromiseClient<typeof ConnectionService>;
@@ -15,19 +15,16 @@ export default class ConnectionClient {
15
15
 
16
16
  /**
17
17
  * Get a connection by id and organization id
18
- * @param id The connection id
19
18
  * @param organizationId The organization id
19
+ * @param id The connection id
20
20
  * @returns {Promise<GetConnectionResponse>} The connection
21
21
  */
22
- async getConnection(id: string, organizationId: string): Promise<GetConnectionResponse> {
22
+ async getConnection(organizationId: string, id: string): Promise<GetConnectionResponse> {
23
23
  return this.coreClient.connectExec(
24
24
  this.client.getConnection,
25
25
  {
26
26
  id,
27
- identities: {
28
- case: 'organizationId',
29
- value: organizationId
30
- }
27
+ organizationId
31
28
  },
32
29
  )
33
30
  }
@@ -41,10 +38,7 @@ export default class ConnectionClient {
41
38
  return this.coreClient.connectExec(
42
39
  this.client.listConnections,
43
40
  {
44
- identities: {
45
- case: 'domain',
46
- value: domain
47
- }
41
+ domain
48
42
  },
49
43
  )
50
44
  }
@@ -58,10 +52,39 @@ export default class ConnectionClient {
58
52
  return this.coreClient.connectExec(
59
53
  this.client.listConnections,
60
54
  {
61
- identities: {
62
- case: 'organizationId',
63
- value: organizationId
64
- }
55
+ organizationId
56
+ },
57
+ )
58
+ }
59
+
60
+ /**
61
+ * Enable a connection by id and organization id
62
+ * @param organizationId The organization id
63
+ * @param id The connection id
64
+ * @returns {Promise<ToggleConnectionResponse>} The connection enable response
65
+ */
66
+ async enableConnection(organizationId: string, id: string): Promise<ToggleConnectionResponse> {
67
+ return this.coreClient.connectExec(
68
+ this.client.enableConnection,
69
+ {
70
+ id,
71
+ organizationId
72
+ },
73
+ )
74
+ }
75
+
76
+ /**
77
+ * Disable a connection by id and organization id
78
+ * @param organizationId The organization id
79
+ * @param id The connection id
80
+ * @returns {Promise<ToggleConnectionResponse>} The connection enable response
81
+ */
82
+ async disableConnection(organizationId: string, id: string): Promise<ToggleConnectionResponse> {
83
+ return this.coreClient.connectExec(
84
+ this.client.disableConnection,
85
+ {
86
+ id,
87
+ organizationId
65
88
  },
66
89
  )
67
90
  }
@@ -1,4 +1,4 @@
1
- import type { IdTokenClaim, User } from '../types/user';
1
+ import type { IdTokenClaim, User } from '../types/auth';
2
2
 
3
3
  export const IdTokenClaimToUserMap: { [k in keyof IdTokenClaim]: keyof User } = {
4
4
  "sub": "id",
package/src/core.ts CHANGED
@@ -5,6 +5,14 @@ import os from "os";
5
5
  import QueryString from "qs";
6
6
  import { GrantType } from './types/scalekit';
7
7
  import { ErrorInfo } from './pkg/grpc/scalekit/v1/errdetails/errdetails_pb';
8
+ import { TokenResponse } from './types/auth';
9
+
10
+ export const headers = {
11
+ "user-agent": "user-agent",
12
+ "x-sdk-version": "x-sdk-version",
13
+ "x-api-version": "x-api-version",
14
+ "authorization": "authorization"
15
+ }
8
16
 
9
17
  const tokenEndpoint = "oauth/token";
10
18
  const jwksEndpoint = "keys";
@@ -12,7 +20,7 @@ export default class CoreClient {
12
20
  public keys: JWK[] = [];
13
21
  public accessToken: string | null = null;
14
22
  public axios: Axios;
15
- public sdkVersion = `Scalekit-Node/1.0.3`;
23
+ public sdkVersion = `Scalekit-Node/1.0.5`;
16
24
  public apiVersion = "20240430";
17
25
  public userAgent = `${this.sdkVersion} Node/${process.version} (${process.platform}; ${os.arch()})`;
18
26
  constructor(
@@ -22,11 +30,11 @@ export default class CoreClient {
22
30
  ) {
23
31
  this.axios = axios.create({ baseURL: envUrl });
24
32
  this.axios.interceptors.request.use((config) => {
25
- config.headers["User-Agent"] = this.userAgent;
26
- config.headers["x-sdk-version"] = this.sdkVersion;
27
- config.headers["x-api-version"] = this.apiVersion;
33
+ config.headers[headers['user-agent']] = this.userAgent;
34
+ config.headers[headers['x-sdk-version']] = this.sdkVersion;
35
+ config.headers[headers['x-api-version']] = this.apiVersion;
28
36
  if (this.accessToken) {
29
- config.headers["Authorization"] = `Bearer ${this.accessToken}`;
37
+ config.headers[headers.authorization] = `Bearer ${this.accessToken}`;
30
38
  }
31
39
 
32
40
  return config;
@@ -46,10 +54,10 @@ export default class CoreClient {
46
54
  /**
47
55
  * Authenticate with the code
48
56
  * @param {string} data Data to authenticate
49
- * @returns {Promise<AxiosResponse<{ access_token: string, id_token: string }>>} Returns access token and id token
57
+ * @returns {Promise<AxiosResponse<TokenResponse>>} Returns access token and id token
50
58
  */
51
- async authenticate(data: string): Promise<AxiosResponse<{ access_token: string; id_token: string; }, any>> {
52
- return this.axios.post<{ access_token: string, id_token: string }>(
59
+ async authenticate(data: string): Promise<AxiosResponse<TokenResponse, any>> {
60
+ return this.axios.post<TokenResponse>(
53
61
  tokenEndpoint,
54
62
  data,
55
63
  {
@@ -89,10 +97,10 @@ export default class CoreClient {
89
97
  return res;
90
98
  } catch (error) {
91
99
  if (retryLeft > 0) {
92
- let isUnauthenticatedError = false;
100
+ let isUnAuthenticatedError = false;
93
101
  if (error instanceof AxiosError) {
94
102
  if (error.status == HttpStatusCode.Unauthorized) {
95
- isUnauthenticatedError = true;
103
+ isUnAuthenticatedError = true;
96
104
  } else {
97
105
  throw new Error(error.message);
98
106
  }
@@ -100,23 +108,22 @@ export default class CoreClient {
100
108
  // ConnectError is a custom error class that extends Error class and has a code property
101
109
  if (error instanceof ConnectError) {
102
110
  if (error.code == Code.Unauthenticated) {
103
- isUnauthenticatedError = true;
104
- } else {
105
- if (error.code == Code.InvalidArgument) {
106
- const message = error.findDetails(ErrorInfo).map((detail) => {
107
- if (detail.validationErrorInfo) {
108
- return detail.validationErrorInfo.fieldViolations.map((fv) => {
109
- return `${fv.field}: ${fv.description}`
110
- }).join("\n")
111
- }
112
- return error.message;
113
- }).join("\n")
114
- throw new Error(message);
115
- }
116
- throw new Error(error.message);
111
+ isUnAuthenticatedError = true;
112
+ }
113
+ if (error.code == Code.InvalidArgument) {
114
+ const messages = [error.message]
115
+ error.findDetails(ErrorInfo).forEach((detail) => {
116
+ if (detail.validationErrorInfo) {
117
+ detail.validationErrorInfo.fieldViolations.forEach((fv) => {
118
+ messages.push(`${fv.field}: ${fv.description}`)
119
+ })
120
+ }
121
+ })
122
+
123
+ throw new Error(messages.join("\n"));
117
124
  }
118
125
  }
119
- if (isUnauthenticatedError) {
126
+ if (isUnAuthenticatedError) {
120
127
  await this.authenticateClient();
121
128
  return this.connectExec(fn, data, retryLeft - 1);
122
129
  }
package/src/domain.ts CHANGED
@@ -34,27 +34,6 @@ export default class DomainClient {
34
34
  )
35
35
  }
36
36
 
37
- /**
38
- * Get a domain by id
39
- * @param {object} options The options to get a domain
40
- * @param {string} options.id The domain id
41
- * @param {string} options.organizationId The organization id
42
- * @returns {Promise<GetDomainResponse>} The domain
43
- */
44
- async getDomain(options: { id: string, organizationId: string }): Promise<GetDomainResponse> {
45
- const { id, organizationId } = options;
46
- return this.coreClient.connectExec(
47
- this.client.getDomain,
48
- {
49
- id,
50
- identities: {
51
- case: 'organizationId',
52
- value: organizationId
53
- }
54
- }
55
- )
56
- }
57
-
58
37
  /**
59
38
  * List domains for an organization
60
39
  * @param organizationId The organization id
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- import Scalekit from "./scalekit";
1
+ import ScalekitClient from "./scalekit";
2
2
 
3
- export { Scalekit };
4
- export default Scalekit;
3
+ export { ScalekitClient };
4
+ export default ScalekitClient;
5
5
 
6
6
  export * from "./types/scalekit";
7
- export * from "./types/user";
7
+ export * from "./types/auth";
@@ -1,4 +1,4 @@
1
- import { PartialMessage } from '@bufbuild/protobuf';
1
+ import { Empty, PartialMessage } from '@bufbuild/protobuf';
2
2
  import { PromiseClient } from '@connectrpc/connect';
3
3
  import GrpcConnect from './connect';
4
4
  import CoreClient from './core';
@@ -16,19 +16,20 @@ export default class OrganizationClient {
16
16
 
17
17
  /**
18
18
  * Create an organization with the given name. Optionally, you can provide an external id.
19
+ * @param {string} name The organization name
19
20
  * @param {object} options The options to create an organization
20
- * @param {string} options.name The organization name
21
21
  * @param {string} options.externalId The external id
22
22
  * @returns {Promise<CreateOrganizationResponse>} The created organization
23
23
  */
24
- async createOrganization(options: { name: string, externalId?: string }): Promise<CreateOrganizationResponse> {
25
- const { name, externalId } = options;
24
+ async createOrganization(name: string, options?: { externalId?: string }): Promise<CreateOrganizationResponse> {
26
25
  return this.coreClient.connectExec(
27
26
  this.client.createOrganization,
28
27
  {
29
28
  organization: {
30
29
  displayName: name,
31
- externalId: externalId
30
+ ...(options?.externalId && {
31
+ externalId: options.externalId
32
+ })
32
33
  }
33
34
  }
34
35
  )
@@ -107,6 +108,20 @@ export default class OrganizationClient {
107
108
  )
108
109
  }
109
110
 
111
+ /**
112
+ * Delete an organization by id
113
+ * @param {string} organizationId The organization id
114
+ * @returns {Promise<Empty>} Returns nothing
115
+ */
116
+ async deleteOrganization(organizationId: string): Promise<Empty> {
117
+ return this.coreClient.connectExec(
118
+ this.client.deleteOrganization,
119
+ {
120
+ identities: { case: "id", value: organizationId, },
121
+ },
122
+ )
123
+ }
124
+
110
125
  /**
111
126
  * Generate admin portal link for an organization
112
127
  * @param organizationId The organization id
@@ -125,5 +140,37 @@ export default class OrganizationClient {
125
140
 
126
141
  return response.link
127
142
  }
143
+
144
+ /**
145
+ * Get admin portal links for an organization
146
+ * @param organizationId The organization id
147
+ * @returns {Promise<Link[]>} The admin portal link object with expiration time and location
148
+ */
149
+ async getPortalLinks(organizationId: string): Promise<Link[]> {
150
+ const response = await this.coreClient.connectExec(
151
+ this.client.getPortalLinks,
152
+ {
153
+ id: organizationId
154
+ },
155
+ )
156
+
157
+ return response.links
158
+ }
159
+
160
+ /**
161
+ * Delete admin portal link for an organization
162
+ * @param organizationId The organization id
163
+ * @param linkId The link id
164
+ * @returns {Promise<Empty>} Returns nothing
165
+ */
166
+ async deletePortalLink(organizationId: string, linkId: string): Promise<Empty> {
167
+ return this.coreClient.connectExec(
168
+ this.client.deletePortalLink,
169
+ {
170
+ id: organizationId,
171
+ linkId
172
+ },
173
+ )
174
+ }
128
175
  }
129
176
 
@@ -1,4 +1,4 @@
1
- // @generated by protoc-gen-es v1.9.0 with parameter "target=ts"
1
+ // @generated by protoc-gen-es v1.10.0 with parameter "target=ts"
2
2
  // @generated from file scalekit/v1/commons/commons.proto (package scalekit.v1.commons, syntax proto3)
3
3
  /* eslint-disable */
4
4
  // @ts-nocheck