Skip to content

Commit

Permalink
Merge pull request #529 from waddaboo/issue#513
Browse files Browse the repository at this point in the history
feat(api-sdk): add joinCredentialGroup()
  • Loading branch information
vplasencia authored Jun 26, 2024
2 parents 23818d5 + df4a157 commit cbb16d9
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 4 deletions.
24 changes: 24 additions & 0 deletions apps/docs/docs/api-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
```
24 changes: 24 additions & 0 deletions libs/api-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
```
33 changes: 31 additions & 2 deletions libs/api-sdk/src/apiSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
Group,
Invite,
GroupCreationDetails,
GroupUpdateDetails
GroupUpdateDetails,
DashboardUrl
} from "./types"
import checkParameter from "./checkParameter"
import {
Expand All @@ -22,7 +23,8 @@ import {
removeMemberByApiKey,
removeMembersByApiKey,
getGroupsByAdminId,
getGroupsByMemberId
getGroupsByMemberId,
getCredentialGroupJoinUrl
} from "./groups"
import { createInvite, getInvite } from "./invites"

Expand Down Expand Up @@ -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
}
}
32 changes: 31 additions & 1 deletion libs/api-sdk/src/groups.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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
}
26 changes: 25 additions & 1 deletion libs/api-sdk/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
Group,
GroupUpdateDetails,
Invite,
SupportedUrl
SupportedUrl,
DashboardUrl
} from "./types"
import checkParameter from "./checkParameter"

Expand Down Expand Up @@ -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", () => {
Expand Down
6 changes: 6 additions & 0 deletions libs/api-sdk/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit cbb16d9

Please sign in to comment.