Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add/del members by api key #311

Merged
merged 8 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions libs/api-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,18 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc"
await apiSdk.addMemberByApiKey(groupId, memberId, apiKey)
```

\# **addMembersByApiKey**(): _Promise\<void>_

Adds multiple members to a group using an API Key.

```ts
const groupId = "10402173435763029700781503965100"
const memberIds = ["1", "2", "3"]
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc"

await apiSdk.addMembersByApiKey(groupId, memberIds, apiKey)
```

\# **addMemberByInviteCode**(): _Promise\<void>_

Adds a member to a group using an Invite Code.
Expand All @@ -170,3 +182,15 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc"

await apiSdk.removeMemberByApiKey(groupId, memberId, apiKey)
```

\# **removeMembersByApiKey**(): _Promise\<void>_

Removes multiple members from a group using an API Key.

```ts
const groupId = "10402173435763029700781503965100"
const memberIds = ["1", "2", "3"]
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc"

await apiSdk.removeMembersByApiKey(groupId, memberIds, apiKey)
```
34 changes: 33 additions & 1 deletion libs/api-sdk/src/apiSdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {
isGroupMember,
generateMerkleProof,
addMemberByApiKey,
addMembersByApiKey,
addMemberByInviteCode,
removeMemberByApiKey
removeMemberByApiKey,
removeMembersByApiKey
} from "./groups"
import { getInvite } from "./invites"

Expand Down Expand Up @@ -133,6 +135,21 @@ export default class ApiSdk {
await addMemberByApiKey(this._config, groupId, memberId, apiKey)
}

/**
* Adds several members to a group using an API Key.
* @param groupId Group id.
* @param memberIds Member ids.
* @param apiKey API Key.
* @returns undefined.
0xjei marked this conversation as resolved.
Show resolved Hide resolved
*/
async addMembersByApiKey(
groupId: string,
memberIds: string[],
apiKey: string
): Promise<void> {
await addMembersByApiKey(this._config, groupId, memberIds, apiKey)
}

/**
* Adds a member to a group using an Invite Code.
* @param groupId Group id.
Expand Down Expand Up @@ -163,6 +180,21 @@ export default class ApiSdk {
await removeMemberByApiKey(this._config, groupId, memberId, apiKey)
}

/**
* Removes multiple members from a group using an API Key.
* @param groupId Group id.
* @param memberIds Member ids.
* @param apiKey API Key.
* @returns undefined.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

*/
async removeMembersByApiKey(
groupId: string,
memberIds: string[],
apiKey: string
): Promise<void> {
await removeMembersByApiKey(this._config, groupId, memberIds, apiKey)
}

/**
* Returns a specific invite.
* @param inviteCode Invite code.
Expand Down
56 changes: 56 additions & 0 deletions libs/api-sdk/src/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ export async function addMemberByApiKey(
await request(requestUrl, newConfig)
}

/**
* Adds members to a group using an API Key.
* @param groupId Group id.
0xjei marked this conversation as resolved.
Show resolved Hide resolved
* @param memberIds Member ids.
* @param apiKey API Key.
* @returns undefined.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

*/
export async function addMembersByApiKey(
config: object,
groupId: string,
memberIds: string[],
apiKey: string
): Promise<void> {
const requestUrl = `${url}/${groupId}/members`

const newConfig: any = {
method: "post",
data: {
memberIds
},
...config
}

newConfig.headers["x-api-key"] = apiKey

await request(requestUrl, newConfig)
}

/**
* Adds a member to a group using an Invite Code.
* @param groupId Group id.
Expand Down Expand Up @@ -147,3 +175,31 @@ export async function removeMemberByApiKey(

await request(requestUrl, newConfig)
}

/**
* Removes multiple members from a group using an API Key.
* @param groupId Group id.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

* @param memberIds Member ids.
* @param apiKey API Key.
* @returns undefined.
*/
export async function removeMembersByApiKey(
config: object,
groupId: string,
memberIds: string[],
apiKey: string
): Promise<void> {
const requestUrl = `${url}/${groupId}/members`

const newConfig: any = {
method: "delete",
data: {
memberIds
},
...config
}

newConfig.headers["x-api-key"] = apiKey

await request(requestUrl, newConfig)
}
49 changes: 44 additions & 5 deletions libs/api-sdk/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,22 +217,61 @@ describe("Bandada API SDK", () => {
expect(res).toBeUndefined()
})
})
describe("#removeMemberByApiKey", () => {
it("Should remove a member from a group using an API Key", async () => {
describe("#addMembers", () => {
it("Should add multiple members to the group using an API Key", async () => {
requestMocked.mockImplementationOnce(() => Promise.resolve())

const groupId = "10402173435763029700781503965100"
const memberId = "1"
const memberIds = ["1", "2", "3"]
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc"

apiSdk = new ApiSdk(SupportedUrl.DEV)
const res = await apiSdk.removeMemberByApiKey(
const res = await apiSdk.addMembersByApiKey(
groupId,
memberId,
memberIds,
apiKey
)
expect(res).toBeUndefined()
vplasencia marked this conversation as resolved.
Show resolved Hide resolved
})
describe("#removeMemberByApiKey", () => {
it("Should remove a member from a group using an API Key", async () => {
requestMocked.mockImplementationOnce(() =>
Promise.resolve()
)

const groupId = "10402173435763029700781503965100"
const memberId = "1"
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc"

apiSdk = new ApiSdk(SupportedUrl.DEV)
const res = await apiSdk.removeMemberByApiKey(
groupId,
memberId,
apiKey
)
expect(res).toBeUndefined()
})
})

describe("#removeMembersByApiKey", () => {
it("Should remove multiple members from a group using an API Key", async () => {
requestMocked.mockImplementationOnce(() =>
Promise.resolve()
)

const groupId = "10402173435763029700781503965100"
const memberIds = ["1", "2", "3"]
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc"

apiSdk = new ApiSdk(SupportedUrl.DEV)
const res = await apiSdk.removeMembersByApiKey(
groupId,
memberIds,
apiKey
)
expect(res).toBeUndefined()
})
})
})
})
describe("Invites", () => {
Expand Down
Loading