@bandada/api-sdk
Advanced tools
Comparing version 0.11.0 to 0.12.0
/** | ||
* @module @bandada/api-sdk | ||
* @version 0.11.0 | ||
* @version 0.12.0 | ||
* @file A Typescript SDK for the Bandada API. | ||
@@ -13,2 +13,12 @@ * @copyright Ethereum Foundation 2023 | ||
var __assign = function() { | ||
__assign = Object.assign || function __assign(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
@@ -51,3 +61,2 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
var url = "/groups"; | ||
var config = { | ||
@@ -59,4 +68,7 @@ headers: { | ||
? "http://localhost:3000" | ||
: "https://api.bandada.appliedzkp.org/" | ||
: /* istanbul ignore next */ | ||
"https://api.bandada.appliedzkp.org/" | ||
}; | ||
var url$1 = "/groups"; | ||
/** | ||
@@ -71,3 +83,3 @@ * Returns the list of groups. | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, utils.request(url, config)]; | ||
case 0: return [4 /*yield*/, utils.request(url$1, config)]; | ||
case 1: | ||
@@ -87,8 +99,8 @@ groups = _a.sent(); | ||
return __awaiter(this, void 0, void 0, function () { | ||
var group; | ||
var requestUrl, group; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url += "/".concat(groupId); | ||
return [4 /*yield*/, utils.request(url, config)]; | ||
requestUrl = "".concat(url$1, "/").concat(groupId); | ||
return [4 /*yield*/, utils.request(requestUrl, config)]; | ||
case 1: | ||
@@ -101,4 +113,149 @@ group = _a.sent(); | ||
} | ||
/** | ||
* Returns true if the member is in the group and false otherwise. | ||
* @param groupId Group id. | ||
* @param memberId Member id. | ||
* @returns true or false. | ||
*/ | ||
function isGroupMember(groupId, memberId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestUrl, isMember; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestUrl = "".concat(url$1, "/").concat(groupId, "/members/").concat(memberId); | ||
return [4 /*yield*/, utils.request(requestUrl, config)]; | ||
case 1: | ||
isMember = _a.sent(); | ||
return [2 /*return*/, isMember]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Returns the Merkle Proof for a member in a group. | ||
* @param groupId Group id. | ||
* @param memberId Member id. | ||
* @returns the Merkle Proof. | ||
*/ | ||
function generateMerkleProof(groupId, memberId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestUrl, merkleProof; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestUrl = "".concat(url$1, "/").concat(groupId, "/members/").concat(memberId, "/proof"); | ||
return [4 /*yield*/, utils.request(requestUrl, config)]; | ||
case 1: | ||
merkleProof = _a.sent(); | ||
return [2 /*return*/, merkleProof]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Adds a member to a group using an API Key. | ||
* @param groupId Group id. | ||
* @param memberId Member id. | ||
* @param apiKey API Key. | ||
* @returns undefined. | ||
*/ | ||
function addMemberByApiKey(groupId, memberId, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestUrl, newConfig; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestUrl = "".concat(url$1, "/").concat(groupId, "/members/").concat(memberId); | ||
newConfig = __assign({ method: "post" }, config); | ||
newConfig.headers["x-api-key"] = apiKey; | ||
return [4 /*yield*/, utils.request(requestUrl, newConfig)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Adds a member to a group using an Invite Code. | ||
* @param groupId Group id. | ||
* @param memberId Member id. | ||
* @param inviteCode Invite Code. | ||
* @returns undefined. | ||
*/ | ||
function addMemberByInviteCode(groupId, memberId, inviteCode) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestUrl; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestUrl = "".concat(url$1, "/").concat(groupId, "/members/").concat(memberId); | ||
return [4 /*yield*/, utils.request(requestUrl, { | ||
method: "post", | ||
data: { | ||
inviteCode: inviteCode | ||
} | ||
})]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
/** | ||
* Removes a member from a group using an API Key. | ||
* @param groupId Group id. | ||
* @param memberId Member id. | ||
* @param apiKey API Key. | ||
* @returns undefined. | ||
*/ | ||
function removeMemberByApiKey(groupId, memberId, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestUrl, newConfig; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestUrl = "".concat(url$1, "/").concat(groupId, "/members/").concat(memberId); | ||
newConfig = __assign({ method: "delete" }, config); | ||
newConfig.headers["x-api-key"] = apiKey; | ||
return [4 /*yield*/, utils.request(requestUrl, newConfig)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
} | ||
var url = "/invites"; | ||
/** | ||
* Returns a specific invite. | ||
* @param inviteCode Invite code. | ||
* @returns Specific invite. | ||
*/ | ||
function getInvite(inviteCode) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestUrl, invite; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
requestUrl = "".concat(url, "/").concat(inviteCode); | ||
return [4 /*yield*/, utils.request(requestUrl, config)]; | ||
case 1: | ||
invite = _a.sent(); | ||
return [2 /*return*/, invite]; | ||
} | ||
}); | ||
}); | ||
} | ||
exports.addMemberByApiKey = addMemberByApiKey; | ||
exports.addMemberByInviteCode = addMemberByInviteCode; | ||
exports.generateMerkleProof = generateMerkleProof; | ||
exports.getGroup = getGroup; | ||
exports.getGroups = getGroups; | ||
exports.getInvite = getInvite; | ||
exports.isGroupMember = isGroupMember; | ||
exports.removeMemberByApiKey = removeMemberByApiKey; |
@@ -1,2 +0,3 @@ | ||
export { getGroups, getGroup } from "./groups"; | ||
export { getGroups, getGroup, isGroupMember, generateMerkleProof, addMemberByApiKey, addMemberByInviteCode, removeMemberByApiKey } from "./groups"; | ||
export { getInvite } from "./invites"; | ||
export * from "./types"; |
@@ -12,1 +12,23 @@ export type GroupResponse = { | ||
}; | ||
type Group = { | ||
id: string; | ||
name: string; | ||
description: string; | ||
adminId: string; | ||
treeDepth: number; | ||
fingerprintDuration: number; | ||
reputationCriteria: object; | ||
apiEnabled: boolean; | ||
apiKey: string; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
}; | ||
export type InviteResponse = { | ||
code: string; | ||
isRedeemed: boolean; | ||
createdAt: Date; | ||
group: Group; | ||
groupName: string; | ||
groupId: string; | ||
}; | ||
export {}; |
{ | ||
"name": "@bandada/api-sdk", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"description": "A Typescript SDK for the Bandada API.", | ||
@@ -32,3 +32,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@bandada/utils": "0.11.0" | ||
"@bandada/utils": "0.12.0" | ||
}, | ||
@@ -35,0 +35,0 @@ "devDependencies": { |
import { request } from "@bandada/utils" | ||
import { GroupResponse } from "./types" | ||
import { config } from "./config" | ||
let url = "/groups" | ||
const url = "/groups" | ||
const config = { | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
baseURL: | ||
process.env.NODE_ENV === "test" | ||
? "http://localhost:3000" | ||
: "https://api.bandada.appliedzkp.org/" | ||
} | ||
/** | ||
@@ -32,5 +23,5 @@ * Returns the list of groups. | ||
export async function getGroup(groupId: string): Promise<GroupResponse> { | ||
url += `/${groupId}` | ||
const requestUrl = `${url}/${groupId}` | ||
const group = await request(url, config) | ||
const group = await request(requestUrl, config) | ||
@@ -50,5 +41,5 @@ return group | ||
): Promise<boolean> { | ||
url += `/${groupId}/members/${memberId}` | ||
const requestUrl = `${url}/${groupId}/members/${memberId}` | ||
const isMember = await request(url, config) | ||
const isMember = await request(requestUrl, config) | ||
@@ -68,5 +59,5 @@ return isMember | ||
): Promise<string> { | ||
url += `/${groupId}/members/${memberId}/proof` | ||
const requestUrl = `${url}/${groupId}/members/${memberId}/proof` | ||
const merkleProof = await request(url, config) | ||
const merkleProof = await request(requestUrl, config) | ||
@@ -88,3 +79,3 @@ return merkleProof | ||
): Promise<void> { | ||
url += `/${groupId}/members/${memberId}` | ||
const requestUrl = `${url}/${groupId}/members/${memberId}` | ||
@@ -98,3 +89,3 @@ const newConfig: any = { | ||
await request(url, newConfig) | ||
await request(requestUrl, newConfig) | ||
} | ||
@@ -114,5 +105,5 @@ | ||
): Promise<void> { | ||
url += `/${groupId}/members/${memberId}` | ||
const requestUrl = `${url}/${groupId}/members/${memberId}` | ||
await request(url, { | ||
await request(requestUrl, { | ||
method: "post", | ||
@@ -137,3 +128,3 @@ data: { | ||
): Promise<void> { | ||
url += `/${groupId}/members/${memberId}` | ||
const requestUrl = `${url}/${groupId}/members/${memberId}` | ||
@@ -147,3 +138,3 @@ const newConfig: any = { | ||
await request(url, newConfig) | ||
await request(requestUrl, newConfig) | ||
} |
@@ -11,3 +11,4 @@ import { request } from "@bandada/utils" | ||
} from "./groups" | ||
import { GroupResponse } from "./types" | ||
import { getInvite } from "./invites" | ||
import { GroupResponse, InviteResponse } from "./types" | ||
@@ -171,2 +172,35 @@ jest.mock("@bandada/utils", () => ({ | ||
}) | ||
describe("Invites", () => { | ||
describe("# getInvite", () => { | ||
it("Should return an invite", async () => { | ||
requestMocked.mockImplementationOnce(() => | ||
Promise.resolve({ | ||
code: "C5VAG4HD", | ||
isRedeemed: false, | ||
createdAt: "2023-08-09T18:10:02.000Z", | ||
group: { | ||
id: "95633257675970239314311768035433", | ||
name: "Group 1", | ||
description: "This is Group 1", | ||
adminId: | ||
"0x63229164c457584616006e31d1e171e6cdd4163695bc9c4bf0227095998ffa4c", | ||
treeDepth: 16, | ||
fingerprintDuration: 3600, | ||
reputationCriteria: null, | ||
apiEnabled: false, | ||
apiKey: null, | ||
createdAt: "2023-08-09T18:09:53.000Z", | ||
updatedAt: "2023-08-09T18:09:53.000Z" | ||
}, | ||
groupName: "Group 1", | ||
groupId: "95633257675970239314311768035433" | ||
}) | ||
) | ||
const inviteCode = "C5VAG4HD" | ||
const invite: InviteResponse = await getInvite(inviteCode) | ||
expect(invite.code).toBe(inviteCode) | ||
}) | ||
}) | ||
}) | ||
}) |
@@ -1,2 +0,11 @@ | ||
export { getGroups, getGroup } from "./groups" | ||
export { | ||
getGroups, | ||
getGroup, | ||
isGroupMember, | ||
generateMerkleProof, | ||
addMemberByApiKey, | ||
addMemberByInviteCode, | ||
removeMemberByApiKey | ||
} from "./groups" | ||
export { getInvite } from "./invites" | ||
export * from "./types" |
@@ -12,1 +12,24 @@ export type GroupResponse = { | ||
} | ||
type Group = { | ||
id: string | ||
name: string | ||
description: string | ||
adminId: string | ||
treeDepth: number | ||
fingerprintDuration: number | ||
reputationCriteria: object | ||
apiEnabled: boolean | ||
apiKey: string | ||
createdAt: Date | ||
updatedAt: Date | ||
} | ||
export type InviteResponse = { | ||
code: string | ||
isRedeemed: boolean | ||
createdAt: Date | ||
group: Group | ||
groupName: string | ||
groupId: string | ||
} |
Sorry, the diff of this file is not supported yet
41833
17
955
+ Added@bandada/utils@0.12.0(transitive)
- Removed@bandada/utils@0.11.0(transitive)
Updated@bandada/utils@0.12.0