From b0119c746e7f52808d68bf11612ffb670edb1582 Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Wed, 15 May 2024 12:12:05 +0530 Subject: [PATCH 01/19] add example --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 48c6d25..914cfcd 100644 --- a/README.md +++ b/README.md @@ -34,11 +34,18 @@ pnpm add @scalekit-sdk/node ```javascript import { Scalekit } from "@scalekit-sdk/node"; -const scalekit = new Scalekit( +const sc = new Scalekit( process.env.SCALEKIT_ENV_URL!, process.env.SCALEKIT_CLIENT_ID!, process.env.SCALEKIT_CLIENT_SECRET! ); + +// Use the sc object to interact with the Scalekit API +const authUrl = sc.getAuthorizationUrl("https://acme-corp.com/redirect-uri", { + state: "state", + connectionId: "connection_id", +}); + ``` ## API Reference From 752e6f7c0df0fc6d9c31da0bc764573675539127 Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Wed, 15 May 2024 12:13:05 +0530 Subject: [PATCH 02/19] refactor headers --- src/connect.ts | 4 ++-- src/core.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/connect.ts b/src/connect.ts index f121a6a..7fc1b8f 100644 --- a/src/connect.ts +++ b/src/connect.ts @@ -15,8 +15,8 @@ export default class GrpcConnect { (next) => { return (req) => { req.header.set("User-Agent", this.coreClient.userAgent) - req.header.set("x-sdk-version", this.coreClient.sdkVersion) - req.header.set("x-api-version", this.coreClient.apiVersion) + req.header.set("X-Sdk-Version", this.coreClient.sdkVersion) + req.header.set("X-Api-Version", this.coreClient.apiVersion) if (this.coreClient.accessToken) { req.header.set("Authorization", `Bearer ${this.coreClient.accessToken}`) } diff --git a/src/core.ts b/src/core.ts index 6471422..66bbad7 100644 --- a/src/core.ts +++ b/src/core.ts @@ -23,8 +23,8 @@ export default class CoreClient { this.axios = axios.create({ baseURL: envUrl }); this.axios.interceptors.request.use((config) => { config.headers["User-Agent"] = this.userAgent; - config.headers["x-sdk-version"] = this.sdkVersion; - config.headers["x-api-version"] = this.apiVersion; + config.headers["X-Sdk-Version"] = this.sdkVersion; + config.headers["X-Api-Version"] = this.apiVersion; if (this.accessToken) { config.headers["Authorization"] = `Bearer ${this.accessToken}`; } From 3d2244ca409aed569d8b92e35403be32c077c1cc Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Wed, 15 May 2024 12:13:37 +0530 Subject: [PATCH 03/19] refactor error handling --- src/core.ts | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/core.ts b/src/core.ts index 66bbad7..fe8a65d 100644 --- a/src/core.ts +++ b/src/core.ts @@ -89,10 +89,10 @@ export default class CoreClient { return res; } catch (error) { if (retryLeft > 0) { - let isUnauthenticatedError = false; + let isUnAuthenticatedError = false; if (error instanceof AxiosError) { if (error.status == HttpStatusCode.Unauthorized) { - isUnauthenticatedError = true; + isUnAuthenticatedError = true; } else { throw new Error(error.message); } @@ -100,23 +100,22 @@ export default class CoreClient { // ConnectError is a custom error class that extends Error class and has a code property if (error instanceof ConnectError) { if (error.code == Code.Unauthenticated) { - isUnauthenticatedError = true; - } else { - if (error.code == Code.InvalidArgument) { - const message = error.findDetails(ErrorInfo).map((detail) => { - if (detail.validationErrorInfo) { - return detail.validationErrorInfo.fieldViolations.map((fv) => { - return `${fv.field}: ${fv.description}` - }).join("\n") - } - return error.message; - }).join("\n") - throw new Error(message); - } - throw new Error(error.message); + isUnAuthenticatedError = true; + } + if (error.code == Code.InvalidArgument) { + const messages = [error.message] + error.findDetails(ErrorInfo).forEach((detail) => { + if (detail.validationErrorInfo) { + detail.validationErrorInfo.fieldViolations.forEach((fv) => { + messages.push(`${fv.field}: ${fv.description}`) + }) + } + }) + + throw new Error(messages.join("\n")); } } - if (isUnauthenticatedError) { + if (isUnAuthenticatedError) { await this.authenticateClient(); return this.connectExec(fn, data, retryLeft - 1); } From 71afda9c201f234cd1ef6ae1f6ac849b478dff63 Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Wed, 15 May 2024 12:14:05 +0530 Subject: [PATCH 04/19] change method signature --- src/organization.ts | 9 +++++---- src/scalekit.ts | 20 ++++++++++++-------- src/types/scalekit.ts | 17 +++++++---------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/organization.ts b/src/organization.ts index d440f16..81057ed 100644 --- a/src/organization.ts +++ b/src/organization.ts @@ -16,19 +16,20 @@ export default class OrganizationClient { /** * Create an organization with the given name. Optionally, you can provide an external id. + * @param {string} name The organization name * @param {object} options The options to create an organization - * @param {string} options.name The organization name * @param {string} options.externalId The external id * @returns {Promise} The created organization */ - async createOrganization(options: { name: string, externalId?: string }): Promise { - const { name, externalId } = options; + async createOrganization(name: string, options?: { externalId?: string }): Promise { return this.coreClient.connectExec( this.client.createOrganization, { organization: { displayName: name, - externalId: externalId + ...(options?.externalId && { + externalId: options.externalId + }) } } ) diff --git a/src/scalekit.ts b/src/scalekit.ts index cfb3c99..86ccdd7 100644 --- a/src/scalekit.ts +++ b/src/scalekit.ts @@ -6,7 +6,7 @@ import { IdTokenClaimToUserMap } from './constants/user'; import CoreClient from './core'; import DomainClient from './domain'; import OrganizationClient from './organization'; -import { AuthorizationUrlOptions, CodeAuthenticationOptions, GrantType } from './types/scalekit'; +import { AuthorizationUrlOptions, AuthenticationOptions, GrantType, AuthenticationResponse } from './types/scalekit'; import { IdTokenClaim, User } from './types/user'; const authorizeEndpoint = "oauth/authorize"; @@ -101,20 +101,24 @@ export default class Scalekit { /** * Authenticate with the code - * @param {CodeAuthenticationOptions} options Code authentication options - * @param {string} options.code Code - * @param {string} options.redirectUri Redirect uri + * @param {string} code Code + * @param {string} redirectUri Redirect uri + * @param {AuthenticationOptions} options Code authentication options * @param {string} options.codeVerifier Code verifier * @returns {Promise<{ user: Partial, idToken: string, accessToken: string }>} Returns user, id token and access token */ - async authenticateWithCode(options: CodeAuthenticationOptions): Promise<{ user: Partial; idToken: string; accessToken: string; }> { + async authenticateWithCode( + code: string, + redirectUri: string, + options?: AuthenticationOptions, + ): Promise { const res = await this.coreClient.authenticate(QueryString.stringify({ - code: options.code, - redirect_uri: options.redirectUri, + code: code, + redirect_uri: redirectUri, grant_type: GrantType.AuthorizationCode, client_id: this.coreClient.clientId, client_secret: this.coreClient.clientSecret, - ...(options.codeVerifier && { code_verifier: options.codeVerifier }) + ...(options?.codeVerifier && { code_verifier: options.codeVerifier }) })) const { id_token, access_token } = res.data; const claims = jose.decodeJwt(id_token); diff --git a/src/types/scalekit.ts b/src/types/scalekit.ts index 45c615b..486fc6f 100644 --- a/src/types/scalekit.ts +++ b/src/types/scalekit.ts @@ -1,3 +1,5 @@ +import { User } from './user'; + export enum GrantType { AuthorizationCode = 'authorization_code', RefreshToken = 'refresh_token', @@ -14,17 +16,12 @@ export type AuthorizationUrlOptions = { loginHint?: string; } -export type CodeAuthenticationOptions = { - code: string; - redirectUri: string; +export type AuthenticationOptions = { codeVerifier?: string; } -export type RefreshTokenAuthenticationOptions = { - code: string; - redirectUri: string; -} - -export type AuthenticationOptions = { - refreshToken: string; +export type AuthenticationResponse = { + user: Partial; + idToken: string; + accessToken: string; } \ No newline at end of file From 425ca239939811b38233ff25231e381913273346 Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Wed, 15 May 2024 14:12:18 +0530 Subject: [PATCH 05/19] add missing options --- src/scalekit.ts | 8 ++++++-- src/types/scalekit.ts | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/scalekit.ts b/src/scalekit.ts index 86ccdd7..de3d732 100644 --- a/src/scalekit.ts +++ b/src/scalekit.ts @@ -65,6 +65,8 @@ export default class Scalekit { * @param {string} options.domainHint Domain hint parameter * @param {string} options.connectionId Connection id parameter * @param {string} options.organizationId Organization id parameter + * @param {string} options.codeChallenge Code challenge parameter in case of PKCE + * @param {string} options.codeChallengeMethod Code challenge method parameter in case of PKCE * * @example * const scalekit = new Scalekit(envUrl, clientId, clientSecret); @@ -94,6 +96,8 @@ export default class Scalekit { ...(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 }) }) return `${this.coreClient.envUrl}/${authorizeEndpoint}?${qs}` @@ -104,8 +108,8 @@ export default class Scalekit { * @param {string} code Code * @param {string} redirectUri Redirect uri * @param {AuthenticationOptions} options Code authentication options - * @param {string} options.codeVerifier Code verifier - * @returns {Promise<{ user: Partial, idToken: string, accessToken: string }>} Returns user, id token and access token + * @param {string} options.codeVerifier Code verifier in case of PKCE + * @returns {Promise} Returns user, id token and access token */ async authenticateWithCode( code: string, diff --git a/src/types/scalekit.ts b/src/types/scalekit.ts index 486fc6f..9a7bda1 100644 --- a/src/types/scalekit.ts +++ b/src/types/scalekit.ts @@ -14,10 +14,12 @@ export type AuthorizationUrlOptions = { nonce?: string; domainHint?: string; loginHint?: string; + codeChallenge?: string; + codeChallengeMethod?: string; } export type AuthenticationOptions = { - codeVerifier?: string; + codeVerifier?: string; } export type AuthenticationResponse = { From a0d741b5113eae7412e1182e754faabf0ea9b184 Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Wed, 29 May 2024 17:31:42 +0530 Subject: [PATCH 06/19] add additional methods --- lib/connect.js | 4 ++-- lib/connection.d.ts | 16 +++++++++++++++- lib/connection.js | 34 +++++++++++++++++++++++++++++++++ lib/connection.js.map | 2 +- lib/core.js | 35 ++++++++++++++++------------------ lib/core.js.map | 2 +- lib/domain.d.ts | 13 +------------ lib/domain.js | 19 ------------------- lib/domain.js.map | 2 +- lib/index.d.ts | 6 +++--- lib/index.js | 4 ++-- lib/index.js.map | 2 +- lib/organization.d.ts | 20 ++++++++++++++++---- lib/organization.js | 39 +++++++++++++++++++++++++++++++------- lib/organization.js.map | 2 +- lib/scalekit.d.ts | 25 +++++++++++------------- lib/scalekit.js | 24 ++++++++++++----------- lib/scalekit.js.map | 2 +- lib/types/scalekit.d.ts | 17 ++++++++--------- lib/types/scalekit.js.map | 2 +- src/connection.ts | 40 ++++++++++++++++++++++++++++++++++++++- src/domain.ts | 21 -------------------- src/index.ts | 6 +++--- src/organization.ts | 34 ++++++++++++++++++++++++++++++++- src/scalekit.ts | 4 ++-- 25 files changed, 237 insertions(+), 138 deletions(-) diff --git a/lib/connect.js b/lib/connect.js index a317ffc..18af962 100644 --- a/lib/connect.js +++ b/lib/connect.js @@ -12,8 +12,8 @@ class GrpcConnect { (next) => { return (req) => { req.header.set("User-Agent", this.coreClient.userAgent); - req.header.set("x-sdk-version", this.coreClient.sdkVersion); - req.header.set("x-api-version", this.coreClient.apiVersion); + req.header.set("X-Sdk-Version", this.coreClient.sdkVersion); + req.header.set("X-Api-Version", this.coreClient.apiVersion); if (this.coreClient.accessToken) { req.header.set("Authorization", `Bearer ${this.coreClient.accessToken}`); } diff --git a/lib/connection.d.ts b/lib/connection.d.ts index 3c3a8ee..b6f5476 100644 --- a/lib/connection.d.ts +++ b/lib/connection.d.ts @@ -1,6 +1,6 @@ import GrpcConnect from './connect'; import CoreClient from './core'; -import { GetConnectionResponse, ListConnectionsResponse } from './pkg/grpc/scalekit/v1/connections/connections_pb'; +import { GetConnectionResponse, ToggleConnectionResponse, ListConnectionsResponse } from './pkg/grpc/scalekit/v1/connections/connections_pb'; export default class ConnectionClient { private readonly grpcConncet; private readonly coreClient; @@ -25,4 +25,18 @@ export default class ConnectionClient { * @returns {Promise} The list of connections */ listConnections(organizationId: string): Promise; + /** + * Enable a connection by id and organization id + * @param id The connection id + * @param organizationId The organization id + * @returns {Promise} The connection enable response + */ + enableConnection(id: string, organizationId: string): Promise; + /** + * Disable a connection by id and organization id + * @param id The connection id + * @param organizationId The organization id + * @returns {Promise} The connection enable response + */ + disableConnection(id: string, organizationId: string): Promise; } diff --git a/lib/connection.js b/lib/connection.js index ea9c8ff..b5190fe 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -63,6 +63,40 @@ class ConnectionClient { }); }); } + /** + * Enable a connection by id and organization id + * @param id The connection id + * @param organizationId The organization id + * @returns {Promise} The connection enable response + */ + enableConnection(id, organizationId) { + return __awaiter(this, void 0, void 0, function* () { + return this.coreClient.connectExec(this.client.enableConnection, { + id, + identities: { + case: 'organizationId', + value: organizationId + } + }); + }); + } + /** + * Disable a connection by id and organization id + * @param id The connection id + * @param organizationId The organization id + * @returns {Promise} The connection enable response + */ + disableConnection(id, organizationId) { + return __awaiter(this, void 0, void 0, function* () { + return this.coreClient.connectExec(this.client.disableConnection, { + id, + identities: { + case: 'organizationId', + value: organizationId + } + }); + }); + } } exports.default = ConnectionClient; //# sourceMappingURL=connection.js.map \ No newline at end of file diff --git a/lib/connection.js.map b/lib/connection.js.map index b013bc8..37406fa 100644 --- a/lib/connection.js.map +++ b/lib/connection.js.map @@ -1 +1 @@ -{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,gGAA2F;AAG3F,MAAqB,gBAAgB;IAEnC,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,uCAAiB,CAAC,CAAC;IACjE,CAAC;IAED;;;;;OAKG;IACG,aAAa,CAAC,EAAU,EAAE,cAAsB;;YACpD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,aAAa,EACzB;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,uBAAuB,CAAC,MAAc;;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,eAAe,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,MAAM;iBACd;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,eAAe,CAAC,cAAsB;;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,eAAe,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;CACF;AA7DD,mCA6DC"} \ No newline at end of file +{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,gGAA2F;AAG3F,MAAqB,gBAAgB;IAEnC,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,uCAAiB,CAAC,CAAC;IACjE,CAAC;IAED;;;;;OAKG;IACG,aAAa,CAAC,EAAU,EAAE,cAAsB;;YACpD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,aAAa,EACzB;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,uBAAuB,CAAC,MAAc;;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,eAAe,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,MAAM;iBACd;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,eAAe,CAAC,cAAsB;;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,eAAe,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACG,gBAAgB,CAAC,EAAU,EAAE,cAAsB;;YACvD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAC5B;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACG,iBAAiB,CAAC,EAAU,EAAE,cAAsB;;YACxD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAC7B;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;CACF;AAnGD,mCAmGC"} \ No newline at end of file diff --git a/lib/core.js b/lib/core.js index d735bb5..59d921c 100644 --- a/lib/core.js +++ b/lib/core.js @@ -56,8 +56,8 @@ class CoreClient { this.axios = axios_1.default.create({ baseURL: envUrl }); this.axios.interceptors.request.use((config) => { config.headers["User-Agent"] = this.userAgent; - config.headers["x-sdk-version"] = this.sdkVersion; - config.headers["x-api-version"] = this.apiVersion; + config.headers["X-Sdk-Version"] = this.sdkVersion; + config.headers["X-Api-Version"] = this.apiVersion; if (this.accessToken) { config.headers["Authorization"] = `Bearer ${this.accessToken}`; } @@ -117,10 +117,10 @@ class CoreClient { } catch (error) { if (retryLeft > 0) { - let isUnauthenticatedError = false; + let isUnAuthenticatedError = false; if (error instanceof axios_1.AxiosError) { if (error.status == axios_1.HttpStatusCode.Unauthorized) { - isUnauthenticatedError = true; + isUnAuthenticatedError = true; } else { throw new Error(error.message); @@ -129,24 +129,21 @@ class CoreClient { // ConnectError is a custom error class that extends Error class and has a code property if (error instanceof connect_1.ConnectError) { if (error.code == connect_1.Code.Unauthenticated) { - isUnauthenticatedError = true; + isUnAuthenticatedError = true; } - else { - if (error.code == connect_1.Code.InvalidArgument) { - const message = error.findDetails(errdetails_pb_1.ErrorInfo).map((detail) => { - if (detail.validationErrorInfo) { - return detail.validationErrorInfo.fieldViolations.map((fv) => { - return `${fv.field}: ${fv.description}`; - }).join("\n"); - } - return error.message; - }).join("\n"); - throw new Error(message); - } - throw new Error(error.message); + if (error.code == connect_1.Code.InvalidArgument) { + const messages = [error.message]; + error.findDetails(errdetails_pb_1.ErrorInfo).forEach((detail) => { + if (detail.validationErrorInfo) { + detail.validationErrorInfo.fieldViolations.forEach((fv) => { + messages.push(`${fv.field}: ${fv.description}`); + }); + } + }); + throw new Error(messages.join("\n")); } } - if (isUnauthenticatedError) { + if (isUnAuthenticatedError) { yield this.authenticateClient(); return this.connectExec(fn, data, retryLeft - 1); } diff --git a/lib/core.js.map b/lib/core.js.map index 9161662..8b54f2f 100644 --- a/lib/core.js.map +++ b/lib/core.js.map @@ -1 +1 @@ -{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAyD;AACzD,+CAAgF;AAEhF,4CAAoB;AACpB,4CAA6B;AAC7B,+CAA6C;AAC7C,mFAA4E;AAE5E,MAAM,aAAa,GAAG,aAAa,CAAC;AACpC,MAAM,YAAY,GAAG,MAAM,CAAC;AAC5B,MAAqB,UAAU;IAO7B,YACW,MAAc,EACd,QAAgB,EAChB,YAAoB;QAFpB,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAQ;QAChB,iBAAY,GAAZ,YAAY,CAAQ;QATxB,SAAI,GAAU,EAAE,CAAC;QACjB,gBAAW,GAAkB,IAAI,CAAC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,CAAC;wBAClC,IAAI,KAAK,CAAC,IAAI,IAAI,cAAI,CAAC,eAAe,EAAE,CAAC;4BACvC,sBAAsB,GAAG,IAAI,CAAC;wBAChC,CAAC;wBACD,IAAI,KAAK,CAAC,IAAI,IAAI,cAAI,CAAC,eAAe,EAAE,CAAC;4BACvC,MAAM,QAAQ,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;4BAChC,KAAK,CAAC,WAAW,CAAC,yBAAS,CAAC,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;gCAC9C,IAAI,MAAM,CAAC,mBAAmB,EAAE,CAAC;oCAC9B,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;wCACzD,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,WAAW,EAAE,CAAC,CAAA;oCACjD,CAAC,CAAC,CAAA;gCACJ,CAAC;4BACH,CAAC,CAAC,CAAA;4BAEF,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;wBACvC,CAAC;oBACH,CAAC;oBACD,IAAI,sBAAsB,EAAE,CAAC;wBAC3B,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;wBAChC,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;oBACnD,CAAC;gBACH,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KAAA;CACF;AAnHD,6BAmHC"} \ No newline at end of file diff --git a/lib/domain.d.ts b/lib/domain.d.ts index e0e0e86..4dc13c4 100644 --- a/lib/domain.d.ts +++ b/lib/domain.d.ts @@ -1,6 +1,6 @@ import GrpcConnect from './connect'; import CoreClient from './core'; -import { CreateDomainResponse, GetDomainResponse, ListDomainResponse } from './pkg/grpc/scalekit/v1/domains/domains_pb'; +import { CreateDomainResponse, ListDomainResponse } from './pkg/grpc/scalekit/v1/domains/domains_pb'; export default class DomainClient { private readonly grpcConncet; private readonly coreClient; @@ -13,17 +13,6 @@ export default class DomainClient { * @returns {Promise} The created domain */ createDomain(organizationId: string, name: string): Promise; - /** - * Get a domain by id - * @param {object} options The options to get a domain - * @param {string} options.id The domain id - * @param {string} options.organizationId The organization id - * @returns {Promise} The domain - */ - getDomain(options: { - id: string; - organizationId: string; - }): Promise; /** * List domains for an organization * @param organizationId The organization id diff --git a/lib/domain.js b/lib/domain.js index 09e6aed..c376a6a 100644 --- a/lib/domain.js +++ b/lib/domain.js @@ -35,25 +35,6 @@ class DomainClient { }); }); } - /** - * Get a domain by id - * @param {object} options The options to get a domain - * @param {string} options.id The domain id - * @param {string} options.organizationId The organization id - * @returns {Promise} The domain - */ - getDomain(options) { - return __awaiter(this, void 0, void 0, function* () { - const { id, organizationId } = options; - return this.coreClient.connectExec(this.client.getDomain, { - id, - identities: { - case: 'organizationId', - value: organizationId - } - }); - }); - } /** * List domains for an organization * @param organizationId The organization id diff --git a/lib/domain.js.map b/lib/domain.js.map index a01bb8e..a36ed2e 100644 --- a/lib/domain.js.map +++ b/lib/domain.js.map @@ -1 +1 @@ -{"version":3,"file":"domain.js","sourceRoot":"","sources":["../src/domain.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,oFAA+E;AAG/E,MAAqB,YAAY;IAE/B,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,+BAAa,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;MAKE;IACI,YAAY,CAAC,cAAsB,EAAE,IAAY;;YACrD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,YAAY,EACxB;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;gBACD,MAAM,EAAE;oBACN,MAAM,EAAE,IAAI;iBACb;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;;MAME;IACI,SAAS,CAAC,OAA+C;;YAC7D,MAAM,EAAE,EAAE,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;YACvC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,SAAS,EACrB;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,WAAW,CAAC,cAAsB;;YACtC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,WAAW,EACvB;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAC;QACJ,CAAC;KAAA;CACF;AAnED,+BAmEC"} \ No newline at end of file +{"version":3,"file":"domain.js","sourceRoot":"","sources":["../src/domain.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,oFAA+E;AAG/E,MAAqB,YAAY;IAE/B,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,+BAAa,CAAC,CAAC;IAC7D,CAAC;IAED;;;;;MAKE;IACI,YAAY,CAAC,cAAsB,EAAE,IAAY;;YACrD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,YAAY,EACxB;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;gBACD,MAAM,EAAE;oBACN,MAAM,EAAE,IAAI;iBACb;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,WAAW,CAAC,cAAsB;;YACtC,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,WAAW,EACvB;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAC;QACJ,CAAC;KAAA;CACF;AA9CD,+BA8CC"} \ No newline at end of file diff --git a/lib/index.d.ts b/lib/index.d.ts index 5058a5c..ea10d09 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,5 +1,5 @@ -import Scalekit from "./scalekit"; -export { Scalekit }; -export default Scalekit; +import ScalekitClient from "./scalekit"; +export { ScalekitClient }; +export default ScalekitClient; export * from "./types/scalekit"; export * from "./types/user"; diff --git a/lib/index.js b/lib/index.js index 299c208..7d5bba5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -17,9 +17,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.Scalekit = void 0; +exports.ScalekitClient = void 0; const scalekit_1 = __importDefault(require("./scalekit")); -exports.Scalekit = scalekit_1.default; +exports.ScalekitClient = scalekit_1.default; exports.default = scalekit_1.default; __exportStar(require("./types/scalekit"), exports); __exportStar(require("./types/user"), exports); diff --git a/lib/index.js.map b/lib/index.js.map index 1556123..cc2f9d6 100644 --- a/lib/index.js.map +++ b/lib/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0DAAkC;AAEzB,mBAFF,kBAAQ,CAEE;AACjB,kBAAe,kBAAQ,CAAC;AAExB,mDAAiC;AACjC,+CAA6B"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0DAAwC;AAE/B,yBAFF,kBAAc,CAEE;AACvB,kBAAe,kBAAc,CAAC;AAE9B,mDAAiC;AACjC,+CAA6B"} \ No newline at end of file diff --git a/lib/organization.d.ts b/lib/organization.d.ts index 548e1cd..c3d601d 100644 --- a/lib/organization.d.ts +++ b/lib/organization.d.ts @@ -1,4 +1,4 @@ -import { PartialMessage } from '@bufbuild/protobuf'; +import { Empty, PartialMessage } from '@bufbuild/protobuf'; import GrpcConnect from './connect'; import CoreClient from './core'; import { CreateOrganizationResponse, GetOrganizationResponse, Link, ListOrganizationsResponse, UpdateOrganization, UpdateOrganizationResponse } from './pkg/grpc/scalekit/v1/organizations/organizations_pb'; @@ -9,13 +9,12 @@ export default class OrganizationClient { constructor(grpcConncet: GrpcConnect, coreClient: CoreClient); /** * Create an organization with the given name. Optionally, you can provide an external id. + * @param {string} name The organization name * @param {object} options The options to create an organization - * @param {string} options.name The organization name * @param {string} options.externalId The external id * @returns {Promise} The created organization */ - createOrganization(options: { - name: string; + createOrganization(name: string, options?: { externalId?: string; }): Promise; /** @@ -61,4 +60,17 @@ export default class OrganizationClient { * @returns {Promise} The admin portal link object with expiration time and location */ generatePortalLink(organizationId: string): Promise; + /** + * Get admin portal link for an organization + * @param organizationId The organization id + * @returns {Promise} The admin portal link object with expiration time and location + */ + getPortalLinks(organizationId: string): Promise; + /** + * Delete admin portal link for an organization + * @param organizationId The organization id + * @param linkId The link id + * @returns {Promise} Returns nothing + */ + deletePortalLink(organizationId: string, linkId: string): Promise; } diff --git a/lib/organization.js b/lib/organization.js index 13f2089..f6e8c3d 100644 --- a/lib/organization.js +++ b/lib/organization.js @@ -18,19 +18,17 @@ class OrganizationClient { } /** * Create an organization with the given name. Optionally, you can provide an external id. + * @param {string} name The organization name * @param {object} options The options to create an organization - * @param {string} options.name The organization name * @param {string} options.externalId The external id * @returns {Promise} The created organization */ - createOrganization(options) { + createOrganization(name, options) { return __awaiter(this, void 0, void 0, function* () { - const { name, externalId } = options; return this.coreClient.connectExec(this.client.createOrganization, { - organization: { - displayName: name, - externalId: externalId - } + organization: Object.assign({ displayName: name }, ((options === null || options === void 0 ? void 0 : options.externalId) && { + externalId: options.externalId + })) }); }); } @@ -110,6 +108,33 @@ class OrganizationClient { return response.link; }); } + /** + * Get admin portal link for an organization + * @param organizationId The organization id + * @returns {Promise} The admin portal link object with expiration time and location + */ + getPortalLinks(organizationId) { + return __awaiter(this, void 0, void 0, function* () { + const response = yield this.coreClient.connectExec(this.client.getPortalLinks, { + id: organizationId + }); + return response.links; + }); + } + /** + * Delete admin portal link for an organization + * @param organizationId The organization id + * @param linkId The link id + * @returns {Promise} Returns nothing + */ + deletePortalLink(organizationId, linkId) { + return __awaiter(this, void 0, void 0, function* () { + return this.coreClient.connectExec(this.client.deletePortalLink, { + id: organizationId, + linkId + }); + }); + } } exports.default = OrganizationClient; //# sourceMappingURL=organization.js.map \ No newline at end of file diff --git a/lib/organization.js.map b/lib/organization.js.map index 382e0ac..b872fc2 100644 --- a/lib/organization.js.map +++ b/lib/organization.js.map @@ -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,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gBACtD,YAAY;aACb,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,kBAAkB,CAAC,cAAsB;;YAC7C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAChD,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAC9B;gBACE,EAAE,EAAE,cAAc;aACnB,CACF,CAAA;YACD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YAED,OAAO,QAAQ,CAAC,IAAI,CAAA;QACtB,CAAC;KAAA;CACF;AAxHD,qCAwHC"} \ No newline at end of file +{"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,IAAY,EAAE,OAAiC;;YACtE,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAC9B;gBACE,YAAY,kBACV,WAAW,EAAE,IAAI,IACd,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,KAAI;oBACzB,UAAU,EAAE,OAAO,CAAC,UAAU;iBAC/B,CAAC,CACH;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,OAA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,CAAA;YACD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YAED,OAAO,QAAQ,CAAC,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;AAzJD,qCAyJC"} \ No newline at end of file diff --git a/lib/scalekit.d.ts b/lib/scalekit.d.ts index b64bd47..d0cf6e7 100644 --- a/lib/scalekit.d.ts +++ b/lib/scalekit.d.ts @@ -1,18 +1,17 @@ import ConnectionClient from './connection'; import DomainClient from './domain'; import OrganizationClient from './organization'; -import { AuthorizationUrlOptions, CodeAuthenticationOptions } from './types/scalekit'; -import { User } from './types/user'; +import { AuthorizationUrlOptions, AuthenticationOptions, AuthenticationResponse } from './types/scalekit'; /** * To initiate scalekit * @param {string} envUrl The environment url * @param {string} clientId The client id * @param {string} clientSecret The client secret - * @returns {Scalekit} Returns the scalekit instance + * @returns {ScalekitClient} Returns the scalekit instance * @example * const scalekit = new Scalekit(envUrl, clientId, clientSecret); */ -export default class Scalekit { +export default class ScalekitClient { private readonly coreClient; private readonly grpcConnect; readonly organization: OrganizationClient; @@ -30,6 +29,8 @@ export default class Scalekit { * @param {string} options.domainHint Domain hint parameter * @param {string} options.connectionId Connection id parameter * @param {string} options.organizationId Organization id parameter + * @param {string} options.codeChallenge Code challenge parameter in case of PKCE + * @param {string} options.codeChallengeMethod Code challenge method parameter in case of PKCE * * @example * const scalekit = new Scalekit(envUrl, clientId, clientSecret); @@ -39,17 +40,13 @@ export default class Scalekit { getAuthorizationUrl(redirectUri: string, options?: AuthorizationUrlOptions): string; /** * Authenticate with the code - * @param {CodeAuthenticationOptions} options Code authentication options - * @param {string} options.code Code - * @param {string} options.redirectUri Redirect uri - * @param {string} options.codeVerifier Code verifier - * @returns {Promise<{ user: Partial, idToken: string, accessToken: string }>} Returns user, id token and access token + * @param {string} code Code + * @param {string} redirectUri Redirect uri + * @param {AuthenticationOptions} options Code authentication options + * @param {string} options.codeVerifier Code verifier in case of PKCE + * @returns {Promise} Returns user, id token and access token */ - authenticateWithCode(options: CodeAuthenticationOptions): Promise<{ - user: Partial; - idToken: string; - accessToken: string; - }>; + authenticateWithCode(code: string, redirectUri: string, options?: AuthenticationOptions): Promise; /** * Validates the access token. * diff --git a/lib/scalekit.js b/lib/scalekit.js index 1599372..7566575 100644 --- a/lib/scalekit.js +++ b/lib/scalekit.js @@ -50,11 +50,11 @@ const authorizeEndpoint = "oauth/authorize"; * @param {string} envUrl The environment url * @param {string} clientId The client id * @param {string} clientSecret The client secret - * @returns {Scalekit} Returns the scalekit instance + * @returns {ScalekitClient} Returns the scalekit instance * @example * const scalekit = new Scalekit(envUrl, clientId, clientSecret); */ -class Scalekit { +class ScalekitClient { constructor(envUrl, clientId, clientSecret) { this.coreClient = new core_1.default(envUrl, clientId, clientSecret); this.grpcConnect = new connect_1.default(this.coreClient); @@ -73,6 +73,8 @@ class Scalekit { * @param {string} options.domainHint Domain hint parameter * @param {string} options.connectionId Connection id parameter * @param {string} options.organizationId Organization id parameter + * @param {string} options.codeChallenge Code challenge parameter in case of PKCE + * @param {string} options.codeChallengeMethod Code challenge method parameter in case of PKCE * * @example * const scalekit = new Scalekit(envUrl, clientId, clientSecret); @@ -85,20 +87,20 @@ class Scalekit { scopes: ['openid', 'profile'] }; options = Object.assign(Object.assign({}, defaultOptions), options); - 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 }))); + 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 }))); return `${this.coreClient.envUrl}/${authorizeEndpoint}?${qs}`; } /** * Authenticate with the code - * @param {CodeAuthenticationOptions} options Code authentication options - * @param {string} options.code Code - * @param {string} options.redirectUri Redirect uri - * @param {string} options.codeVerifier Code verifier - * @returns {Promise<{ user: Partial, idToken: string, accessToken: string }>} Returns user, id token and access token + * @param {string} code Code + * @param {string} redirectUri Redirect uri + * @param {AuthenticationOptions} options Code authentication options + * @param {string} options.codeVerifier Code verifier in case of PKCE + * @returns {Promise} Returns user, id token and access token */ - authenticateWithCode(options) { + authenticateWithCode(code, redirectUri, options) { return __awaiter(this, void 0, void 0, function* () { - 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 })))); + 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 })))); const { id_token, access_token } = res.data; const claims = jose.decodeJwt(id_token); const user = {}; @@ -136,5 +138,5 @@ class Scalekit { }); } } -exports.default = Scalekit; +exports.default = ScalekitClient; //# sourceMappingURL=scalekit.js.map \ No newline at end of file diff --git a/lib/scalekit.js.map b/lib/scalekit.js.map index a233a80..6723c82 100644 --- a/lib/scalekit.js.map +++ b/lib/scalekit.js.map @@ -1 +1 @@ -{"version":3,"file":"scalekit.js","sourceRoot":"","sources":["../src/scalekit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAA6B;AAC7B,wDAAoC;AACpC,8DAA4C;AAC5C,2CAAyD;AACzD,kDAAgC;AAChC,sDAAoC;AACpC,kEAAgD;AAChD,+CAAiG;AAGjG,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAE5C;;;;;;;;EAQE;AACF,MAAqB,QAAQ;IAM3B,YACE,MAAc,EACd,QAAgB,EAChB,YAAoB;QAEpB,IAAI,CAAC,UAAU,GAAG,IAAI,cAAU,CAC9B,MAAM,EACN,QAAQ,EACR,YAAY,CACb,CAAC;QACF,IAAI,CAAC,WAAW,GAAG,IAAI,iBAAW,CAChC,IAAI,CAAC,UAAU,CAChB,CAAC;QAEF,IAAI,CAAC,YAAY,GAAG,IAAI,sBAAkB,CACxC,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,CAChB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BAAiB,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;AAlID,2BAkIC"} \ No newline at end of file +{"version":3,"file":"scalekit.js","sourceRoot":"","sources":["../src/scalekit.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,4CAA6B;AAC7B,wDAAoC;AACpC,8DAA4C;AAC5C,2CAAyD;AACzD,kDAAgC;AAChC,sDAAoC;AACpC,kEAAgD;AAChD,+CAAqH;AAGrH,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAE5C;;;;;;;;EAQE;AACF,MAAqB,cAAc;IAMjC,YACE,MAAc,EACd,QAAgB,EAChB,YAAoB;QAEpB,IAAI,CAAC,UAAU,GAAG,IAAI,cAAU,CAC9B,MAAM,EACN,QAAQ,EACR,YAAY,CACb,CAAC;QACF,IAAI,CAAC,WAAW,GAAG,IAAI,iBAAW,CAChC,IAAI,CAAC,UAAU,CAChB,CAAC;QAEF,IAAI,CAAC,YAAY,GAAG,IAAI,sBAAkB,CACxC,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,CAChB,CAAC;QACF,IAAI,CAAC,UAAU,GAAG,IAAI,oBAAgB,CACpC,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,CAChB,CAAC;QACF,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAY,CAC5B,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,UAAU,CAChB,CAAA;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,mBAAmB,CACjB,WAAmB,E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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;AA1ID,iCA0IC"} \ No newline at end of file diff --git a/lib/types/scalekit.d.ts b/lib/types/scalekit.d.ts index d487e71..25c2d2c 100644 --- a/lib/types/scalekit.d.ts +++ b/lib/types/scalekit.d.ts @@ -1,3 +1,4 @@ +import { User } from './user'; export declare enum GrantType { AuthorizationCode = "authorization_code", RefreshToken = "refresh_token", @@ -11,16 +12,14 @@ export type AuthorizationUrlOptions = { nonce?: string; domainHint?: string; loginHint?: string; + codeChallenge?: string; + codeChallengeMethod?: string; }; -export type CodeAuthenticationOptions = { - code: string; - redirectUri: string; +export type AuthenticationOptions = { codeVerifier?: string; }; -export type RefreshTokenAuthenticationOptions = { - code: string; - redirectUri: string; -}; -export type AuthenticationOptions = { - refreshToken: string; +export type AuthenticationResponse = { + user: Partial; + idToken: string; + accessToken: string; }; diff --git a/lib/types/scalekit.js.map b/lib/types/scalekit.js.map index 30b39be..888f314 100644 --- a/lib/types/scalekit.js.map +++ b/lib/types/scalekit.js.map @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/src/connection.ts b/src/connection.ts index d1e2891..7d9b6fd 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -2,7 +2,7 @@ import { PromiseClient } from '@connectrpc/connect'; import GrpcConnect from './connect'; import CoreClient from './core'; import { ConnectionService } from './pkg/grpc/scalekit/v1/connections/connections_connect'; -import { GetConnectionResponse, ListConnectionsResponse } from './pkg/grpc/scalekit/v1/connections/connections_pb'; +import { GetConnectionResponse, ToggleConnectionResponse, ListConnectionsResponse } from './pkg/grpc/scalekit/v1/connections/connections_pb'; export default class ConnectionClient { private client: PromiseClient; @@ -65,5 +65,43 @@ export default class ConnectionClient { }, ) } + + /** + * Enable a connection by id and organization id + * @param id The connection id + * @param organizationId The organization id + * @returns {Promise} The connection enable response + */ + async enableConnection(id: string, organizationId: string): Promise { + return this.coreClient.connectExec( + this.client.enableConnection, + { + id, + identities: { + case: 'organizationId', + value: organizationId + } + }, + ) + } + + /** + * Disable a connection by id and organization id + * @param id The connection id + * @param organizationId The organization id + * @returns {Promise} The connection enable response + */ + async disableConnection(id: string, organizationId: string): Promise { + return this.coreClient.connectExec( + this.client.disableConnection, + { + id, + identities: { + case: 'organizationId', + value: organizationId + } + }, + ) + } } diff --git a/src/domain.ts b/src/domain.ts index d789e13..eb37da8 100644 --- a/src/domain.ts +++ b/src/domain.ts @@ -34,27 +34,6 @@ export default class DomainClient { ) } - /** - * Get a domain by id - * @param {object} options The options to get a domain - * @param {string} options.id The domain id - * @param {string} options.organizationId The organization id - * @returns {Promise} The domain - */ - async getDomain(options: { id: string, organizationId: string }): Promise { - const { id, organizationId } = options; - return this.coreClient.connectExec( - this.client.getDomain, - { - id, - identities: { - case: 'organizationId', - value: organizationId - } - } - ) - } - /** * List domains for an organization * @param organizationId The organization id diff --git a/src/index.ts b/src/index.ts index 92d415b..14ba65f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ -import Scalekit from "./scalekit"; +import ScalekitClient from "./scalekit"; -export { Scalekit }; -export default Scalekit; +export { ScalekitClient }; +export default ScalekitClient; export * from "./types/scalekit"; export * from "./types/user"; \ No newline at end of file diff --git a/src/organization.ts b/src/organization.ts index 81057ed..3deec89 100644 --- a/src/organization.ts +++ b/src/organization.ts @@ -1,4 +1,4 @@ -import { PartialMessage } from '@bufbuild/protobuf'; +import { Empty, PartialMessage } from '@bufbuild/protobuf'; import { PromiseClient } from '@connectrpc/connect'; import GrpcConnect from './connect'; import CoreClient from './core'; @@ -126,5 +126,37 @@ export default class OrganizationClient { return response.link } + + /** + * Get admin portal link for an organization + * @param organizationId The organization id + * @returns {Promise} The admin portal link object with expiration time and location + */ + async getPortalLinks(organizationId: string): Promise { + const response = await this.coreClient.connectExec( + this.client.getPortalLinks, + { + id: organizationId + }, + ) + + return response.links + } + + /** + * Delete admin portal link for an organization + * @param organizationId The organization id + * @param linkId The link id + * @returns {Promise} Returns nothing + */ + async deletePortalLink(organizationId: string, linkId: string): Promise { + return this.coreClient.connectExec( + this.client.deletePortalLink, + { + id: organizationId, + linkId + }, + ) + } } diff --git a/src/scalekit.ts b/src/scalekit.ts index de3d732..6cb9816 100644 --- a/src/scalekit.ts +++ b/src/scalekit.ts @@ -16,11 +16,11 @@ const authorizeEndpoint = "oauth/authorize"; * @param {string} envUrl The environment url * @param {string} clientId The client id * @param {string} clientSecret The client secret - * @returns {Scalekit} Returns the scalekit instance + * @returns {ScalekitClient} Returns the scalekit instance * @example * const scalekit = new Scalekit(envUrl, clientId, clientSecret); */ -export default class Scalekit { +export default class ScalekitClient { private readonly coreClient: CoreClient; private readonly grpcConnect: GrpcConnect; readonly organization: OrganizationClient; From 3d3862fa08cd2d82585a2ed05fec555461f45d6e Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Thu, 6 Jun 2024 10:40:19 +0530 Subject: [PATCH 07/19] refactor connection apis and add email scope --- src/connection.ts | 12 ++++++------ src/organization.ts | 14 ++++++++++++++ src/scalekit.ts | 2 +- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/connection.ts b/src/connection.ts index 7d9b6fd..613266b 100644 --- a/src/connection.ts +++ b/src/connection.ts @@ -15,11 +15,11 @@ export default class ConnectionClient { /** * Get a connection by id and organization id - * @param id The connection id * @param organizationId The organization id + * @param id The connection id * @returns {Promise} The connection */ - async getConnection(id: string, organizationId: string): Promise { + async getConnection(organizationId: string, id: string): Promise { return this.coreClient.connectExec( this.client.getConnection, { @@ -68,11 +68,11 @@ export default class ConnectionClient { /** * Enable a connection by id and organization id - * @param id The connection id * @param organizationId The organization id + * @param id The connection id * @returns {Promise} The connection enable response */ - async enableConnection(id: string, organizationId: string): Promise { + async enableConnection(organizationId: string, id: string): Promise { return this.coreClient.connectExec( this.client.enableConnection, { @@ -87,11 +87,11 @@ export default class ConnectionClient { /** * Disable a connection by id and organization id - * @param id The connection id * @param organizationId The organization id + * @param id The connection id * @returns {Promise} The connection enable response */ - async disableConnection(id: string, organizationId: string): Promise { + async disableConnection(organizationId: string, id: string): Promise { return this.coreClient.connectExec( this.client.disableConnection, { diff --git a/src/organization.ts b/src/organization.ts index 3deec89..c042ecf 100644 --- a/src/organization.ts +++ b/src/organization.ts @@ -108,6 +108,20 @@ export default class OrganizationClient { ) } + /** + * Delete an organization by id + * @param {string} organizationId The organization id + * @returns {Promise} Returns nothing + */ + async deleteOrganization(organizationId: string): Promise { + return this.coreClient.connectExec( + this.client.deleteOrganization, + { + identities: { case: "id", value: organizationId, }, + }, + ) + } + /** * Generate admin portal link for an organization * @param organizationId The organization id diff --git a/src/scalekit.ts b/src/scalekit.ts index 6cb9816..23ca4c3 100644 --- a/src/scalekit.ts +++ b/src/scalekit.ts @@ -78,7 +78,7 @@ export default class ScalekitClient { options?: AuthorizationUrlOptions ): string { const defaultOptions: AuthorizationUrlOptions = { - scopes: ['openid', 'profile'] + scopes: ['openid', 'profile', 'email'] } options = { ...defaultOptions, From 60a4b31ff4775d755c2f05a9f186eda8e54ad9cf Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Thu, 13 Jun 2024 14:28:52 +0530 Subject: [PATCH 08/19] typing fixes --- src/constants/user.ts | 2 +- src/core.ts | 7 ++++--- src/index.ts | 2 +- src/scalekit.ts | 9 +++++---- src/types/{user.ts => auth.ts} | 6 ++++++ src/types/scalekit.ts | 5 +++-- 6 files changed, 20 insertions(+), 11 deletions(-) rename src/types/{user.ts => auth.ts} (93%) diff --git a/src/constants/user.ts b/src/constants/user.ts index e713f5c..214c2c1 100644 --- a/src/constants/user.ts +++ b/src/constants/user.ts @@ -1,4 +1,4 @@ -import type { IdTokenClaim, User } from '../types/user'; +import type { IdTokenClaim, User } from '../types/auth'; export const IdTokenClaimToUserMap: { [k in keyof IdTokenClaim]: keyof User } = { "sub": "id", diff --git a/src/core.ts b/src/core.ts index fe8a65d..3643edc 100644 --- a/src/core.ts +++ b/src/core.ts @@ -5,6 +5,7 @@ import os from "os"; import QueryString from "qs"; import { GrantType } from './types/scalekit'; import { ErrorInfo } from './pkg/grpc/scalekit/v1/errdetails/errdetails_pb'; +import { TokenResponse } from './types/auth'; const tokenEndpoint = "oauth/token"; const jwksEndpoint = "keys"; @@ -46,10 +47,10 @@ export default class CoreClient { /** * Authenticate with the code * @param {string} data Data to authenticate - * @returns {Promise>} Returns access token and id token + * @returns {Promise>} Returns access token and id token */ - async authenticate(data: string): Promise> { - return this.axios.post<{ access_token: string, id_token: string }>( + async authenticate(data: string): Promise> { + return this.axios.post( tokenEndpoint, data, { diff --git a/src/index.ts b/src/index.ts index 14ba65f..8f88501 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,4 +4,4 @@ export { ScalekitClient }; export default ScalekitClient; export * from "./types/scalekit"; -export * from "./types/user"; \ No newline at end of file +export * from "./types/auth"; \ No newline at end of file diff --git a/src/scalekit.ts b/src/scalekit.ts index 23ca4c3..60184f0 100644 --- a/src/scalekit.ts +++ b/src/scalekit.ts @@ -7,7 +7,7 @@ import CoreClient from './core'; import DomainClient from './domain'; import OrganizationClient from './organization'; import { AuthorizationUrlOptions, AuthenticationOptions, GrantType, AuthenticationResponse } from './types/scalekit'; -import { IdTokenClaim, User } from './types/user'; +import { IdTokenClaim, User } from './types/auth'; const authorizeEndpoint = "oauth/authorize"; @@ -124,9 +124,9 @@ export default class ScalekitClient { client_secret: this.coreClient.clientSecret, ...(options?.codeVerifier && { code_verifier: options.codeVerifier }) })) - const { id_token, access_token } = res.data; + const { id_token, access_token, expires_in } = res.data; const claims = jose.decodeJwt(id_token); - const user: Partial = {}; + const user = {}; for (const [k, v] of Object.entries(claims)) { if (IdTokenClaimToUserMap[k]) { user[IdTokenClaimToUserMap[k]] = v; @@ -136,7 +136,8 @@ export default class ScalekitClient { return { user, idToken: id_token, - accessToken: access_token + accessToken: access_token, + expiresIn: expires_in } } diff --git a/src/types/user.ts b/src/types/auth.ts similarity index 93% rename from src/types/user.ts rename to src/types/auth.ts index 692aba0..0306155 100644 --- a/src/types/user.ts +++ b/src/types/auth.ts @@ -56,4 +56,10 @@ export type IdTokenClaim = { updated_at: string | undefined; identities: IdTokenClaimIdentity[]; metadata: string | undefined; +} + +export type TokenResponse = { + access_token: string; + id_token: string; + expires_in: number; } \ No newline at end of file diff --git a/src/types/scalekit.ts b/src/types/scalekit.ts index 9a7bda1..3aeeebf 100644 --- a/src/types/scalekit.ts +++ b/src/types/scalekit.ts @@ -1,4 +1,4 @@ -import { User } from './user'; +import { User } from './auth'; export enum GrantType { AuthorizationCode = 'authorization_code', @@ -23,7 +23,8 @@ export type AuthenticationOptions = { } export type AuthenticationResponse = { - user: Partial; + user: User; idToken: string; accessToken: string; + expiresIn: number; } \ No newline at end of file From 4288062d99c35d06ee0cd656ba830732d9edb7f8 Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Thu, 13 Jun 2024 14:29:07 +0530 Subject: [PATCH 09/19] update readme with examples --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 914cfcd..1623381 100644 --- a/README.md +++ b/README.md @@ -32,9 +32,9 @@ pnpm add @scalekit-sdk/node ## Usage ```javascript -import { Scalekit } from "@scalekit-sdk/node"; +import { ScalekitClient } from "@scalekit-sdk/node"; -const sc = new Scalekit( +const sc = new ScalekitClient( process.env.SCALEKIT_ENV_URL!, process.env.SCALEKIT_CLIENT_ID!, process.env.SCALEKIT_CLIENT_SECRET! @@ -48,9 +48,64 @@ const authUrl = sc.getAuthorizationUrl("https://acme-corp.com/redirect-uri", { ``` +## Examples - SSO with Express.js + +```javascript +import express from "express"; +import { ScalekitClient } from "@scalekit-sdk/node"; + +const app = express(); + +const sc = new ScalekitClient( + process.env.SCALEKIT_ENV_URL!, + process.env.SCALEKIT_CLIENT_ID!, + process.env.SCALEKIT_CLIENT_SECRET! +); + +const redirectUri = `${process.env.HOST}/auth/callback`; + +// Get the authorization URL and redirect the user to the IdP login page +app.get("/auth/login", (req, res) => { + const authUrl = sc.getAuthorizationUrl( + redirectUri, + { + state: "state", + connectionId: "connection_id", + } + ); + + res.redirect(authUrl); +}); + +// Handle the callback from the Scalekit +app.get("/auth/callback", async (req, res) => { + const code = req.query.code as string; + const authResp = await sc.authenticateWithCode(code, redirectUri); + res.cookie("access_token", authResp.accessToken); + res.json(token); +}); + +app.listen(3000, () => { + console.log("Server is running on port 3000"); +}); +``` + +## Sample Apps + +- [Express.js](https://github.com/scalekit-inc/scalekit-express-example.git) +- [Next.js](https://github.com/scalekit-inc/scalekit-nextjs-example.git) + ## API Reference -See the [Scalekit API docs](https://docs.scalekit.com) for more information about the API and authentication. + +See the [Scalekit API docs](https://docs.scalekit.com/apis) for more information about the API and authentication. + +## More Information + +- [SSO Quickstart Guide](https://docs.scalekit.com) +- [SSO Basics](https://docs.scalekit.com/best-practices/single-sign-on) +- [ID Token](https://docs.scalekit.com/best-practices/idtoken-claims) ## License + This project is licensed under the **MIT license**. -See the [LICENSE](LICENSE) file for more information. \ No newline at end of file +See the [LICENSE](LICENSE) file for more information. From eb9f8f0c769ee393be63703bf948b147313701c6 Mon Sep 17 00:00:00 2001 From: Ravi Madabhushi Date: Thu, 13 Jun 2024 15:14:26 +0530 Subject: [PATCH 10/19] Update README.md --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1623381..755bc33 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

