@bandada/api-sdk
Advanced tools
Comparing version 2.1.1 to 2.2.0
/** | ||
* @module @bandada/api-sdk | ||
* @version 2.1.1 | ||
* @version 2.2.0 | ||
* @file A Typescript SDK for the Bandada API. | ||
* @copyright Ethereum Foundation 2023 | ||
* @license MIT | ||
* @see [Github]{@link https://github.com/privacy-scaling-explorations/bandada/tree/main/libs/api-sdk} | ||
* @see [Github]{@link https://github.com/bandada-infra/bandada/tree/main/libs/api-sdk} | ||
*/ | ||
@@ -99,2 +99,123 @@ 'use strict'; | ||
/** | ||
* Creates one or more groups with the provided details. | ||
* @param groupsData Data to create the groups. | ||
* @param apiKey API Key of the admin. | ||
* @returns Array of the created groups. | ||
*/ | ||
function createGroups(config, groupsData, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var newConfig, req; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
newConfig = __assign({ method: "post", data: { | ||
groupsData: groupsData | ||
} }, config); | ||
newConfig.headers["x-api-key"] = apiKey; | ||
return [4 /*yield*/, utils.request(url$1, newConfig)]; | ||
case 1: | ||
req = _a.sent(); | ||
return [2 /*return*/, req]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Removes the group. | ||
* @param groupId The group id. | ||
* @param apiKey API Key of the admin. | ||
*/ | ||
function removeGroup(config, groupId, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestUrl, newConfig, req; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestUrl = "".concat(url$1, "/").concat(groupId); | ||
newConfig = __assign({ method: "delete" }, config); | ||
newConfig.headers["x-api-key"] = apiKey; | ||
return [4 /*yield*/, utils.request(requestUrl, newConfig)]; | ||
case 1: | ||
req = _a.sent(); | ||
return [2 /*return*/, req]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Removes one or more groups. | ||
* @param groupIds The group ids. | ||
* @param apiKey API Key of the admin. | ||
*/ | ||
function removeGroups(config, groupIds, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var newConfig, req; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
newConfig = __assign({ method: "delete", data: { | ||
groupIds: groupIds | ||
} }, config); | ||
newConfig.headers["x-api-key"] = apiKey; | ||
return [4 /*yield*/, utils.request(url$1, newConfig)]; | ||
case 1: | ||
req = _a.sent(); | ||
return [2 /*return*/, req]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Updates the group. | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param apiKey API Key of the admin. | ||
* @return The updated group. | ||
*/ | ||
function updateGroup(config, groupId, groupData, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestUrl, newConfig, req; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestUrl = "".concat(url$1, "/").concat(groupId); | ||
newConfig = __assign({ method: "put", data: { | ||
groupData: groupData | ||
} }, config); | ||
newConfig.headers["x-api-key"] = apiKey; | ||
return [4 /*yield*/, utils.request(requestUrl, newConfig)]; | ||
case 1: | ||
req = _a.sent(); | ||
return [2 /*return*/, req]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Updates the groups. | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param apiKey API Key of the admin. | ||
* @return The updated groups. | ||
*/ | ||
function updateGroups(config, groupIds, groupsData, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var newConfig, req; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
newConfig = __assign({ method: "put", data: { | ||
groupIds: groupIds, | ||
groupsData: groupsData | ||
} }, config); | ||
newConfig.headers["x-api-key"] = apiKey; | ||
return [4 /*yield*/, utils.request(url$1, newConfig)]; | ||
case 1: | ||
req = _a.sent(); | ||
return [2 /*return*/, req]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Returns a specific group. | ||
@@ -380,2 +501,106 @@ * @param groupId Group id. | ||
/** | ||
* Creates a group using the API key. | ||
* @param groupData Data to create the group. | ||
* @param apiKey The API key of the admin of the group. | ||
* @returns The created group. | ||
*/ | ||
ApiSdk.prototype.createGroup = function (groupData, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var groups; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, createGroups(this._config, [groupData], apiKey)]; | ||
case 1: | ||
groups = _a.sent(); | ||
return [2 /*return*/, groups[0]]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Creates one or more groups using the API key. | ||
* @param groupsData Data to create the groups. | ||
* @param apiKey The API key of the admin of the groups. | ||
* @returns The created groups. | ||
*/ | ||
ApiSdk.prototype.createGroups = function (groupsData, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var groups; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, createGroups(this._config, groupsData, apiKey)]; | ||
case 1: | ||
groups = _a.sent(); | ||
return [2 /*return*/, groups]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Removes a group using the API key. | ||
* @param groupId The group id. | ||
* @param apiKey The API key of the admin of the group. | ||
* @returns undefined. | ||
*/ | ||
ApiSdk.prototype.removeGroup = function (groupId, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, removeGroup(this._config, groupId, apiKey)]; | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Removes one or more group using the API key. | ||
* @param groupIds The group ids. | ||
* @param apiKey The API key of the admin of the groups. | ||
* @returns undefined. | ||
*/ | ||
ApiSdk.prototype.removeGroups = function (groupIds, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, removeGroups(this._config, groupIds, apiKey)]; | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Update a specific group using the API key. | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param apiKey The API key of the admin of the group. | ||
* @returns The updated group. | ||
*/ | ||
ApiSdk.prototype.updateGroup = function (groupId, groupData, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var group; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, updateGroup(this._config, groupId, groupData, apiKey)]; | ||
case 1: | ||
group = _a.sent(); | ||
return [2 /*return*/, group]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Updats one or more groups using the API key. | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param apiKey The API key of the admin of the groups. | ||
* @returns The updated groups. | ||
*/ | ||
ApiSdk.prototype.updateGroups = function (groupIds, groupsData, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var groups; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, updateGroups(this._config, groupIds, groupsData, apiKey)]; | ||
case 1: | ||
groups = _a.sent(); | ||
return [2 /*return*/, groups]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Returns a specific group. | ||
@@ -440,3 +665,3 @@ * @param groupId Group id. | ||
* @param memberId Member id. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -460,3 +685,3 @@ */ | ||
* @param memberIds Member ids. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -499,3 +724,3 @@ */ | ||
* @param memberId Member id. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -519,3 +744,3 @@ */ | ||
* @param memberIds Member ids. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -522,0 +747,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
import { SupportedUrl, GroupResponse, InviteResponse } from "./types"; | ||
import { SupportedUrl, GroupResponse, InviteResponse, GroupRequest, GroupUpdateRequest } from "./types"; | ||
export default class ApiSdk { | ||
@@ -27,2 +27,46 @@ private _url; | ||
/** | ||
* Creates a group using the API key. | ||
* @param groupData Data to create the group. | ||
* @param apiKey The API key of the admin of the group. | ||
* @returns The created group. | ||
*/ | ||
createGroup(groupData: GroupRequest, apiKey: string): Promise<GroupResponse>; | ||
/** | ||
* Creates one or more groups using the API key. | ||
* @param groupsData Data to create the groups. | ||
* @param apiKey The API key of the admin of the groups. | ||
* @returns The created groups. | ||
*/ | ||
createGroups(groupsData: Array<GroupRequest>, apiKey: string): Promise<Array<GroupResponse>>; | ||
/** | ||
* Removes a group using the API key. | ||
* @param groupId The group id. | ||
* @param apiKey The API key of the admin of the group. | ||
* @returns undefined. | ||
*/ | ||
removeGroup(groupId: string, apiKey: string): Promise<void>; | ||
/** | ||
* Removes one or more group using the API key. | ||
* @param groupIds The group ids. | ||
* @param apiKey The API key of the admin of the groups. | ||
* @returns undefined. | ||
*/ | ||
removeGroups(groupIds: Array<string>, apiKey: string): Promise<void>; | ||
/** | ||
* Update a specific group using the API key. | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param apiKey The API key of the admin of the group. | ||
* @returns The updated group. | ||
*/ | ||
updateGroup(groupId: string, groupData: GroupUpdateRequest, apiKey: string): Promise<GroupResponse>; | ||
/** | ||
* Updats one or more groups using the API key. | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param apiKey The API key of the admin of the groups. | ||
* @returns The updated groups. | ||
*/ | ||
updateGroups(groupIds: Array<string>, groupsData: Array<GroupUpdateRequest>, apiKey: string): Promise<Array<GroupResponse>>; | ||
/** | ||
* Returns a specific group. | ||
@@ -51,3 +95,3 @@ * @param groupId Group id. | ||
* @param memberId Member id. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -60,3 +104,3 @@ */ | ||
* @param memberIds Member ids. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -77,3 +121,3 @@ */ | ||
* @param memberId Member id. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -86,3 +130,3 @@ */ | ||
* @param memberIds Member ids. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -89,0 +133,0 @@ */ |
@@ -1,2 +0,2 @@ | ||
import { GroupResponse } from "./types"; | ||
import { GroupRequest, GroupResponse, GroupUpdateRequest } from "./types"; | ||
/** | ||
@@ -8,2 +8,37 @@ * Returns the list of groups. | ||
/** | ||
* Creates one or more groups with the provided details. | ||
* @param groupsData Data to create the groups. | ||
* @param apiKey API Key of the admin. | ||
* @returns Array of the created groups. | ||
*/ | ||
export declare function createGroups(config: object, groupsData: Array<GroupRequest>, apiKey: string): Promise<Array<GroupResponse>>; | ||
/** | ||
* Removes the group. | ||
* @param groupId The group id. | ||
* @param apiKey API Key of the admin. | ||
*/ | ||
export declare function removeGroup(config: object, groupId: string, apiKey: string): Promise<void>; | ||
/** | ||
* Removes one or more groups. | ||
* @param groupIds The group ids. | ||
* @param apiKey API Key of the admin. | ||
*/ | ||
export declare function removeGroups(config: object, groupIds: Array<string>, apiKey: string): Promise<void>; | ||
/** | ||
* Updates the group. | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param apiKey API Key of the admin. | ||
* @return The updated group. | ||
*/ | ||
export declare function updateGroup(config: object, groupId: string, groupData: GroupUpdateRequest, apiKey: string): Promise<GroupResponse>; | ||
/** | ||
* Updates the groups. | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param apiKey API Key of the admin. | ||
* @return The updated groups. | ||
*/ | ||
export declare function updateGroups(config: object, groupIds: Array<string>, groupsData: Array<GroupUpdateRequest>, apiKey: string): Promise<Array<GroupResponse>>; | ||
/** | ||
* Returns a specific group. | ||
@@ -10,0 +45,0 @@ * @param groupId Group id. |
@@ -16,2 +16,22 @@ export type GroupResponse = { | ||
}; | ||
export type GroupRequest = { | ||
name: string; | ||
description: string; | ||
treeDepth: number; | ||
fingerprintDuration: number; | ||
id?: string; | ||
credentials?: { | ||
id: string; | ||
criteria: Record<string, any>; | ||
}; | ||
}; | ||
export type GroupUpdateRequest = { | ||
description: string; | ||
treeDepth: number; | ||
fingerprintDuration: number; | ||
credentials?: { | ||
id: string; | ||
criteria: Record<string, any>; | ||
}; | ||
}; | ||
type Group = { | ||
@@ -18,0 +38,0 @@ id: string; |
{ | ||
"name": "@bandada/api-sdk", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "A Typescript SDK for the Bandada API.", | ||
@@ -18,6 +18,6 @@ "license": "MIT", | ||
], | ||
"repository": "https://github.com/privacy-scaling-explorations/bandada", | ||
"homepage": "https://github.com/privacy-scaling-explorations/bandada/tree/main/libs/api-sdk", | ||
"repository": "https://github.com/bandada-infra/bandada", | ||
"homepage": "https://github.com/bandada-infra/bandada/tree/main/libs/api-sdk", | ||
"bugs": { | ||
"url": "https://github.com/privacy-scaling-explorations/bandada.git/issues" | ||
"url": "https://github.com/bandada-infra/bandada.git/issues" | ||
}, | ||
@@ -33,3 +33,3 @@ "scripts": { | ||
"dependencies": { | ||
"@bandada/utils": "2.1.1" | ||
"@bandada/utils": "2.2.0" | ||
}, | ||
@@ -36,0 +36,0 @@ "devDependencies": { |
@@ -9,7 +9,7 @@ <p align="center"> | ||
<p align="center"> | ||
<a href="https://github.com/privacy-scaling-explorations/bandada"> | ||
<a href="https://github.com/bandada-infra/bandada"> | ||
<img src="https://img.shields.io/badge/project-Bandada-blue.svg?style=flat-square"> | ||
</a> | ||
<a href="https://github.com/privacy-scaling-explorations/bandada/blob/main/LICENSE"> | ||
<img alt="Github license" src="https://img.shields.io/github/license/privacy-scaling-explorations/bandada.svg?style=flat-square"> | ||
<a href="https://github.com/bandada-infra/bandada/blob/main/LICENSE"> | ||
<img alt="Github license" src="https://img.shields.io/github/license/bandada-infra/bandada.svg?style=flat-square"> | ||
</a> | ||
@@ -32,11 +32,11 @@ <a href="https://www.npmjs.com/package/@bandada/api-sdk"> | ||
<h4> | ||
<a href="https://github.com/privacy-scaling-explorations/bandada/blob/main/CONTRIBUTING.md"> | ||
<a href="https://github.com/bandada-infra/bandada/blob/main/CONTRIBUTING.md"> | ||
👥 Contributing | ||
</a> | ||
<span> | </span> | ||
<a href="https://github.com/privacy-scaling-explorations/bandada/blob/main/CODE_OF_CONDUCT.md"> | ||
<a href="https://github.com/bandada-infra/bandada/blob/main/CODE_OF_CONDUCT.md"> | ||
🤝 Code of conduct | ||
</a> | ||
<span> | </span> | ||
<a href="https://github.com/privacy-scaling-explorations/bandada/contribute"> | ||
<a href="https://github.com/bandada-infra/bandada/contribute"> | ||
🔎 Issues | ||
@@ -43,0 +43,0 @@ </a> |
@@ -1,2 +0,8 @@ | ||
import { SupportedUrl, GroupResponse, InviteResponse } from "./types" | ||
import { | ||
SupportedUrl, | ||
GroupResponse, | ||
InviteResponse, | ||
GroupRequest, | ||
GroupUpdateRequest | ||
} from "./types" | ||
import checkParameter from "./checkParameter" | ||
@@ -6,2 +12,7 @@ import { | ||
getGroup, | ||
createGroups, | ||
removeGroup, | ||
removeGroups, | ||
updateGroup, | ||
updateGroups, | ||
isGroupMember, | ||
@@ -79,2 +90,96 @@ generateMerkleProof, | ||
/** | ||
* Creates a group using the API key. | ||
* @param groupData Data to create the group. | ||
* @param apiKey The API key of the admin of the group. | ||
* @returns The created group. | ||
*/ | ||
async createGroup( | ||
groupData: GroupRequest, | ||
apiKey: string | ||
): Promise<GroupResponse> { | ||
const groups = await createGroups(this._config, [groupData], apiKey) | ||
return groups[0] | ||
} | ||
/** | ||
* Creates one or more groups using the API key. | ||
* @param groupsData Data to create the groups. | ||
* @param apiKey The API key of the admin of the groups. | ||
* @returns The created groups. | ||
*/ | ||
async createGroups( | ||
groupsData: Array<GroupRequest>, | ||
apiKey: string | ||
): Promise<Array<GroupResponse>> { | ||
const groups = await createGroups(this._config, groupsData, apiKey) | ||
return groups | ||
} | ||
/** | ||
* Removes a group using the API key. | ||
* @param groupId The group id. | ||
* @param apiKey The API key of the admin of the group. | ||
* @returns undefined. | ||
*/ | ||
async removeGroup(groupId: string, apiKey: string): Promise<void> { | ||
return removeGroup(this._config, groupId, apiKey) | ||
} | ||
/** | ||
* Removes one or more group using the API key. | ||
* @param groupIds The group ids. | ||
* @param apiKey The API key of the admin of the groups. | ||
* @returns undefined. | ||
*/ | ||
async removeGroups(groupIds: Array<string>, apiKey: string): Promise<void> { | ||
return removeGroups(this._config, groupIds, apiKey) | ||
} | ||
/** | ||
* Update a specific group using the API key. | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param apiKey The API key of the admin of the group. | ||
* @returns The updated group. | ||
*/ | ||
async updateGroup( | ||
groupId: string, | ||
groupData: GroupUpdateRequest, | ||
apiKey: string | ||
): Promise<GroupResponse> { | ||
const group = await updateGroup( | ||
this._config, | ||
groupId, | ||
groupData, | ||
apiKey | ||
) | ||
return group | ||
} | ||
/** | ||
* Updats one or more groups using the API key. | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param apiKey The API key of the admin of the groups. | ||
* @returns The updated groups. | ||
*/ | ||
async updateGroups( | ||
groupIds: Array<string>, | ||
groupsData: Array<GroupUpdateRequest>, | ||
apiKey: string | ||
): Promise<Array<GroupResponse>> { | ||
const groups = await updateGroups( | ||
this._config, | ||
groupIds, | ||
groupsData, | ||
apiKey | ||
) | ||
return groups | ||
} | ||
/** | ||
* Returns a specific group. | ||
@@ -125,3 +230,3 @@ * @param groupId Group id. | ||
* @param memberId Member id. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -141,3 +246,3 @@ */ | ||
* @param memberIds Member ids. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -172,3 +277,3 @@ */ | ||
* @param memberId Member id. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -188,3 +293,3 @@ */ | ||
* @param memberIds Member ids. | ||
* @param apiKey API Key. | ||
* @param apiKey API Key of the admin of the group. | ||
* @returns undefined. | ||
@@ -191,0 +296,0 @@ */ |
import { request } from "@bandada/utils" | ||
import { GroupResponse } from "./types" | ||
import { GroupRequest, GroupResponse, GroupUpdateRequest } from "./types" | ||
@@ -22,2 +22,136 @@ const url = "/groups" | ||
/** | ||
* Creates one or more groups with the provided details. | ||
* @param groupsData Data to create the groups. | ||
* @param apiKey API Key of the admin. | ||
* @returns Array of the created groups. | ||
*/ | ||
export async function createGroups( | ||
config: object, | ||
groupsData: Array<GroupRequest>, | ||
apiKey: string | ||
): Promise<Array<GroupResponse>> { | ||
const newConfig: any = { | ||
method: "post", | ||
data: { | ||
groupsData | ||
}, | ||
...config | ||
} | ||
newConfig.headers["x-api-key"] = apiKey | ||
const req = await request(url, newConfig) | ||
return req | ||
} | ||
/** | ||
* Removes the group. | ||
* @param groupId The group id. | ||
* @param apiKey API Key of the admin. | ||
*/ | ||
export async function removeGroup( | ||
config: object, | ||
groupId: string, | ||
apiKey: string | ||
): Promise<void> { | ||
const requestUrl = `${url}/${groupId}` | ||
const newConfig: any = { | ||
method: "delete", | ||
...config | ||
} | ||
newConfig.headers["x-api-key"] = apiKey | ||
const req = await request(requestUrl, newConfig) | ||
return req | ||
} | ||
/** | ||
* Removes one or more groups. | ||
* @param groupIds The group ids. | ||
* @param apiKey API Key of the admin. | ||
*/ | ||
export async function removeGroups( | ||
config: object, | ||
groupIds: Array<string>, | ||
apiKey: string | ||
): Promise<void> { | ||
const newConfig: any = { | ||
method: "delete", | ||
data: { | ||
groupIds | ||
}, | ||
...config | ||
} | ||
newConfig.headers["x-api-key"] = apiKey | ||
const req = await request(url, newConfig) | ||
return req | ||
} | ||
/** | ||
* Updates the group. | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param apiKey API Key of the admin. | ||
* @return The updated group. | ||
*/ | ||
export async function updateGroup( | ||
config: object, | ||
groupId: string, | ||
groupData: GroupUpdateRequest, | ||
apiKey: string | ||
): Promise<GroupResponse> { | ||
const requestUrl = `${url}/${groupId}` | ||
const newConfig: any = { | ||
method: "put", | ||
data: { | ||
groupData | ||
}, | ||
...config | ||
} | ||
newConfig.headers["x-api-key"] = apiKey | ||
const req = await request(requestUrl, newConfig) | ||
return req | ||
} | ||
/** | ||
* Updates the groups. | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param apiKey API Key of the admin. | ||
* @return The updated groups. | ||
*/ | ||
export async function updateGroups( | ||
config: object, | ||
groupIds: Array<string>, | ||
groupsData: Array<GroupUpdateRequest>, | ||
apiKey: string | ||
): Promise<Array<GroupResponse>> { | ||
const newConfig: any = { | ||
method: "put", | ||
data: { | ||
groupIds, | ||
groupsData | ||
}, | ||
...config | ||
} | ||
newConfig.headers["x-api-key"] = apiKey | ||
const req = await request(url, newConfig) | ||
return req | ||
} | ||
/** | ||
* Returns a specific group. | ||
@@ -24,0 +158,0 @@ * @param groupId Group id. |
import { request } from "@bandada/utils" | ||
import ApiSdk from "./apiSdk" | ||
import { GroupResponse, InviteResponse, SupportedUrl } from "./types" | ||
import { | ||
GroupRequest, | ||
GroupResponse, | ||
GroupUpdateRequest, | ||
InviteResponse, | ||
SupportedUrl | ||
} from "./types" | ||
jest.mock("@bandada/utils", () => ({ | ||
__esModule: true, | ||
request: jest.fn() | ||
})) | ||
jest.mock("@bandada/utils", () => { | ||
const originalModule = jest.requireActual("@bandada/utils") | ||
return { | ||
__esModule: true, | ||
...originalModule, | ||
request: jest.fn() | ||
} | ||
}) | ||
const requestMocked = request as jest.MockedFunction<typeof request> | ||
@@ -72,2 +83,242 @@ | ||
describe("Groups", () => { | ||
describe("#createGroup", () => { | ||
it("Should create a group", async () => { | ||
const expectedGroup: GroupRequest = { | ||
id: "10402173435763029700781503965100", | ||
name: "Group1", | ||
description: "This is a new group", | ||
treeDepth: 16, | ||
fingerprintDuration: 3600 | ||
} | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
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 | ||
} | ||
]) | ||
) | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const group: GroupResponse = await apiSdk.createGroup( | ||
expectedGroup, | ||
apiKey | ||
) | ||
expect(group.id).toBe(expectedGroup.id) | ||
expect(group.description).toBe(expectedGroup.description) | ||
expect(group.name).toBe(expectedGroup.name) | ||
expect(group.treeDepth).toBe(expectedGroup.treeDepth) | ||
expect(group.fingerprintDuration).toBe( | ||
group.fingerprintDuration | ||
) | ||
expect(group.members).toHaveLength(0) | ||
expect(group.credentials).toBeNull() | ||
}) | ||
}) | ||
describe("#createGroups", () => { | ||
it("Should create the groups", async () => { | ||
const expectedGroups: Array<GroupRequest> = [ | ||
{ | ||
id: "10402173435763029700781503965100", | ||
name: "Group1", | ||
description: "This is a new group", | ||
treeDepth: 16, | ||
fingerprintDuration: 3600 | ||
}, | ||
{ | ||
id: "20402173435763029700781503965200", | ||
name: "Group2", | ||
description: "This is a new group", | ||
treeDepth: 32, | ||
fingerprintDuration: 7200 | ||
} | ||
] | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
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 | ||
}, | ||
{ | ||
id: "20402173435763029700781503965200", | ||
name: "Group2", | ||
description: "This is a new group", | ||
admin: "0xdf558148e66850ac48dbe2c8119b0eefa7d08bfd19c997c90a142eb97916b847", | ||
treeDepth: 32, | ||
fingerprintDuration: 7200, | ||
createdAt: "2023-07-15T08:21:05.000Z", | ||
members: [], | ||
credentials: null | ||
} | ||
]) | ||
) | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const groups: Array<GroupResponse> = await apiSdk.createGroups( | ||
[expectedGroups[0], expectedGroups[1]], | ||
apiKey | ||
) | ||
groups.forEach((group: GroupResponse, i: number) => { | ||
expect(group.id).toBe(expectedGroups[i].id) | ||
expect(group.description).toBe( | ||
expectedGroups[i].description | ||
) | ||
expect(group.name).toBe(expectedGroups[i].name) | ||
expect(group.treeDepth).toBe(expectedGroups[i].treeDepth) | ||
expect(group.fingerprintDuration).toBe( | ||
group.fingerprintDuration | ||
) | ||
expect(group.members).toHaveLength(0) | ||
expect(group.credentials).toBeNull() | ||
}) | ||
}) | ||
}) | ||
describe("#removeGroup", () => { | ||
it("Should create a group", async () => { | ||
const groupId = "10402173435763029700781503965100" | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
requestMocked.mockImplementationOnce(() => Promise.resolve()) | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const res = await apiSdk.removeGroup(groupId, apiKey) | ||
expect(res).toBeUndefined() | ||
}) | ||
}) | ||
describe("#removeGroups", () => { | ||
it("Should create a group", async () => { | ||
const groupIds = [ | ||
"10402173435763029700781503965100", | ||
"20402173435763029700781503965200" | ||
] | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
requestMocked.mockImplementationOnce(() => Promise.resolve()) | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const res = await apiSdk.removeGroups(groupIds, apiKey) | ||
expect(res).toBeUndefined() | ||
}) | ||
}) | ||
describe("#updateGroup", () => { | ||
it("Should update a group", async () => { | ||
const groupId = "10402173435763029700781503965100" | ||
const updatedGroup: GroupUpdateRequest = { | ||
description: "This is a new group", | ||
treeDepth: 16, | ||
fingerprintDuration: 3600 | ||
} | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
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 | ||
}) | ||
) | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const group: GroupResponse = await apiSdk.updateGroup( | ||
groupId, | ||
updatedGroup, | ||
apiKey | ||
) | ||
expect(group.description).toBe(updatedGroup.description) | ||
expect(group.treeDepth).toBe(updatedGroup.treeDepth) | ||
expect(group.fingerprintDuration).toBe( | ||
updatedGroup.fingerprintDuration | ||
) | ||
}) | ||
}) | ||
describe("#updateGroups", () => { | ||
it("Should update some groups", async () => { | ||
const groupIds = [ | ||
"10402173435763029700781503965100", | ||
"20402173435763029700781503965200" | ||
] | ||
const updatedGroups: Array<GroupUpdateRequest> = [ | ||
{ | ||
description: "This is a new group1", | ||
treeDepth: 32, | ||
fingerprintDuration: 7200 | ||
}, | ||
{ | ||
description: "This is a new group2", | ||
treeDepth: 32, | ||
fingerprintDuration: 7200 | ||
} | ||
] | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
requestMocked.mockImplementationOnce(() => | ||
Promise.resolve([ | ||
{ | ||
id: "10402173435763029700781503965100", | ||
name: "Group1", | ||
description: "This is a new group1", | ||
admin: "0xdf558148e66850ac48dbe2c8119b0eefa7d08bfd19c997c90a142eb97916b847", | ||
treeDepth: 32, | ||
fingerprintDuration: 7200, | ||
createdAt: "2023-07-15T08:21:05.000Z", | ||
members: [], | ||
credentials: null | ||
}, | ||
{ | ||
id: "20402173435763029700781503965200", | ||
name: "Group1", | ||
description: "This is a new group2", | ||
admin: "0xdf558148e66850ac48dbe2c8119b0eefa7d08bfd19c997c90a142eb97916b847", | ||
treeDepth: 32, | ||
fingerprintDuration: 7200, | ||
createdAt: "2023-07-15T08:21:05.000Z", | ||
members: [], | ||
credentials: null | ||
} | ||
]) | ||
) | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const groups: Array<GroupResponse> = await apiSdk.updateGroups( | ||
groupIds, | ||
updatedGroups, | ||
apiKey | ||
) | ||
groups.forEach((group: GroupResponse, i: number) => { | ||
expect(group.description).toBe(updatedGroups[i].description) | ||
expect(group.treeDepth).toBe(updatedGroups[i].treeDepth) | ||
expect(group.fingerprintDuration).toBe( | ||
updatedGroups[i].fingerprintDuration | ||
) | ||
}) | ||
}) | ||
}) | ||
describe("#getGroups", () => { | ||
@@ -74,0 +325,0 @@ it("Should return all groups", async () => { |
@@ -0,1 +1,3 @@ | ||
import { ApiKeyActions } from "@bandada/utils" | ||
export type GroupResponse = { | ||
@@ -17,2 +19,24 @@ id: string | ||
export type GroupRequest = { | ||
name: string | ||
description: string | ||
treeDepth: number | ||
fingerprintDuration: number | ||
id?: string | ||
credentials?: { | ||
id: string | ||
criteria: Record<string, any> | ||
} | ||
} | ||
export type GroupUpdateRequest = { | ||
description: string | ||
treeDepth: number | ||
fingerprintDuration: number | ||
credentials?: { | ||
id: string | ||
criteria: Record<string, any> | ||
} | ||
} | ||
type Group = { | ||
@@ -19,0 +43,0 @@ id: string |
Sorry, the diff of this file is not supported yet
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
117278
3033
+ Added@bandada/utils@2.2.0(transitive)
- Removed@bandada/utils@2.1.1(transitive)
Updated@bandada/utils@2.2.0