From 5d3de8dc6a1978689ea05526ef4d0be66a3e379d Mon Sep 17 00:00:00 2001 From: Hw <56923450+waddaboo@users.noreply.github.com> Date: Mon, 17 Jun 2024 17:42:23 +0800 Subject: [PATCH 01/11] feat(api-sdk): add joinCredentialGroup() --- libs/api-sdk/README.md | 22 ++++++++++++++++++++++ libs/api-sdk/src/apiSdk.ts | 30 +++++++++++++++++++++++++++++- libs/api-sdk/src/groups.ts | 23 +++++++++++++++++++++++ libs/api-sdk/src/index.test.ts | 23 +++++++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) diff --git a/libs/api-sdk/README.md b/libs/api-sdk/README.md index 136c4a46..96b733bd 100644 --- a/libs/api-sdk/README.md +++ b/libs/api-sdk/README.md @@ -400,3 +400,25 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" const invite = await apiSdk.getInvite(inviteCode) ``` + +## Join credential group + +\# **joinCredentialGroup**(): _string_ + +Returns a custom URL string for joining credential group. + +```ts +const baseUrl = "http://localhost:3000" +const groupId = "10402173435763029700781503965100" +const commitment = "1" +const providerName = "GITHUB" +const redirectUri = "http://localhost:3003" + +const url = apiSdk.joinCredentialGroup( + baseUrl, + groupId, + commitment, + providerName, + redirectUri +) +``` diff --git a/libs/api-sdk/src/apiSdk.ts b/libs/api-sdk/src/apiSdk.ts index 01db4980..edb8a68e 100644 --- a/libs/api-sdk/src/apiSdk.ts +++ b/libs/api-sdk/src/apiSdk.ts @@ -22,7 +22,8 @@ import { removeMemberByApiKey, removeMembersByApiKey, getGroupsByAdminId, - getGroupsByMemberId + getGroupsByMemberId, + joinCredentialGroup } from "./groups" import { createInvite, getInvite } from "./invites" @@ -350,4 +351,31 @@ export default class ApiSdk { return invite } + + /** + * Generate a custom url for joining a credential group. + * @param baseUrl Base url. + * @param groupId Group id. + * @param commitment Identity commitment. + * @param providerName Group credential provider name. + * @param redirectUri Redirect uri. + * @returns Url string. + */ + joinCredentialGroup( + baseUrl: string, + groupId: string, + commitment: string, + providerName: string, + redirectUri?: string + ) { + const url = joinCredentialGroup( + baseUrl, + groupId, + commitment, + providerName, + redirectUri + ) + + return url + } } diff --git a/libs/api-sdk/src/groups.ts b/libs/api-sdk/src/groups.ts index b0b4c938..fe7e2e38 100644 --- a/libs/api-sdk/src/groups.ts +++ b/libs/api-sdk/src/groups.ts @@ -371,3 +371,26 @@ export async function removeMembersByApiKey( await request(requestUrl, newConfig) } + +/** + * Generate a custorm url for joining a credential group. + * @param baseUrl Base url. + * @param groupId Group id. + * @param commitment Identity commitment. + * @param providerName Group credential provider name. + * @param redirectUri Redirect uri. + * @returns Url string. + */ +export function joinCredentialGroup( + baseUrl: string, + groupId: string, + commitment: string, + providerName: string, + redirectUri?: string +) { + if (redirectUri) { + return `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}/groups?redirect=true` + } + + return `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}` +} diff --git a/libs/api-sdk/src/index.test.ts b/libs/api-sdk/src/index.test.ts index af950cd1..06b530f0 100644 --- a/libs/api-sdk/src/index.test.ts +++ b/libs/api-sdk/src/index.test.ts @@ -582,6 +582,29 @@ describe("Bandada API SDK", () => { expect(res).toBeUndefined() }) }) + + describe("#joinCredentialGroup", () => { + it("Should generate a custom url for joining a credential group", async () => { + const baseUrl = "http://localhost:3000" + const groupId = "10402173435763029700781503965100" + const commitment = "1" + const providerName = "GITHUB" + const redirectUri = "http://localhost:3003" + + apiSdk = new ApiSdk(SupportedUrl.DEV) + const res = apiSdk.joinCredentialGroup( + baseUrl, + groupId, + commitment, + providerName, + redirectUri + ) + + const url = `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}/groups?redirect=true` + + expect(res).toBe(url) + }) + }) }) }) describe("Invites", () => { From 4130e94c81b853abd450a0b45eae4f2bf29fd011 Mon Sep 17 00:00:00 2001 From: hw <56923450+waddaboo@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:25:27 +0800 Subject: [PATCH 02/11] docs: update description Co-authored-by: Vivian Plasencia --- libs/api-sdk/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api-sdk/README.md b/libs/api-sdk/README.md index 96b733bd..c064ce73 100644 --- a/libs/api-sdk/README.md +++ b/libs/api-sdk/README.md @@ -405,7 +405,7 @@ const invite = await apiSdk.getInvite(inviteCode) \# **joinCredentialGroup**(): _string_ -Returns a custom URL string for joining credential group. +Returns a custom URL string for joining a credential group. ```ts const baseUrl = "http://localhost:3000" From 2c66e92a07e1c7aaac1229047c7ceca23c6b4774 Mon Sep 17 00:00:00 2001 From: hw <56923450+waddaboo@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:26:03 +0800 Subject: [PATCH 03/11] docs: update example providerName Co-authored-by: Vivian Plasencia --- libs/api-sdk/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api-sdk/README.md b/libs/api-sdk/README.md index c064ce73..557e472a 100644 --- a/libs/api-sdk/README.md +++ b/libs/api-sdk/README.md @@ -411,7 +411,7 @@ Returns a custom URL string for joining a credential group. const baseUrl = "http://localhost:3000" const groupId = "10402173435763029700781503965100" const commitment = "1" -const providerName = "GITHUB" +const providerName = "github" const redirectUri = "http://localhost:3003" const url = apiSdk.joinCredentialGroup( From 774a52f36f394c208442536d6172b9aac3220cd1 Mon Sep 17 00:00:00 2001 From: hw <56923450+waddaboo@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:29:17 +0800 Subject: [PATCH 04/11] fix: add return string type Co-authored-by: Vivian Plasencia --- libs/api-sdk/src/apiSdk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api-sdk/src/apiSdk.ts b/libs/api-sdk/src/apiSdk.ts index edb8a68e..518ae42b 100644 --- a/libs/api-sdk/src/apiSdk.ts +++ b/libs/api-sdk/src/apiSdk.ts @@ -367,7 +367,7 @@ export default class ApiSdk { commitment: string, providerName: string, redirectUri?: string - ) { + ): string { const url = joinCredentialGroup( baseUrl, groupId, From e3441c1a97b8e712b7c4e5a17987e6554eac91a4 Mon Sep 17 00:00:00 2001 From: hw <56923450+waddaboo@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:29:58 +0800 Subject: [PATCH 05/11] fix: add return string type Co-authored-by: Vivian Plasencia --- libs/api-sdk/src/groups.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api-sdk/src/groups.ts b/libs/api-sdk/src/groups.ts index fe7e2e38..cd3e80cb 100644 --- a/libs/api-sdk/src/groups.ts +++ b/libs/api-sdk/src/groups.ts @@ -387,7 +387,7 @@ export function joinCredentialGroup( commitment: string, providerName: string, redirectUri?: string -) { +): string { if (redirectUri) { return `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}/groups?redirect=true` } From 59f1137c594cf3dff5dbafc69204e036b975e458 Mon Sep 17 00:00:00 2001 From: hw <56923450+waddaboo@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:32:47 +0800 Subject: [PATCH 06/11] refactor: remove repeating code and update return url string Co-authored-by: Vivian Plasencia --- libs/api-sdk/src/groups.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/api-sdk/src/groups.ts b/libs/api-sdk/src/groups.ts index cd3e80cb..5dc4089b 100644 --- a/libs/api-sdk/src/groups.ts +++ b/libs/api-sdk/src/groups.ts @@ -388,9 +388,11 @@ export function joinCredentialGroup( providerName: string, redirectUri?: string ): string { + let resultUrl = `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}` + if (redirectUri) { - return `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}/groups?redirect=true` + resultUrl += `&redirect_uri=${redirectUri}?redirect=true` } - return `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}` + return resultUrl } From 16642544a35d3771c90c7466b88b447e04ea4963 Mon Sep 17 00:00:00 2001 From: Hw <56923450+waddaboo@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:03:58 +0800 Subject: [PATCH 07/11] fix: rename joinCredentialGroup to getCredentialGroupJoinUrl --- libs/api-sdk/README.md | 4 ++-- libs/api-sdk/src/apiSdk.ts | 6 +++--- libs/api-sdk/src/groups.ts | 2 +- libs/api-sdk/src/index.test.ts | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libs/api-sdk/README.md b/libs/api-sdk/README.md index 557e472a..bbffa691 100644 --- a/libs/api-sdk/README.md +++ b/libs/api-sdk/README.md @@ -403,7 +403,7 @@ const invite = await apiSdk.getInvite(inviteCode) ## Join credential group -\# **joinCredentialGroup**(): _string_ +\# **getCredentialGroupJoinUrl**(): _string_ Returns a custom URL string for joining a credential group. @@ -414,7 +414,7 @@ const commitment = "1" const providerName = "github" const redirectUri = "http://localhost:3003" -const url = apiSdk.joinCredentialGroup( +const url = apiSdk.getCredentialGroupJoinUrl( baseUrl, groupId, commitment, diff --git a/libs/api-sdk/src/apiSdk.ts b/libs/api-sdk/src/apiSdk.ts index 518ae42b..35eeb4ce 100644 --- a/libs/api-sdk/src/apiSdk.ts +++ b/libs/api-sdk/src/apiSdk.ts @@ -23,7 +23,7 @@ import { removeMembersByApiKey, getGroupsByAdminId, getGroupsByMemberId, - joinCredentialGroup + getCredentialGroupJoinUrl } from "./groups" import { createInvite, getInvite } from "./invites" @@ -361,14 +361,14 @@ export default class ApiSdk { * @param redirectUri Redirect uri. * @returns Url string. */ - joinCredentialGroup( + getCredentialGroupJoinUrl( baseUrl: string, groupId: string, commitment: string, providerName: string, redirectUri?: string ): string { - const url = joinCredentialGroup( + const url = getCredentialGroupJoinUrl( baseUrl, groupId, commitment, diff --git a/libs/api-sdk/src/groups.ts b/libs/api-sdk/src/groups.ts index 5dc4089b..17ad8942 100644 --- a/libs/api-sdk/src/groups.ts +++ b/libs/api-sdk/src/groups.ts @@ -381,7 +381,7 @@ export async function removeMembersByApiKey( * @param redirectUri Redirect uri. * @returns Url string. */ -export function joinCredentialGroup( +export function getCredentialGroupJoinUrl( baseUrl: string, groupId: string, commitment: string, diff --git a/libs/api-sdk/src/index.test.ts b/libs/api-sdk/src/index.test.ts index 06b530f0..98d70aef 100644 --- a/libs/api-sdk/src/index.test.ts +++ b/libs/api-sdk/src/index.test.ts @@ -583,16 +583,16 @@ describe("Bandada API SDK", () => { }) }) - describe("#joinCredentialGroup", () => { + describe("#getCredentialGroupJoinUrl", () => { it("Should generate a custom url for joining a credential group", async () => { const baseUrl = "http://localhost:3000" const groupId = "10402173435763029700781503965100" const commitment = "1" - const providerName = "GITHUB" + const providerName = "github" const redirectUri = "http://localhost:3003" apiSdk = new ApiSdk(SupportedUrl.DEV) - const res = apiSdk.joinCredentialGroup( + const res = apiSdk.getCredentialGroupJoinUrl( baseUrl, groupId, commitment, @@ -600,7 +600,7 @@ describe("Bandada API SDK", () => { redirectUri ) - const url = `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}/groups?redirect=true` + const url = `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}?redirect=true` expect(res).toBe(url) }) From a81325ba3e3725845c43a4f19cafcafc167c099b Mon Sep 17 00:00:00 2001 From: Hw <56923450+waddaboo@users.noreply.github.com> Date: Wed, 26 Jun 2024 17:34:47 +0800 Subject: [PATCH 08/11] docs: update getCredentialGroupJoinUrl name --- libs/api-sdk/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/api-sdk/README.md b/libs/api-sdk/README.md index bbffa691..0d96fcf5 100644 --- a/libs/api-sdk/README.md +++ b/libs/api-sdk/README.md @@ -401,7 +401,7 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" const invite = await apiSdk.getInvite(inviteCode) ``` -## Join credential group +## Get credential group join URL \# **getCredentialGroupJoinUrl**(): _string_ From 2286677d14cda7f58cc4bd03c423d17c57876034 Mon Sep 17 00:00:00 2001 From: Hw <56923450+waddaboo@users.noreply.github.com> Date: Wed, 26 Jun 2024 20:16:38 +0800 Subject: [PATCH 09/11] feat: add DashboardUrl type --- libs/api-sdk/src/types/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/api-sdk/src/types/index.ts b/libs/api-sdk/src/types/index.ts index 050e6ce7..b9feda7f 100644 --- a/libs/api-sdk/src/types/index.ts +++ b/libs/api-sdk/src/types/index.ts @@ -55,3 +55,9 @@ export enum SupportedUrl { PROD = "https://api.bandada.pse.dev", STAGING = "https://api-staging.bandada.pse.dev" } + +export enum DashboardUrl { + DEV = "http://localhost:3001", + PROD = "https://app.bandada.pse.dev", + STAGING = "https://app-staging.bandada.pse.dev" +} From a85fccfeb246ae0b4e545c003daa4009ee622688 Mon Sep 17 00:00:00 2001 From: Hw <56923450+waddaboo@users.noreply.github.com> Date: Wed, 26 Jun 2024 20:22:46 +0800 Subject: [PATCH 10/11] fix: update getCredentialGroupJoinUrl baseUrl type to DashboardUrl type --- libs/api-sdk/README.md | 6 ++++-- libs/api-sdk/src/apiSdk.ts | 9 +++++---- libs/api-sdk/src/groups.ts | 13 +++++++++---- libs/api-sdk/src/index.test.ts | 9 +++++---- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/libs/api-sdk/README.md b/libs/api-sdk/README.md index 0d96fcf5..32ffebdd 100644 --- a/libs/api-sdk/README.md +++ b/libs/api-sdk/README.md @@ -408,14 +408,16 @@ const invite = await apiSdk.getInvite(inviteCode) Returns a custom URL string for joining a credential group. ```ts -const baseUrl = "http://localhost:3000" +import { DashboardUrl } from "@bandada/api-sdk" + +const dashboardUrl = DashboardUrl.DEV const groupId = "10402173435763029700781503965100" const commitment = "1" const providerName = "github" const redirectUri = "http://localhost:3003" const url = apiSdk.getCredentialGroupJoinUrl( - baseUrl, + dashboardUrl, groupId, commitment, providerName, diff --git a/libs/api-sdk/src/apiSdk.ts b/libs/api-sdk/src/apiSdk.ts index 35eeb4ce..5fc9dc2b 100644 --- a/libs/api-sdk/src/apiSdk.ts +++ b/libs/api-sdk/src/apiSdk.ts @@ -3,7 +3,8 @@ import { Group, Invite, GroupCreationDetails, - GroupUpdateDetails + GroupUpdateDetails, + DashboardUrl } from "./types" import checkParameter from "./checkParameter" import { @@ -354,7 +355,7 @@ export default class ApiSdk { /** * Generate a custom url for joining a credential group. - * @param baseUrl Base url. + * @param dashboardUrl Dashboard base url. * @param groupId Group id. * @param commitment Identity commitment. * @param providerName Group credential provider name. @@ -362,14 +363,14 @@ export default class ApiSdk { * @returns Url string. */ getCredentialGroupJoinUrl( - baseUrl: string, + dashboardUrl: DashboardUrl, groupId: string, commitment: string, providerName: string, redirectUri?: string ): string { const url = getCredentialGroupJoinUrl( - baseUrl, + dashboardUrl, groupId, commitment, providerName, diff --git a/libs/api-sdk/src/groups.ts b/libs/api-sdk/src/groups.ts index 17ad8942..02a66212 100644 --- a/libs/api-sdk/src/groups.ts +++ b/libs/api-sdk/src/groups.ts @@ -1,5 +1,10 @@ import { request } from "@bandada/utils" -import type { GroupCreationDetails, Group, GroupUpdateDetails } from "./types" +import type { + GroupCreationDetails, + Group, + GroupUpdateDetails, + DashboardUrl +} from "./types" const url = "/groups" @@ -374,7 +379,7 @@ export async function removeMembersByApiKey( /** * Generate a custorm url for joining a credential group. - * @param baseUrl Base url. + * @param dashboardUrl Dashboard url. * @param groupId Group id. * @param commitment Identity commitment. * @param providerName Group credential provider name. @@ -382,13 +387,13 @@ export async function removeMembersByApiKey( * @returns Url string. */ export function getCredentialGroupJoinUrl( - baseUrl: string, + dashboardUrl: DashboardUrl, groupId: string, commitment: string, providerName: string, redirectUri?: string ): string { - let resultUrl = `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}` + let resultUrl = `${dashboardUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}` if (redirectUri) { resultUrl += `&redirect_uri=${redirectUri}?redirect=true` diff --git a/libs/api-sdk/src/index.test.ts b/libs/api-sdk/src/index.test.ts index 98d70aef..d06f8fb8 100644 --- a/libs/api-sdk/src/index.test.ts +++ b/libs/api-sdk/src/index.test.ts @@ -5,7 +5,8 @@ import { Group, GroupUpdateDetails, Invite, - SupportedUrl + SupportedUrl, + DashboardUrl } from "./types" import checkParameter from "./checkParameter" @@ -585,7 +586,7 @@ describe("Bandada API SDK", () => { describe("#getCredentialGroupJoinUrl", () => { it("Should generate a custom url for joining a credential group", async () => { - const baseUrl = "http://localhost:3000" + const dashboardUrl = DashboardUrl.DEV const groupId = "10402173435763029700781503965100" const commitment = "1" const providerName = "github" @@ -593,14 +594,14 @@ describe("Bandada API SDK", () => { apiSdk = new ApiSdk(SupportedUrl.DEV) const res = apiSdk.getCredentialGroupJoinUrl( - baseUrl, + dashboardUrl, groupId, commitment, providerName, redirectUri ) - const url = `${baseUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}?redirect=true` + const url = `${dashboardUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}?redirect=true` expect(res).toBe(url) }) From df4a157416925939942b273bf5b8b396bef1252d Mon Sep 17 00:00:00 2001 From: Hw <56923450+waddaboo@users.noreply.github.com> Date: Wed, 26 Jun 2024 20:28:02 +0800 Subject: [PATCH 11/11] docs: add getCredentialGroupJoinUrl --- apps/docs/docs/api-sdk.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/apps/docs/docs/api-sdk.md b/apps/docs/docs/api-sdk.md index fe44943b..51c33b49 100644 --- a/apps/docs/docs/api-sdk.md +++ b/apps/docs/docs/api-sdk.md @@ -377,3 +377,27 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" const invite = await apiSdk.getInvite(inviteCode) ``` + +## Get credential group join URL + +\# **getCredentialGroupJoinUrl**(): _string_ + +Returns a custom URL string for joining a credential group. + +```ts +import { DashboardUrl } from "@bandada/api-sdk" + +const dashboardUrl = DashboardUrl.DEV +const groupId = "10402173435763029700781503965100" +const commitment = "1" +const providerName = "github" +const redirectUri = "http://localhost:3003" + +const url = apiSdk.getCredentialGroupJoinUrl( + dashboardUrl, + groupId, + commitment, + providerName, + redirectUri +) +```