+

@@ -6,20 +6,21 @@

-

- Official Scalekit Node SDK -

-Scalekit helps you in shipping enterprise auth in days. - -This Node SDK is a wrapper around Scalekit's REST API to help you integrate Scalekit with your Node.js applications. +# Official Scalekit Node SDK +Scalekit is an Enterprise Authentication Platform purpose built for B2B applications. This Node SDK helps implement Enterprise Capabilities like Single Sign-on via SAML or OIDC in your Node.js applications within a few hours. +
+📚 Documentation - 🚀 Getting started - 💻 API reference +
+
## Getting Started 1. [Sign up](https://scalekit.com) for a Scalekit account. 2. Get your ```env_url```, ```client_id``` and ```client_secret``` from the Scalekit dashboard. ## Installation +Install Scalekit SDK using your preferred package manager. ```sh npm install @scalekit-sdk/node @@ -30,7 +31,7 @@ pnpm add @scalekit-sdk/node ``` ## Usage - +Initialize the Scalekit client using the appropriate credentials. Refer code sample below. ```javascript import { ScalekitClient } from "@scalekit-sdk/node"; @@ -49,7 +50,7 @@ const authUrl = sc.getAuthorizationUrl("https://acme-corp.com/redirect-uri", { ``` ## Examples - SSO with Express.js - +Below is a simple code sample that showcases how to implement Single Sign-on using Scalekit SDK ```javascript import express from "express"; import { ScalekitClient } from "@scalekit-sdk/node"; @@ -91,7 +92,7 @@ app.listen(3000, () => { ``` ## Sample Apps - +Fully functional sample applications written using some popular web application frameworks and Scalekit SDK. Feel free to clone the repo and run them locally. - [Express.js](https://github.com/scalekit-inc/scalekit-express-example.git) - [Next.js](https://github.com/scalekit-inc/scalekit-nextjs-example.git) @@ -101,9 +102,8 @@ See the [Scalekit API docs](https://docs.scalekit.com/apis) for more information ## More Information -- [SSO Quickstart Guide](https://docs.scalekit.com) -- [SSO Basics](https://docs.scalekit.com/best-practices/single-sign-on) -- [ID Token](https://docs.scalekit.com/best-practices/idtoken-claims) +- Quickstart Guide to implement Single Sign-on in your application: [SSO Quickstart Guide](https://docs.scalekit.com) +- Understand Single Sign-on basics: [SSO Basics](https://docs.scalekit.com/best-practices/single-sign-on) ## License From e314d7a26d420ec76f9f8b06b2fbf980b55b2dc2 Mon Sep 17 00:00:00 2001 From: Ravi Madabhushi Date: Thu, 13 Jun 2024 15:15:45 +0530 Subject: [PATCH 11/19] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 755bc33..303cd62 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ 📚 Documentation - 🚀 Getting started - 💻 API reference
+ ## Getting Started 1. [Sign up](https://scalekit.com) for a Scalekit account. From 95f0b7f42afe300a031387e7fafdc3a55341d206 Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Thu, 13 Jun 2024 15:24:04 +0530 Subject: [PATCH 12/19] update readme --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 303cd62..034562b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

