From c8c2f9181f9636309907ad79e6e89dd3986c7008 Mon Sep 17 00:00:00 2001 From: Vivian Plasencia Date: Thu, 11 Apr 2024 17:56:15 +0200 Subject: [PATCH] docs: update api sdk docs with the latest bandada changes --- apps/docs/docs/api/api-sdk.md | 163 ++++++++++++++++++++++++++++++++-- libs/api-sdk/README.md | 61 +++++++++++-- 2 files changed, 208 insertions(+), 16 deletions(-) diff --git a/apps/docs/docs/api/api-sdk.md b/apps/docs/docs/api/api-sdk.md index 46db151..f7e047a 100644 --- a/apps/docs/docs/api/api-sdk.md +++ b/apps/docs/docs/api/api-sdk.md @@ -50,7 +50,7 @@ pnpm add @bandada/api-sdk Creates a new instance of ApiSdk using the API URL and the [config](https://axios-http.com/docs/req_config). -- Creates a new instance using the production Bandada API URL and the default config. +- Create a new instance using the Bandada API URL and the default config. This is what you need if you are using the production Bandada API. @@ -60,7 +60,7 @@ import { ApiSdk } from "@bandada/api-sdk" const apiSdk = new ApiSdk() ``` -- Creates a new instance using a [Supported URL](https://github.com/bandada-infra/bandada/blob/main/libs/api-sdk/src/types/index.ts#L43). +- Create a new instance using a [Supported URL](https://github.com/bandada-infra/bandada/blob/main/libs/api-sdk/src/types/index.ts#L43). This is useful when working with the development environment. @@ -70,7 +70,7 @@ import { ApiSdk, SupportedUrl } from "@bandada/api-sdk" const apiSdk = new ApiSdk(SupportedUrl.DEV) ``` -- Creates a new instance using a custom API URL. +- Create a new instance using a custom API URL. ```ts import { ApiSdk } from "@bandada/api-sdk" @@ -78,7 +78,7 @@ import { ApiSdk } from "@bandada/api-sdk" const apiSdk = new ApiSdk("https://example.com/api") ``` -- Creates a new instance using a custom API URL and config. +- Create a new instance using a custom API URL and config. ```ts import { ApiSdk } from "@bandada/api-sdk" @@ -92,19 +92,128 @@ const config = { const apiSdk = new ApiSdk(url, config) ``` -## Get groups +## Create group -\# **getGroups**(): _Promise\_ +\# **createGroup**(): _Promise\_ -Returns the list of groups. +Creates a Bandada group. ```ts -const groups = await apiSdk.getGroups() +const groupCreateDetails = { + name: "Group 1", + description: "This is Group 1.", + treeDepth: 16, + fingerprintDuration: 3600 +} +const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" + +const group = await apiSdk.createGroup(groupCreateDetails, apiKey) +``` + +## Create groups + +\# **createGroups**(): _Promise\_ + +Creates one or many Bandada groups. + +```ts +const groupsCreateDetails = [ + { + name: "Group 1", + description: "This is Group 1.", + treeDepth: 16, + fingerprintDuration: 3600 + }, + { + name: "Group 2", + description: "This is Group 2.", + treeDepth: 16, + fingerprintDuration: 3600 + } +] +const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" + +const groups = await apiSdk.createGroups(groupsCreateDetails, apiKey) +``` + +## Remove group + +\# **removeGroup**(): _Promise\_ + +Removes a specific Bandada group. + +```ts +const groupId = "10402173435763029700781503965100" +const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" + +await apiSdk.removeGroup(groupId, apiKey) +``` + +## Remove groups + +\# **removeGroups**(): _Promise\_ + +Removes one or many Bandada groups. + +```ts +const groupIds = [ + "10402173435763029700781503965100", + "20402173435763029700781503965200" +] +const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" + +await apiSdk.removeGroups(groupIds, apiKey) +``` + +## Update group + +\# **updateGroup**(): _Promise\_ + +Updates a specific Bandada group. + +```ts +const groupId = "10402173435763029700781503965100" +const groupUpdateDetails = { + description: "This is a new group.", + treeDepth: 20, + fingerprintDuration: 4000 +} +const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" + +await apiSdk.updateGroup(groupId, groupUpdateDetails, apiKey) +``` + +## Update groups + +\# **updateGroups**(): _Promise\_ + +Updates one or many Bandada groups. + +```ts +const groupIds = [ + "10402173435763029700781503965100", + "20402173435763029700781503965200" +] +const updatedGroups: Array = [ + { + 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" + +await apiSdk.updateGroups(groupId, groupUpdateDetails, apiKey) ``` ## Get group -\# **getGroup**(): _Promise\_ +\# **getGroup**(): _Promise\_ Returns a specific group. @@ -114,6 +223,16 @@ const groupId = "10402173435763029700781503965100" const group = await apiSdk.getGroup(groupId) ``` +## Get groups + +\# **getGroups**(): _Promise\_ + +Returns the list of groups. + +```ts +const groups = await apiSdk.getGroups() +``` + ## Is group member \# **isGroupMember**(): _Promise\_ @@ -209,3 +328,29 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" await apiSdk.removeMembersByApiKey(groupId, memberIds, apiKey) ``` + +## Create invite + +\# **createInvite**(): _Promise\_ + +Creates a new group invite. + +```ts +const groupId = "10402173435763029700781503965100" +const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" + +const invite = await apiSdk.createInvite(groupId, apiKey) +``` + +## Get invite + +\# **getInvite**(): _Promise\_ + +Returns a specific invite. + +```ts +const inviteCode = "C5VAG4HD" +const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" + +const invite = await apiSdk.getInvite(inviteCode) +``` diff --git a/libs/api-sdk/README.md b/libs/api-sdk/README.md index bbd6373..ef4572a 100644 --- a/libs/api-sdk/README.md +++ b/libs/api-sdk/README.md @@ -67,6 +67,8 @@ yarn add @bandada/api-sdk ## 📜 Usage +## Create a new instance + \# **new ApiSdk**(url: SupportedUrl | string, config?: object): _ApiSdk_ Creates a new instance of ApiSdk using the API URL and the [config](https://axios-http.com/docs/req_config). @@ -113,6 +115,8 @@ const config = { const apiSdk = new ApiSdk(url, config) ``` +## Create group + \# **createGroup**(): _Promise\_ Creates a Bandada group. @@ -129,6 +133,8 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" const group = await apiSdk.createGroup(groupCreateDetails, apiKey) ``` +## Create groups + \# **createGroups**(): _Promise\_ Creates one or many Bandada groups. @@ -153,6 +159,8 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" const groups = await apiSdk.createGroups(groupsCreateDetails, apiKey) ``` +## Remove group + \# **removeGroup**(): _Promise\_ Removes a specific Bandada group. @@ -164,6 +172,8 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" await apiSdk.removeGroup(groupId, apiKey) ``` +## Remove groups + \# **removeGroups**(): _Promise\_ Removes one or many Bandada groups. @@ -178,6 +188,8 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" await apiSdk.removeGroups(groupIds, apiKey) ``` +## Update group + \# **updateGroup**(): _Promise\_ Updates a specific Bandada group. @@ -194,6 +206,8 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" await apiSdk.updateGroup(groupId, groupUpdateDetails, apiKey) ``` +## Update groups + \# **updateGroups**(): _Promise\_ Updates one or many Bandada groups. @@ -220,13 +234,7 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" await apiSdk.updateGroups(groupId, groupUpdateDetails, apiKey) ``` -\# **getGroups**(): _Promise\_ - -Returns the list of groups. - -```ts -const groups = await apiSdk.getGroups() -``` +## Get group \# **getGroup**(): _Promise\_ @@ -238,6 +246,18 @@ const groupId = "10402173435763029700781503965100" const group = await apiSdk.getGroup(groupId) ``` +## Get groups + +\# **getGroups**(): _Promise\_ + +Returns the list of groups. + +```ts +const groups = await apiSdk.getGroups() +``` + +## Is group member + \# **isGroupMember**(): _Promise\_ Returns true if the member is in the group and false otherwise. @@ -249,6 +269,8 @@ const memberId = "1" const isMember = await apiSdk.isGroupMember(groupId, memberId) ``` +## Generate merkle proof + \# **generateMerkleProof**(): _Promise\_ Returns the Merkle Proof for a member in a group. @@ -260,6 +282,8 @@ const memberId = "1" const proof = await apiSdk.generateMerkleProof(groupId, memberId) ``` +## Add member using an API Key + \# **addMemberByApiKey**(): _Promise\_ Adds a member to a group using an API Key. @@ -272,6 +296,8 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" await apiSdk.addMemberByApiKey(groupId, memberId, apiKey) ``` +## Add members using an API Key + \# **addMembersByApiKey**(): _Promise\_ Adds multiple members to a group using an API Key. @@ -284,6 +310,8 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" await apiSdk.addMembersByApiKey(groupId, memberIds, apiKey) ``` +## Add member using an invite code + \# **addMemberByInviteCode**(): _Promise\_ Adds a member to a group using an Invite Code. @@ -296,6 +324,8 @@ const inviteCode = "MQYS4UR5" await apiSdk.addMemberByInviteCode(groupId, memberId, inviteCode) ``` +## Remove member using an API Key + \# **removeMemberByApiKey**(): _Promise\_ Removes a member from a group using an API Key. @@ -308,6 +338,8 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" await apiSdk.removeMemberByApiKey(groupId, memberId, apiKey) ``` +## Remove members using an API Key + \# **removeMembersByApiKey**(): _Promise\_ Removes multiple members from a group using an API Key. @@ -320,6 +352,21 @@ const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" await apiSdk.removeMembersByApiKey(groupId, memberIds, apiKey) ``` +## Create invite + +\# **createInvite**(): _Promise\_ + +Creates a new group invite. + +```ts +const groupId = "10402173435763029700781503965100" +const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" + +const invite = await apiSdk.createInvite(groupId, apiKey) +``` + +## Get invite + \# **getInvite**(): _Promise\_ Returns a specific invite.