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 +) +``` diff --git a/libs/api-sdk/README.md b/libs/api-sdk/README.md index 136c4a46..32ffebdd 100644 --- a/libs/api-sdk/README.md +++ b/libs/api-sdk/README.md @@ -400,3 +400,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 +) +``` diff --git a/libs/api-sdk/src/apiSdk.ts b/libs/api-sdk/src/apiSdk.ts index 01db4980..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 { @@ -22,7 +23,8 @@ import { removeMemberByApiKey, removeMembersByApiKey, getGroupsByAdminId, - getGroupsByMemberId + getGroupsByMemberId, + getCredentialGroupJoinUrl } from "./groups" import { createInvite, getInvite } from "./invites" @@ -350,4 +352,31 @@ export default class ApiSdk { return invite } + + /** + * Generate a custom url for joining a credential group. + * @param dashboardUrl Dashboard base url. + * @param groupId Group id. + * @param commitment Identity commitment. + * @param providerName Group credential provider name. + * @param redirectUri Redirect uri. + * @returns Url string. + */ + getCredentialGroupJoinUrl( + dashboardUrl: DashboardUrl, + groupId: string, + commitment: string, + providerName: string, + redirectUri?: string + ): string { + const url = getCredentialGroupJoinUrl( + dashboardUrl, + groupId, + commitment, + providerName, + redirectUri + ) + + return url + } } diff --git a/libs/api-sdk/src/groups.ts b/libs/api-sdk/src/groups.ts index b0b4c938..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" @@ -371,3 +376,28 @@ export async function removeMembersByApiKey( await request(requestUrl, newConfig) } + +/** + * Generate a custorm url for joining a credential group. + * @param dashboardUrl Dashboard url. + * @param groupId Group id. + * @param commitment Identity commitment. + * @param providerName Group credential provider name. + * @param redirectUri Redirect uri. + * @returns Url string. + */ +export function getCredentialGroupJoinUrl( + dashboardUrl: DashboardUrl, + groupId: string, + commitment: string, + providerName: string, + redirectUri?: string +): string { + let resultUrl = `${dashboardUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}` + + if (redirectUri) { + resultUrl += `&redirect_uri=${redirectUri}?redirect=true` + } + + return resultUrl +} diff --git a/libs/api-sdk/src/index.test.ts b/libs/api-sdk/src/index.test.ts index af950cd1..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" @@ -582,6 +583,29 @@ describe("Bandada API SDK", () => { expect(res).toBeUndefined() }) }) + + describe("#getCredentialGroupJoinUrl", () => { + it("Should generate a custom url for joining a credential group", async () => { + const dashboardUrl = DashboardUrl.DEV + const groupId = "10402173435763029700781503965100" + const commitment = "1" + const providerName = "github" + const redirectUri = "http://localhost:3003" + + apiSdk = new ApiSdk(SupportedUrl.DEV) + const res = apiSdk.getCredentialGroupJoinUrl( + dashboardUrl, + groupId, + commitment, + providerName, + redirectUri + ) + + const url = `${dashboardUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}?redirect=true` + + expect(res).toBe(url) + }) + }) }) }) describe("Invites", () => { 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" +}