+

@@ -7,15 +7,15 @@

-# Official Scalekit Node SDK -Scalekit is an Enterprise Authentication Platform purpose built for B2B applications. This Node SDK helps implement Enterprise Capabilities like Single Sign-on via SAML or OIDC in your Node.js applications within a few hours. +# Official Node.js SDK +Scalekit is an Enterprise Authentication Platform purpose built for B2B applications. This Node.js SDK helps implement Enterprise Capabilities like Single Sign-on via SAML or OIDC in your Node.js applications within a few hours.
📚 Documentation - 🚀 Getting started - 💻 API reference

-## Getting Started +## Pre-requisites 1. [Sign up](https://scalekit.com) for a Scalekit account. 2. Get your ```env_url```, ```client_id``` and ```client_secret``` from the Scalekit dashboard. @@ -99,7 +99,7 @@ Fully functional sample applications written using some popular web application ## API Reference -See the [Scalekit API docs](https://docs.scalekit.com/apis) for more information about the API and authentication. +Refer to our [API reference docs](https://docs.scalekit.com/apis) for detailed information about all our API endpoints and their usage. ## More Information From 0b965f458065f77d611b3df5d994d06cb5dd0700 Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Thu, 13 Jun 2024 15:26:26 +0530 Subject: [PATCH 13/19] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 034562b..cc3cdfb 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Scalekit is an Enterprise Authentication Platform purpose built for B2B applications. This Node.js SDK helps implement Enterprise Capabilities like Single Sign-on via SAML or OIDC in your Node.js applications within a few hours.
-📚 Documentation - 🚀 Getting started - 💻 API reference +📚 Documentation - 🚀 Quick-start Guide - 💻 API Reference

