@bandada/api-sdk
Advanced tools
Comparing version
/** | ||
* @module @bandada/api-sdk | ||
* @version 2.6.0 | ||
* @version 2.7.0 | ||
* @file A Typescript SDK for the Bandada API. | ||
@@ -174,2 +174,36 @@ * @copyright Ethereum Foundation 2023 | ||
/** | ||
* Returns the list of groups by group ids. | ||
* @param groupIds Group ids. | ||
* @returns List of groups by group ids. | ||
*/ | ||
function getGroupsByGroupIds(config, groupIds) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestUrl, _i, groupIds_1, groupId, groups; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestUrl = "".concat(url$1, "?"); | ||
for (_i = 0, groupIds_1 = groupIds; _i < groupIds_1.length; _i++) { | ||
groupId = groupIds_1[_i]; | ||
requestUrl += "&groupIds=".concat(groupId); | ||
} | ||
return [4 /*yield*/, utils.request(requestUrl, config)]; | ||
case 1: | ||
groups = _a.sent(); | ||
groups = groups.map(function (group) { | ||
var credentials; | ||
try { | ||
credentials = JSON.parse(group.credentials); | ||
} | ||
catch (error) { | ||
credentials = null; | ||
} | ||
return __assign(__assign({}, group), { credentials: credentials }); | ||
}); | ||
return [2 /*return*/, groups]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Creates one or more groups with the provided details. | ||
@@ -442,2 +476,17 @@ * @param groupsCreationDetails Data to create the groups. | ||
/** | ||
* Adds a member to multiple groups. | ||
* @param groupIds Array of group ids. | ||
* @param memberId Member id. | ||
* @param apiKey API Key of the admin. | ||
* @returns Array of the groups of added member. | ||
*/ | ||
function addMemberToGroupsByApiKey(config, groupIds, memberId, apiKey) { | ||
var newConfig = __assign({ method: "post", data: { | ||
groupIds: groupIds | ||
} }, config); | ||
newConfig.headers["x-api-key"] = apiKey; | ||
var req = utils.request("".concat(url$1, "/members/").concat(memberId), newConfig); | ||
return req; | ||
} | ||
/** | ||
* Removes a member from a group using an API Key. | ||
@@ -699,2 +748,20 @@ * @param groupId Group id. | ||
/** | ||
* Returns the list of groups by group ids. | ||
* @param groupIds Group ids. | ||
* @returns List of groups by group ids. | ||
*/ | ||
ApiSdk.prototype.getGroupsByGroupIds = function (groupIds) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var groups; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, getGroupsByGroupIds(this._config, groupIds)]; | ||
case 1: | ||
groups = _a.sent(); | ||
return [2 /*return*/, groups]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Creates a group using the API key. | ||
@@ -939,2 +1006,21 @@ * @param groupCreationDetails Data to create the group. | ||
/** | ||
* Adds a member to multiple groups using an API Key. | ||
* @param groupIds Array of group ids. | ||
* @param memberId Member id. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns Array of the groups of added member. | ||
*/ | ||
ApiSdk.prototype.addMemberToGroupsByApiKey = function (groupIds, memberId, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, addMemberToGroupsByApiKey(this._config, groupIds, memberId, apiKey)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Removes a member from a group using an API Key. | ||
@@ -941,0 +1027,0 @@ * @param groupId Group id. |
@@ -39,2 +39,8 @@ import { SupportedUrl, Group, Invite, GroupCreationDetails, GroupUpdateDetails, DashboardUrl } from "./types"; | ||
/** | ||
* Returns the list of groups by group ids. | ||
* @param groupIds Group ids. | ||
* @returns List of groups by group ids. | ||
*/ | ||
getGroupsByGroupIds(groupIds: string[]): Promise<Group[]>; | ||
/** | ||
* Creates a group using the API key. | ||
@@ -128,2 +134,10 @@ * @param groupCreationDetails Data to create the group. | ||
/** | ||
* Adds a member to multiple groups using an API Key. | ||
* @param groupIds Array of group ids. | ||
* @param memberId Member id. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns Array of the groups of added member. | ||
*/ | ||
addMemberToGroupsByApiKey(groupIds: string[], memberId: string, apiKey: string): Promise<void>; | ||
/** | ||
* Removes a member from a group using an API Key. | ||
@@ -130,0 +144,0 @@ * @param groupId Group id. |
@@ -20,2 +20,8 @@ import type { GroupCreationDetails, Group, GroupUpdateDetails, DashboardUrl } from "./types"; | ||
/** | ||
* Returns the list of groups by group ids. | ||
* @param groupIds Group ids. | ||
* @returns List of groups by group ids. | ||
*/ | ||
export declare function getGroupsByGroupIds(config: object, groupIds: string[]): Promise<Group[]>; | ||
/** | ||
* Creates one or more groups with the provided details. | ||
@@ -100,2 +106,10 @@ * @param groupsCreationDetails Data to create the groups. | ||
/** | ||
* Adds a member to multiple groups. | ||
* @param groupIds Array of group ids. | ||
* @param memberId Member id. | ||
* @param apiKey API Key of the admin. | ||
* @returns Array of the groups of added member. | ||
*/ | ||
export declare function addMemberToGroupsByApiKey(config: object, groupIds: string[], memberId: string, apiKey: string): Promise<void>; | ||
/** | ||
* Removes a member from a group using an API Key. | ||
@@ -102,0 +116,0 @@ * @param groupId Group id. |
{ | ||
"name": "@bandada/api-sdk", | ||
"version": "2.6.0", | ||
"version": "2.7.0", | ||
"description": "A Typescript SDK for the Bandada API.", | ||
@@ -33,3 +33,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@bandada/utils": "2.6.0" | ||
"@bandada/utils": "2.7.0" | ||
}, | ||
@@ -36,0 +36,0 @@ "devDependencies": { |
@@ -348,2 +348,17 @@ <p align="center"> | ||
## Get groups by group ids | ||
\# **getGroupByGroupIds**(): _Promise\<Group[]>_ | ||
Returns the list of groups by group ids. | ||
```ts | ||
const groupIds = [ | ||
"10402173435763029700781503965100", | ||
"20402173435763029700781503965200" | ||
] | ||
const groups = await apiSdk.getGroupsByGroupIds(groupIds) | ||
``` | ||
## Is group member | ||
@@ -417,2 +432,19 @@ | ||
## Add member to groups using an API Key | ||
\# **addMemberToGroupsByApiKey**(): _Promise\<void>_ | ||
Adds a member to multiple groups using an API Key. | ||
```ts | ||
const groupIds = [ | ||
"10402173435763029700781503965100", | ||
"20402173435763029700781503965200" | ||
] | ||
const memberId = "1" | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
await apiSdk.addMemberToGroupsByApiKey(groupIds, memberId, apiKey) | ||
``` | ||
## Remove member using an API Key | ||
@@ -419,0 +451,0 @@ |
@@ -27,4 +27,6 @@ import { | ||
getGroupsByMemberId, | ||
getGroupsByGroupIds, | ||
getCredentialGroupJoinUrl, | ||
getMultipleCredentialsGroupJoinUrl | ||
getMultipleCredentialsGroupJoinUrl, | ||
addMemberToGroupsByApiKey | ||
} from "./groups" | ||
@@ -117,2 +119,13 @@ import { createInvite, getInvite, redeemInvite } from "./invites" | ||
/** | ||
* Returns the list of groups by group ids. | ||
* @param groupIds Group ids. | ||
* @returns List of groups by group ids. | ||
*/ | ||
async getGroupsByGroupIds(groupIds: string[]): Promise<Group[]> { | ||
const groups = await getGroupsByGroupIds(this._config, groupIds) | ||
return groups | ||
} | ||
/** | ||
* Creates a group using the API key. | ||
@@ -320,2 +333,22 @@ * @param groupCreationDetails Data to create the group. | ||
/** | ||
* Adds a member to multiple groups using an API Key. | ||
* @param groupIds Array of group ids. | ||
* @param memberId Member id. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns Array of the groups of added member. | ||
*/ | ||
async addMemberToGroupsByApiKey( | ||
groupIds: string[], | ||
memberId: string, | ||
apiKey: string | ||
): Promise<void> { | ||
await addMemberToGroupsByApiKey( | ||
this._config, | ||
groupIds, | ||
memberId, | ||
apiKey | ||
) | ||
} | ||
/** | ||
* Removes a member from a group using an API Key. | ||
@@ -322,0 +355,0 @@ * @param groupId Group id. |
@@ -99,2 +99,37 @@ import { request } from "@bandada/utils" | ||
/** | ||
* Returns the list of groups by group ids. | ||
* @param groupIds Group ids. | ||
* @returns List of groups by group ids. | ||
*/ | ||
export async function getGroupsByGroupIds( | ||
config: object, | ||
groupIds: string[] | ||
): Promise<Group[]> { | ||
let requestUrl = `${url}?` | ||
for (const groupId of groupIds) { | ||
requestUrl += `&groupIds=${groupId}` | ||
} | ||
let groups = await request(requestUrl, config) | ||
groups = groups.map((group: any) => { | ||
let credentials | ||
try { | ||
credentials = JSON.parse(group.credentials) | ||
} catch (error) { | ||
credentials = null | ||
} | ||
return { | ||
...group, | ||
credentials | ||
} | ||
}) | ||
return groups | ||
} | ||
/** | ||
* Creates one or more groups with the provided details. | ||
@@ -380,2 +415,30 @@ * @param groupsCreationDetails Data to create the groups. | ||
/** | ||
* Adds a member to multiple groups. | ||
* @param groupIds Array of group ids. | ||
* @param memberId Member id. | ||
* @param apiKey API Key of the admin. | ||
* @returns Array of the groups of added member. | ||
*/ | ||
export function addMemberToGroupsByApiKey( | ||
config: object, | ||
groupIds: string[], | ||
memberId: string, | ||
apiKey: string | ||
): Promise<void> { | ||
const newConfig: any = { | ||
method: "post", | ||
data: { | ||
groupIds | ||
}, | ||
...config | ||
} | ||
newConfig.headers["x-api-key"] = apiKey | ||
const req = request(`${url}/members/${memberId}`, newConfig) | ||
return req | ||
} | ||
/** | ||
* Removes a member from a group using an API Key. | ||
@@ -382,0 +445,0 @@ * @param groupId Group id. |
@@ -607,2 +607,55 @@ import { request } from "@bandada/utils" | ||
}) | ||
describe("getGroupsByGroupIds", () => { | ||
it("Should return all groups by group ids", async () => { | ||
requestMocked.mockImplementationOnce(() => | ||
Promise.resolve([ | ||
{ | ||
id: "10402173435763029700781503965100", | ||
name: "Group1", | ||
description: "This is a new group", | ||
admin: "0xdf558148e66850ac48dbe2c8119b0eefa7d08bfd19c997c90a142eb97916b847", | ||
treeDepth: 16, | ||
fingerprintDuration: 3600, | ||
createdAt: "2023-07-15T08:21:05.000Z", | ||
members: [], | ||
credentials: null | ||
} | ||
]) | ||
) | ||
const groupIds = ["10402173435763029700781503965100"] | ||
const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const groups: Group[] = await apiSdk.getGroupsByGroupIds( | ||
groupIds | ||
) | ||
expect(groups).toHaveLength(1) | ||
}) | ||
it("Should return all groups by group ids and null in the credentials that don't have a valid JSON string", async () => { | ||
requestMocked.mockImplementationOnce(() => | ||
Promise.resolve([ | ||
{ | ||
id: "10402173435763029700781503965100", | ||
name: "Group1", | ||
description: "This is a new group", | ||
admin: "0xdf558148e66850ac48dbe2c8119b0eefa7d08bfd19c997c90a142eb97916b847", | ||
treeDepth: 16, | ||
fingerprintDuration: 3600, | ||
createdAt: "2023-07-15T08:21:05.000Z", | ||
members: [], | ||
credentials: {} | ||
} | ||
]) | ||
) | ||
const groupIds = ["10402173435763029700781503965100"] | ||
const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const groups: Group[] = await apiSdk.getGroupsByGroupIds( | ||
groupIds | ||
) | ||
expect(groups).toHaveLength(1) | ||
expect(groups[0].credentials).toBeNull() | ||
}) | ||
}) | ||
describe("#getGroup", () => { | ||
@@ -799,82 +852,101 @@ it("Should return a group", async () => { | ||
}) | ||
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" | ||
describe("#addMemberToGroups", () => { | ||
it("Should add a member to multiple groups using an API Key", async () => { | ||
requestMocked.mockImplementationOnce(() => Promise.resolve()) | ||
const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const res = await apiSdk.removeMemberByApiKey( | ||
groupId, | ||
memberId, | ||
apiKey | ||
) | ||
expect(res).toBeUndefined() | ||
}) | ||
const groupIds = [ | ||
"10402173435763029700781503965100", | ||
"20402173435763029700781503965200" | ||
] | ||
const memberId = "1" | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const res = await apiSdk.addMemberToGroupsByApiKey( | ||
groupIds, | ||
memberId, | ||
apiKey | ||
) | ||
expect(res).toBeUndefined() | ||
}) | ||
}) | ||
describe("#removeMembersByApiKey", () => { | ||
it("Should remove multiple members from a group using an API Key", async () => { | ||
requestMocked.mockImplementationOnce(() => | ||
Promise.resolve() | ||
) | ||
describe("#removeMemberByApiKey", () => { | ||
it("Should remove a member 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" | ||
const groupId = "10402173435763029700781503965100" | ||
const memberId = "1" | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const res = await apiSdk.removeMembersByApiKey( | ||
groupId, | ||
memberIds, | ||
apiKey | ||
) | ||
expect(res).toBeUndefined() | ||
}) | ||
const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const res = await apiSdk.removeMemberByApiKey( | ||
groupId, | ||
memberId, | ||
apiKey | ||
) | ||
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" | ||
describe("#removeMembersByApiKey", () => { | ||
it("Should remove multiple members from a group using an API Key", async () => { | ||
requestMocked.mockImplementationOnce(() => Promise.resolve()) | ||
const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const res = apiSdk.getCredentialGroupJoinUrl( | ||
dashboardUrl, | ||
groupId, | ||
commitment, | ||
providerName, | ||
redirectUri | ||
) | ||
const groupId = "10402173435763029700781503965100" | ||
const memberIds = ["1", "2", "3"] | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
const url = `${dashboardUrl}/credentials?group=${groupId}&member=${commitment}&provider=${providerName}&redirect_uri=${redirectUri}?redirect=true` | ||
const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const res = await apiSdk.removeMembersByApiKey( | ||
groupId, | ||
memberIds, | ||
apiKey | ||
) | ||
expect(res).toBeUndefined() | ||
}) | ||
}) | ||
expect(res).toBe(url) | ||
}) | ||
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" | ||
const apiSdk: 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("#getMultipleCredentialGroupJoinUrl", () => { | ||
it("Should generate a custom url for joining a multiple credential group", async () => { | ||
const dashboardUrl = DashboardUrl.DEV | ||
const groupId = "10402173435763029700781503965100" | ||
const commitment = "1" | ||
describe("#getMultipleCredentialGroupJoinUrl", () => { | ||
it("Should generate a custom url for joining a multiple credential group", async () => { | ||
const dashboardUrl = DashboardUrl.DEV | ||
const groupId = "10402173435763029700781503965100" | ||
const commitment = "1" | ||
const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const res = apiSdk.getMultipleCredentialsGroupJoinUrl( | ||
dashboardUrl, | ||
groupId, | ||
commitment | ||
) | ||
const apiSdk: ApiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const res = apiSdk.getMultipleCredentialsGroupJoinUrl( | ||
dashboardUrl, | ||
groupId, | ||
commitment | ||
) | ||
const url = `${dashboardUrl}/credentials?group=${groupId}&member=${commitment}&type=multiple` | ||
const url = `${dashboardUrl}/credentials?group=${groupId}&member=${commitment}&type=multiple` | ||
expect(res).toBe(url) | ||
}) | ||
expect(res).toBe(url) | ||
}) | ||
@@ -881,0 +953,0 @@ }) |
Sorry, the diff of this file is not supported yet
192367
7.59%4722
7.88%559
6.07%+ Added
- Removed
Updated