From 5579b58f370db140b13d3ee0e22b5bbd4aa903dd Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Thu, 13 Jun 2024 16:23:43 +0530 Subject: [PATCH 14/19] fix link --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cc3cdfb..273a28a 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ 2. Get your ```env_url```, ```client_id``` and ```client_secret``` from the Scalekit dashboard. ## Installation + Install Scalekit SDK using your preferred package manager. ```sh @@ -32,7 +33,9 @@ pnpm add @scalekit-sdk/node ``` ## Usage + Initialize the Scalekit client using the appropriate credentials. Refer code sample below. + ```javascript import { ScalekitClient } from "@scalekit-sdk/node"; @@ -51,7 +54,9 @@ const authUrl = sc.getAuthorizationUrl("https://acme-corp.com/redirect-uri", { ``` ## Examples - SSO with Express.js + Below is a simple code sample that showcases how to implement Single Sign-on using Scalekit SDK + ```javascript import express from "express"; import { ScalekitClient } from "@scalekit-sdk/node"; @@ -93,9 +98,11 @@ app.listen(3000, () => { ``` ## Sample Apps + Fully functional sample applications written using some popular web application frameworks and Scalekit SDK. Feel free to clone the repo and run them locally. + - [Express.js](https://github.com/scalekit-inc/scalekit-express-example.git) -- [Next.js](https://github.com/scalekit-inc/scalekit-nextjs-example.git) +- [Next.js](https://github.com/scalekit-inc/scalekit-next-example.git) ## API Reference From 498f7c66c0195783f5d0a81e06dca25284bd129e Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Thu, 13 Jun 2024 16:28:01 +0530 Subject: [PATCH 15/19] update next repo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 273a28a..15e4fda 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ app.listen(3000, () => { Fully functional sample applications written using some popular web application frameworks and Scalekit SDK. Feel free to clone the repo and run them locally. - [Express.js](https://github.com/scalekit-inc/scalekit-express-example.git) -- [Next.js](https://github.com/scalekit-inc/scalekit-next-example.git) +- [Next.js](https://github.com/scalekit-inc/scalekit-nextjs-example.git) ## API Reference From 6b7f19c5bb33f42737fd3040aa1fd0834b6440bd Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Mon, 17 Jun 2024 10:56:11 +0530 Subject: [PATCH 16/19] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 15e4fda..8d362ef 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ app.listen(3000, () => { }); ``` -## Sample Apps +## Example Apps Fully functional sample applications written using some popular web application frameworks and Scalekit SDK. Feel free to clone the repo and run them locally. From 7f6fd7990ec3b5ab38896f404cc9fd01e78ff448 Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Mon, 17 Jun 2024 11:49:09 +0530 Subject: [PATCH 17/19] add dependabot --- .github/dependabot.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..3629ba8 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "weekly" + time: "06:00" + timezone: "Asia/Kolkata" + reviewers: + - "dhawani" From bc6a4d0a6cd83eae765712e61bd2eaa64a041b5f Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Mon, 24 Jun 2024 11:56:08 +0530 Subject: [PATCH 18/19] update readme and move headers to constants --- README.md | 4 ++-- src/connect.ts | 10 +++++----- src/core.ts | 17 ++++++++++++----- src/organization.ts | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 8d362ef..1234cc2 100644 --- a/README.md +++ b/README.md @@ -84,12 +84,12 @@ app.get("/auth/login", (req, res) => { res.redirect(authUrl); }); -// Handle the callback from the Scalekit +// Handle the callback from Scalekit app.get("/auth/callback", async (req, res) => { const code = req.query.code as string; const authResp = await sc.authenticateWithCode(code, redirectUri); res.cookie("access_token", authResp.accessToken); - res.json(token); + res.json(authResp.accessToken); }); app.listen(3000, () => { diff --git a/src/connect.ts b/src/connect.ts index 7fc1b8f..b1db374 100644 --- a/src/connect.ts +++ b/src/connect.ts @@ -1,7 +1,7 @@ import { ServiceType } from '@bufbuild/protobuf'; import { PromiseClient, Transport, createPromiseClient } from '@connectrpc/connect'; import { createGrpcTransport } from '@connectrpc/connect-node'; -import CoreClient from './core'; +import CoreClient, { headers } from './core'; export default class GrpcConnect { private transport: Transport; @@ -14,11 +14,11 @@ export default class GrpcConnect { interceptors: [ (next) => { return (req) => { - req.header.set("User-Agent", this.coreClient.userAgent) - req.header.set("X-Sdk-Version", this.coreClient.sdkVersion) - req.header.set("X-Api-Version", this.coreClient.apiVersion) + req.header.set(headers['user-agent'], this.coreClient.userAgent) + req.header.set(headers['x-sdk-version'], this.coreClient.sdkVersion) + req.header.set(headers['x-api-version'], this.coreClient.apiVersion) if (this.coreClient.accessToken) { - req.header.set("Authorization", `Bearer ${this.coreClient.accessToken}`) + req.header.set(headers.authorization, `Bearer ${this.coreClient.accessToken}`) } return next(req) } diff --git a/src/core.ts b/src/core.ts index 3643edc..b92bfb4 100644 --- a/src/core.ts +++ b/src/core.ts @@ -7,6 +7,13 @@ import { GrantType } from './types/scalekit'; import { ErrorInfo } from './pkg/grpc/scalekit/v1/errdetails/errdetails_pb'; import { TokenResponse } from './types/auth'; +export const headers = { + "user-agent": "user-agent", + "x-sdk-version": "x-sdk-version", + "x-api-version": "x-api-version", + "authorization": "authorization" +} + const tokenEndpoint = "oauth/token"; const jwksEndpoint = "keys"; export default class CoreClient { @@ -23,11 +30,11 @@ export default class CoreClient { ) { this.axios = axios.create({ baseURL: envUrl }); this.axios.interceptors.request.use((config) => { - config.headers["User-Agent"] = this.userAgent; - config.headers["X-Sdk-Version"] = this.sdkVersion; - config.headers["X-Api-Version"] = this.apiVersion; + config.headers[headers['user-agent']] = this.userAgent; + config.headers[headers['x-sdk-version']] = this.sdkVersion; + config.headers[headers['x-api-version']] = this.apiVersion; if (this.accessToken) { - config.headers["Authorization"] = `Bearer ${this.accessToken}`; + config.headers[headers.authorization] = `Bearer ${this.accessToken}`; } return config; @@ -107,7 +114,7 @@ export default class CoreClient { const messages = [error.message] error.findDetails(ErrorInfo).forEach((detail) => { if (detail.validationErrorInfo) { - detail.validationErrorInfo.fieldViolations.forEach((fv) => { + detail.validationErrorInfo.fieldViolations.forEach((fv) => { messages.push(`${fv.field}: ${fv.description}`) }) } diff --git a/src/organization.ts b/src/organization.ts index c042ecf..3cf836b 100644 --- a/src/organization.ts +++ b/src/organization.ts @@ -142,7 +142,7 @@ export default class OrganizationClient { } /** - * Get admin portal link for an organization + * Get admin portal links for an organization * @param organizationId The organization id * @returns {Promise} The admin portal link object with expiration time and location */ From 807a452cf378eba008cc870d1f660373e29cdb9d Mon Sep 17 00:00:00 2001 From: Nitish Bhasker Date: Mon, 24 Jun 2024 11:58:29 +0530 Subject: [PATCH 19/19] prepare release 1.0.4 --- lib/connect.js | 9 +++++---- lib/connect.js.map | 2 +- lib/connection.d.ts | 12 ++++++------ lib/connection.js | 12 ++++++------ lib/connection.js.map | 2 +- lib/constants/user.d.ts | 2 +- lib/core.d.ts | 14 +++++++++----- lib/core.js | 17 ++++++++++++----- lib/core.js.map | 2 +- lib/index.d.ts | 2 +- lib/index.js | 2 +- lib/organization.d.ts | 8 +++++++- lib/organization.js | 14 +++++++++++++- lib/organization.js.map | 2 +- lib/scalekit.js | 7 ++++--- lib/scalekit.js.map | 2 +- lib/types/{user.d.ts => auth.d.ts} | 5 +++++ lib/types/{user.js => auth.js} | 2 +- lib/types/auth.js.map | 1 + lib/types/scalekit.d.ts | 5 +++-- lib/types/user.js.map | 1 - package.json | 2 +- src/core.ts | 2 +- 23 files changed, 82 insertions(+), 45 deletions(-) rename lib/types/{user.d.ts => auth.d.ts} (93%) rename lib/types/{user.js => auth.js} (70%) create mode 100644 lib/types/auth.js.map delete mode 100644 lib/types/user.js.map diff --git a/lib/connect.js b/lib/connect.js index 18af962..d8de032 100644 --- a/lib/connect.js +++ b/lib/connect.js @@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); const connect_1 = require("@connectrpc/connect"); const connect_node_1 = require("@connectrpc/connect-node"); +const core_1 = require("./core"); class GrpcConnect { constructor(coreClient) { this.coreClient = coreClient; @@ -11,11 +12,11 @@ class GrpcConnect { interceptors: [ (next) => { return (req) => { - req.header.set("User-Agent", this.coreClient.userAgent); - req.header.set("X-Sdk-Version", this.coreClient.sdkVersion); - req.header.set("X-Api-Version", this.coreClient.apiVersion); + req.header.set(core_1.headers['user-agent'], this.coreClient.userAgent); + req.header.set(core_1.headers['x-sdk-version'], this.coreClient.sdkVersion); + req.header.set(core_1.headers['x-api-version'], this.coreClient.apiVersion); if (this.coreClient.accessToken) { - req.header.set("Authorization", `Bearer ${this.coreClient.accessToken}`); + req.header.set(core_1.headers.authorization, `Bearer ${this.coreClient.accessToken}`); } return next(req); }; diff --git a/lib/connect.js.map b/lib/connect.js.map index 40fc456..406d3c3 100644 --- a/lib/connect.js.map +++ b/lib/connect.js.map @@ -1 +1 @@ -{"version":3,"file":"connect.js","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":";;AACA,iDAAoF;AACpF,2DAA+D;AAG/D,MAAqB,WAAW;IAE9B,YACmB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QAEvC,IAAI,CAAC,SAAS,GAAG,IAAA,kCAAmB,EAAC;YACnC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM;YAC/B,WAAW,EAAE,GAAG;YAChB,YAAY,EAAE;gBACZ,CAAC,IAAI,EAAE,EAAE;oBACP,OAAO,CAAC,GAAG,EAAE,EAAE;wBACb,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;wBACvD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;wBAC3D,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;wBAC3D,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;4BAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,eAAe,EAAE,UAAU,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAA;wBAC1E,CAAC;wBACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;oBAClB,CAAC,CAAA;gBACH,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAwB,OAAU;QAC5C,OAAO,IAAA,6BAAmB,EAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACF;AA3BD,8BA2BC"} \ No newline at end of file +{"version":3,"file":"connect.js","sourceRoot":"","sources":["../src/connect.ts"],"names":[],"mappings":";;AACA,iDAAoF;AACpF,2DAA+D;AAC/D,iCAA6C;AAE7C,MAAqB,WAAW;IAE9B,YACmB,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QAEvC,IAAI,CAAC,SAAS,GAAG,IAAA,kCAAmB,EAAC;YACnC,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM;YAC/B,WAAW,EAAE,GAAG;YAChB,YAAY,EAAE;gBACZ,CAAC,IAAI,EAAE,EAAE;oBACP,OAAO,CAAC,GAAG,EAAE,EAAE;wBACb,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,cAAO,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;wBAChE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,cAAO,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;wBACpE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,cAAO,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;wBACpE,IAAI,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC;4BAChC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,cAAO,CAAC,aAAa,EAAE,UAAU,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,CAAC,CAAA;wBAChF,CAAC;wBACD,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA;oBAClB,CAAC,CAAA;gBACH,CAAC;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,YAAY,CAAwB,OAAU;QAC5C,OAAO,IAAA,6BAAmB,EAAC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACtD,CAAC;CACF;AA3BD,8BA2BC"} \ No newline at end of file diff --git a/lib/connection.d.ts b/lib/connection.d.ts index b6f5476..8fd804a 100644 --- a/lib/connection.d.ts +++ b/lib/connection.d.ts @@ -8,11 +8,11 @@ export default class ConnectionClient { constructor(grpcConncet: GrpcConnect, coreClient: CoreClient); /** * Get a connection by id and organization id - * @param id The connection id * @param organizationId The organization id + * @param id The connection id * @returns {Promise} The connection */ - getConnection(id: string, organizationId: string): Promise; + getConnection(organizationId: string, id: string): Promise; /** * List connections by domain * @param domain The domain @@ -27,16 +27,16 @@ export default class ConnectionClient { listConnections(organizationId: string): Promise; /** * Enable a connection by id and organization id - * @param id The connection id * @param organizationId The organization id + * @param id The connection id * @returns {Promise} The connection enable response */ - enableConnection(id: string, organizationId: string): Promise; + enableConnection(organizationId: string, id: string): Promise; /** * Disable a connection by id and organization id - * @param id The connection id * @param organizationId The organization id + * @param id The connection id * @returns {Promise} The connection enable response */ - disableConnection(id: string, organizationId: string): Promise; + disableConnection(organizationId: string, id: string): Promise; } diff --git a/lib/connection.js b/lib/connection.js index b5190fe..d0cb54d 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -18,11 +18,11 @@ class ConnectionClient { } /** * Get a connection by id and organization id - * @param id The connection id * @param organizationId The organization id + * @param id The connection id * @returns {Promise} The connection */ - getConnection(id, organizationId) { + getConnection(organizationId, id) { return __awaiter(this, void 0, void 0, function* () { return this.coreClient.connectExec(this.client.getConnection, { id, @@ -65,11 +65,11 @@ class ConnectionClient { } /** * Enable a connection by id and organization id - * @param id The connection id * @param organizationId The organization id + * @param id The connection id * @returns {Promise} The connection enable response */ - enableConnection(id, organizationId) { + enableConnection(organizationId, id) { return __awaiter(this, void 0, void 0, function* () { return this.coreClient.connectExec(this.client.enableConnection, { id, @@ -82,11 +82,11 @@ class ConnectionClient { } /** * Disable a connection by id and organization id - * @param id The connection id * @param organizationId The organization id + * @param id The connection id * @returns {Promise} The connection enable response */ - disableConnection(id, organizationId) { + disableConnection(organizationId, id) { return __awaiter(this, void 0, void 0, function* () { return this.coreClient.connectExec(this.client.disableConnection, { id, diff --git a/lib/connection.js.map b/lib/connection.js.map index 37406fa..906b904 100644 --- a/lib/connection.js.map +++ b/lib/connection.js.map @@ -1 +1 @@ -{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,gGAA2F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iBAAiB,CAAC,EAAU,EAAE,cAAsB;;YACxD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAC7B;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;CACF;AAnGD,mCAmGC"} \ No newline at end of file +{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,gGAA2F;AAG3F,MAAqB,gBAAgB;IAEnC,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,uCAAiB,CAAC,CAAC;IACjE,CAAC;IAED;;;;;OAKG;IACG,aAAa,CAAC,cAAsB,EAAE,EAAU;;YACpD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,aAAa,EACzB;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,uBAAuB,CAAC,MAAc;;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,eAAe,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,MAAM;iBACd;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;OAIG;IACG,eAAe,CAAC,cAAsB;;YAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,eAAe,EAC3B;gBACE,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACG,gBAAgB,CAAC,cAAsB,EAAE,EAAU;;YACvD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAC5B;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACG,iBAAiB,CAAC,cAAsB,EAAE,EAAU;;YACxD,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAC7B;gBACE,EAAE;gBACF,UAAU,EAAE;oBACV,IAAI,EAAE,gBAAgB;oBACtB,KAAK,EAAE,cAAc;iBACtB;aACF,CACF,CAAA;QACH,CAAC;KAAA;CACF;AAnGD,mCAmGC"} \ No newline at end of file diff --git a/lib/constants/user.d.ts b/lib/constants/user.d.ts index d2e3c30..40bd40d 100644 --- a/lib/constants/user.d.ts +++ b/lib/constants/user.d.ts @@ -1,4 +1,4 @@ -import type { IdTokenClaim, User } from '../types/user'; +import type { IdTokenClaim, User } from '../types/auth'; export declare const IdTokenClaimToUserMap: { [k in keyof IdTokenClaim]: keyof User; }; diff --git a/lib/core.d.ts b/lib/core.d.ts index 717425f..7782d89 100644 --- a/lib/core.d.ts +++ b/lib/core.d.ts @@ -1,5 +1,12 @@ import { Axios, AxiosResponse } from "axios"; import { JWK } from 'jose'; +import { TokenResponse } from './types/auth'; +export declare const headers: { + "user-agent": string; + "x-sdk-version": string; + "x-api-version": string; + authorization: string; +}; export default class CoreClient { readonly envUrl: string; readonly clientId: string; @@ -15,12 +22,9 @@ export default class CoreClient { /** * Authenticate with the code * @param {string} data Data to authenticate - * @returns {Promise>} Returns access token and id token + * @returns {Promise>} Returns access token and id token */ - authenticate(data: string): Promise>; + authenticate(data: string): Promise>; /** * Get the JWKS from the server and store it in the client instance * @returns {Promise} Returns nothing diff --git a/lib/core.js b/lib/core.js index 59d921c..2f8b3ca 100644 --- a/lib/core.js +++ b/lib/core.js @@ -35,12 +35,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); +exports.headers = void 0; const connect_1 = require("@connectrpc/connect"); const axios_1 = __importStar(require("axios")); const os_1 = __importDefault(require("os")); const qs_1 = __importDefault(require("qs")); const scalekit_1 = require("./types/scalekit"); const errdetails_pb_1 = require("./pkg/grpc/scalekit/v1/errdetails/errdetails_pb"); +exports.headers = { + "user-agent": "user-agent", + "x-sdk-version": "x-sdk-version", + "x-api-version": "x-api-version", + "authorization": "authorization" +}; const tokenEndpoint = "oauth/token"; const jwksEndpoint = "keys"; class CoreClient { @@ -55,11 +62,11 @@ class CoreClient { this.userAgent = `${this.sdkVersion} Node/${process.version} (${process.platform}; ${os_1.default.arch()})`; this.axios = axios_1.default.create({ baseURL: envUrl }); this.axios.interceptors.request.use((config) => { - config.headers["User-Agent"] = this.userAgent; - config.headers["X-Sdk-Version"] = this.sdkVersion; - config.headers["X-Api-Version"] = this.apiVersion; + config.headers[exports.headers['user-agent']] = this.userAgent; + config.headers[exports.headers['x-sdk-version']] = this.sdkVersion; + config.headers[exports.headers['x-api-version']] = this.apiVersion; if (this.accessToken) { - config.headers["Authorization"] = `Bearer ${this.accessToken}`; + config.headers[exports.headers.authorization] = `Bearer ${this.accessToken}`; } return config; }); @@ -78,7 +85,7 @@ class CoreClient { /** * Authenticate with the code * @param {string} data Data to authenticate - * @returns {Promise>} Returns access token and id token + * @returns {Promise>} Returns access token and id token */ authenticate(data) { return __awaiter(this, void 0, void 0, function* () { diff --git a/lib/core.js.map b/lib/core.js.map index 8b54f2f..a78c067 100644 --- a/lib/core.js.map +++ b/lib/core.js.map @@ -1 +1 @@ -{"version":3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AM,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;wBACvC,CAAC;oBACH,CAAC;oBACD,IAAI,sBAAsB,EAAE,CAAC;wBAC3B,MAAM,IAAI,CAAC,kBAAkB,EAAE,CAAC;wBAChC,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC;oBACnD,CAAC;gBACH,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KAAA;CACF;AAnHD,6BAmHC"} \ No newline at end of file diff --git a/lib/index.d.ts b/lib/index.d.ts index ea10d09..d365322 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -2,4 +2,4 @@ import ScalekitClient from "./scalekit"; export { ScalekitClient }; export default ScalekitClient; export * from "./types/scalekit"; -export * from "./types/user"; +export * from "./types/auth"; diff --git a/lib/index.js b/lib/index.js index 7d5bba5..9a1c3ac 100644 --- a/lib/index.js +++ b/lib/index.js @@ -22,5 +22,5 @@ const scalekit_1 = __importDefault(require("./scalekit")); exports.ScalekitClient = scalekit_1.default; exports.default = scalekit_1.default; __exportStar(require("./types/scalekit"), exports); -__exportStar(require("./types/user"), exports); +__exportStar(require("./types/auth"), exports); //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/lib/organization.d.ts b/lib/organization.d.ts index c3d601d..3a6cd87 100644 --- a/lib/organization.d.ts +++ b/lib/organization.d.ts @@ -54,6 +54,12 @@ export default class OrganizationClient { * @returns {Promise} The updated organization */ updateOrganizationByExternalId(externalId: string, organization: PartialMessage): Promise; + /** + * Delete an organization by id + * @param {string} organizationId The organization id + * @returns {Promise} Returns nothing + */ + deleteOrganization(organizationId: string): Promise; /** * Generate admin portal link for an organization * @param organizationId The organization id @@ -61,7 +67,7 @@ export default class OrganizationClient { */ generatePortalLink(organizationId: string): Promise; /** - * Get admin portal link for an organization + * Get admin portal links for an organization * @param organizationId The organization id * @returns {Promise} The admin portal link object with expiration time and location */ diff --git a/lib/organization.js b/lib/organization.js index f6e8c3d..94b97cf 100644 --- a/lib/organization.js +++ b/lib/organization.js @@ -92,6 +92,18 @@ class OrganizationClient { }); }); } + /** + * Delete an organization by id + * @param {string} organizationId The organization id + * @returns {Promise} Returns nothing + */ + deleteOrganization(organizationId) { + return __awaiter(this, void 0, void 0, function* () { + return this.coreClient.connectExec(this.client.deleteOrganization, { + identities: { case: "id", value: organizationId, }, + }); + }); + } /** * Generate admin portal link for an organization * @param organizationId The organization id @@ -109,7 +121,7 @@ class OrganizationClient { }); } /** - * Get admin portal link for an organization + * Get admin portal links for an organization * @param organizationId The organization id * @returns {Promise} The admin portal link object with expiration time and location */ diff --git a/lib/organization.js.map b/lib/organization.js.map index b872fc2..de788de 100644 --- a/lib/organization.js.map +++ b/lib/organization.js.map @@ -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,IAAY,EAAE,OAAiC;;YACtE,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAC9B;gBACE,YAAY,kBACV,WAAW,EAAE,IAAI,IACd,CAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,KAAI;oBACzB,UAAU,EAAE,OAAO,CAAC,UAAU;iBAC/B,CAAC,CACH;aACF,CACF,CAAA;QACH,CAAC;KAAA;IAED;;;;;;OAMG;IACG,gBAAgB,CAAC,OAGtB;;YACC,OAAO,IA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AC,UAAU,CAAC,WAAW,CAChD,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAC9B;gBACE,EAAE,EAAE,cAAc;aACnB,CACF,CAAA;YACD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAClD,CAAC;YAED,OAAO,QAAQ,CAAC,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;AAzJD,qCAyJC"} \ No newline at end of file +{"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,IAAY,EAAE,OAAiC;;YACtE,OAAO,IAAI,CAAC,UAAU,CAAC,WAAW,CAChC,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAC9B;gBACE,YAAY,kBACV,WAAW,E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scalekit.js b/lib/scalekit.js index 7566575..9b3be08 100644 --- a/lib/scalekit.js +++ b/lib/scalekit.js @@ -84,7 +84,7 @@ class ScalekitClient { getAuthorizationUrl(redirectUri, options) { var _a; const defaultOptions = { - scopes: ['openid', 'profile'] + scopes: ['openid', 'profile', 'email'] }; options = Object.assign(Object.assign({}, defaultOptions), options); 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 }))); @@ -101,7 +101,7 @@ class ScalekitClient { authenticateWithCode(code, redirectUri, options) { return __awaiter(this, void 0, void 0, function* () { 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 })))); - const { id_token, access_token } = res.data; + const { id_token, access_token, expires_in } = res.data; const claims = jose.decodeJwt(id_token); const user = {}; for (const [k, v] of Object.entries(claims)) { @@ -112,7 +112,8 @@ class ScalekitClient { return { user, idToken: id_token, - accessToken: access_token + accessToken: access_token, + expiresIn: expires_in }; }); } diff --git a/lib/scalekit.js.map b/lib/scalekit.js.map index 6723c82..7755462 100644 --- a/lib/scalekit.js.map +++ b/lib/scalekit.js.map @@ -1 +1 @@ -{"version":3,"file":"scalekit.js","sourceRoot":"","sources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AY,KAAI,EAAE,aAAa,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,EACrE,CAAC,CAAA;YACH,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;YACxD,MAAM,MAAM,GAAG,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;AA3ID,iCA2IC"} \ No newline at end of file diff --git a/lib/types/user.d.ts b/lib/types/auth.d.ts similarity index 93% rename from lib/types/user.d.ts rename to lib/types/auth.d.ts index 6f4d4ad..58ba70f 100644 --- a/lib/types/user.d.ts +++ b/lib/types/auth.d.ts @@ -54,3 +54,8 @@ export type IdTokenClaim = { identities: IdTokenClaimIdentity[]; metadata: string | undefined; }; +export type TokenResponse = { + access_token: string; + id_token: string; + expires_in: number; +}; diff --git a/lib/types/user.js b/lib/types/auth.js similarity index 70% rename from lib/types/user.js rename to lib/types/auth.js index 33269d3..1bf0817 100644 --- a/lib/types/user.js +++ b/lib/types/auth.js @@ -1,3 +1,3 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -//# sourceMappingURL=user.js.map \ No newline at end of file +//# sourceMappingURL=auth.js.map \ No newline at end of file diff --git a/lib/types/auth.js.map b/lib/types/auth.js.map new file mode 100644 index 0000000..8e51891 --- /dev/null +++ b/lib/types/auth.js.map @@ -0,0 +1 @@ +{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/lib/types/scalekit.d.ts b/lib/types/scalekit.d.ts index 25c2d2c..feff268 100644 --- a/lib/types/scalekit.d.ts +++ b/lib/types/scalekit.d.ts @@ -1,4 +1,4 @@ -import { User } from './user'; +import { User } from './auth'; export declare enum GrantType { AuthorizationCode = "authorization_code", RefreshToken = "refresh_token", @@ -19,7 +19,8 @@ export type AuthenticationOptions = { codeVerifier?: string; }; export type AuthenticationResponse = { - user: Partial; + user: User; idToken: string; accessToken: string; + expiresIn: number; }; diff --git a/lib/types/user.js.map b/lib/types/user.js.map deleted file mode 100644 index 07c1726..0000000 --- a/lib/types/user.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"user.js","sourceRoot":"","sources":["../../src/types/user.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/package.json b/package.json index 7fcb266..d23f50d 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.0.3", + "version": "1.0.4", "name": "@scalekit-sdk/node", "description": "Official Scalekit Node SDK", "main": "lib/index.js", diff --git a/src/core.ts b/src/core.ts index b92bfb4..c77fb90 100644 --- a/src/core.ts +++ b/src/core.ts @@ -20,7 +20,7 @@ export default class CoreClient { public keys: JWK[] = []; public accessToken: string | null = null; public axios: Axios; - public sdkVersion = `Scalekit-Node/1.0.3`; + public sdkVersion = `Scalekit-Node/1.0.4`; public apiVersion = "20240430"; public userAgent = `${this.sdkVersion} Node/${process.version} (${process.platform}; ${os.arch()})`; constructor(