@bandada/api-sdk
Advanced tools
Comparing version 2.2.0 to 2.2.1
/** | ||
* @module @bandada/api-sdk | ||
* @version 2.2.0 | ||
* @version 2.2.1 | ||
* @file A Typescript SDK for the Bandada API. | ||
@@ -100,7 +100,7 @@ * @copyright Ethereum Foundation 2023 | ||
* Creates one or more groups with the provided details. | ||
* @param groupsData Data to create the groups. | ||
* @param groupsCreationDetails Data to create the groups. | ||
* @param apiKey API Key of the admin. | ||
* @returns Array of the created groups. | ||
*/ | ||
function createGroups(config, groupsData, apiKey) { | ||
function createGroups(config, groupsCreationDetails, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -111,5 +111,3 @@ var newConfig, req; | ||
case 0: | ||
newConfig = __assign({ method: "post", data: { | ||
groupsData: groupsData | ||
} }, config); | ||
newConfig = __assign({ method: "post", data: groupsCreationDetails }, config); | ||
newConfig.headers["x-api-key"] = apiKey; | ||
@@ -172,7 +170,7 @@ return [4 /*yield*/, utils.request(url$1, newConfig)]; | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param groupUpdateDetails Data to update the group. | ||
* @param apiKey API Key of the admin. | ||
* @return The updated group. | ||
*/ | ||
function updateGroup(config, groupId, groupData, apiKey) { | ||
function updateGroup(config, groupId, groupUpdateDetails, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -185,3 +183,3 @@ var requestUrl, newConfig, req; | ||
newConfig = __assign({ method: "put", data: { | ||
groupData: groupData | ||
groupUpdateDetails: groupUpdateDetails | ||
} }, config); | ||
@@ -200,7 +198,7 @@ newConfig.headers["x-api-key"] = apiKey; | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param groupsUpdateDetails Data to update the groups. | ||
* @param apiKey API Key of the admin. | ||
* @return The updated groups. | ||
*/ | ||
function updateGroups(config, groupIds, groupsData, apiKey) { | ||
function updateGroups(config, groupIds, groupsUpdateDetails, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -213,3 +211,3 @@ var newConfig, req; | ||
groupIds: groupIds, | ||
groupsData: groupsData | ||
groupsUpdateDetails: groupsUpdateDetails | ||
} }, config); | ||
@@ -507,7 +505,7 @@ newConfig.headers["x-api-key"] = apiKey; | ||
* Creates a group using the API key. | ||
* @param groupData Data to create the group. | ||
* @param groupCreationDetails 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) { | ||
ApiSdk.prototype.createGroup = function (groupCreationDetails, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -517,3 +515,3 @@ var groups; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, createGroups(this._config, [groupData], apiKey)]; | ||
case 0: return [4 /*yield*/, createGroups(this._config, [groupCreationDetails], apiKey)]; | ||
case 1: | ||
@@ -528,7 +526,7 @@ groups = _a.sent(); | ||
* Creates one or more groups using the API key. | ||
* @param groupsData Data to create the groups. | ||
* @param groupsCreationDetails 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) { | ||
ApiSdk.prototype.createGroups = function (groupsCreationDetails, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -538,3 +536,3 @@ var groups; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, createGroups(this._config, groupsData, apiKey)]; | ||
case 0: return [4 /*yield*/, createGroups(this._config, groupsCreationDetails, apiKey)]; | ||
case 1: | ||
@@ -576,7 +574,7 @@ groups = _a.sent(); | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param groupUpdateDetails 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) { | ||
ApiSdk.prototype.updateGroup = function (groupId, groupUpdateDetails, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -586,3 +584,3 @@ var group; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, updateGroup(this._config, groupId, groupData, apiKey)]; | ||
case 0: return [4 /*yield*/, updateGroup(this._config, groupId, groupUpdateDetails, apiKey)]; | ||
case 1: | ||
@@ -598,7 +596,7 @@ group = _a.sent(); | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param groupsUpdateDetails 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) { | ||
ApiSdk.prototype.updateGroups = function (groupIds, groupsUpdateDetails, apiKey) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -608,3 +606,3 @@ var groups; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, updateGroups(this._config, groupIds, groupsData, apiKey)]; | ||
case 0: return [4 /*yield*/, updateGroups(this._config, groupIds, groupsUpdateDetails, apiKey)]; | ||
case 1: | ||
@@ -611,0 +609,0 @@ groups = _a.sent(); |
@@ -1,2 +0,2 @@ | ||
import { SupportedUrl, GroupResponse, InviteResponse, GroupRequest, GroupUpdateRequest } from "./types"; | ||
import { SupportedUrl, Group, Invite, GroupCreationDetails, GroupUpdateDetails } from "./types"; | ||
export default class ApiSdk { | ||
@@ -25,17 +25,17 @@ private _url; | ||
*/ | ||
getGroups(): Promise<GroupResponse[]>; | ||
getGroups(): Promise<Group[]>; | ||
/** | ||
* Creates a group using the API key. | ||
* @param groupData Data to create the group. | ||
* @param groupCreationDetails 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>; | ||
createGroup(groupCreationDetails: GroupCreationDetails, apiKey: string): Promise<Group>; | ||
/** | ||
* Creates one or more groups using the API key. | ||
* @param groupsData Data to create the groups. | ||
* @param groupsCreationDetails 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>>; | ||
createGroups(groupsCreationDetails: Array<GroupCreationDetails>, apiKey: string): Promise<Array<Group>>; | ||
/** | ||
@@ -58,15 +58,15 @@ * Removes a group using the API key. | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param groupUpdateDetails 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>; | ||
updateGroup(groupId: string, groupUpdateDetails: GroupUpdateDetails, apiKey: string): Promise<Group>; | ||
/** | ||
* Updats one or more groups using the API key. | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param groupsUpdateDetails 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>>; | ||
updateGroups(groupIds: Array<string>, groupsUpdateDetails: Array<GroupUpdateDetails>, apiKey: string): Promise<Array<Group>>; | ||
/** | ||
@@ -77,3 +77,3 @@ * Returns a specific group. | ||
*/ | ||
getGroup(groupId: string): Promise<GroupResponse>; | ||
getGroup(groupId: string): Promise<Group>; | ||
/** | ||
@@ -138,3 +138,3 @@ * Returns true if the member is in the group and false otherwise. | ||
*/ | ||
getInvite(inviteCode: string): Promise<InviteResponse>; | ||
getInvite(inviteCode: string): Promise<Invite>; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { GroupRequest, GroupResponse, GroupUpdateRequest } from "./types"; | ||
import type { GroupCreationDetails, Group, GroupUpdateDetails } from "./types"; | ||
/** | ||
@@ -6,10 +6,10 @@ * Returns the list of groups. | ||
*/ | ||
export declare function getGroups(config: object): Promise<GroupResponse[]>; | ||
export declare function getGroups(config: object): Promise<Group[]>; | ||
/** | ||
* Creates one or more groups with the provided details. | ||
* @param groupsData Data to create the groups. | ||
* @param groupsCreationDetails 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>>; | ||
export declare function createGroups(config: object, groupsCreationDetails: Array<GroupCreationDetails>, apiKey: string): Promise<Array<Group>>; | ||
/** | ||
@@ -30,15 +30,15 @@ * Removes the group. | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param groupUpdateDetails 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>; | ||
export declare function updateGroup(config: object, groupId: string, groupUpdateDetails: GroupUpdateDetails, apiKey: string): Promise<Group>; | ||
/** | ||
* Updates the groups. | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param groupsUpdateDetails 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>>; | ||
export declare function updateGroups(config: object, groupIds: Array<string>, groupsUpdateDetails: Array<GroupUpdateDetails>, apiKey: string): Promise<Array<Group>>; | ||
/** | ||
@@ -49,3 +49,3 @@ * Returns a specific group. | ||
*/ | ||
export declare function getGroup(config: object, groupId: string): Promise<GroupResponse>; | ||
export declare function getGroup(config: object, groupId: string): Promise<Group>; | ||
/** | ||
@@ -52,0 +52,0 @@ * Returns true if the member is in the group and false otherwise. |
@@ -1,2 +0,2 @@ | ||
import { InviteResponse } from "./types"; | ||
import { Invite } from "./types"; | ||
/** | ||
@@ -7,2 +7,2 @@ * Returns a specific invite. | ||
*/ | ||
export declare function getInvite(config: object, inviteCode: string): Promise<InviteResponse>; | ||
export declare function getInvite(config: object, inviteCode: string): Promise<Invite>; |
@@ -1,3 +0,7 @@ | ||
export type GroupResponse = { | ||
export type Credential = { | ||
id: string; | ||
criteria: Record<string, any>; | ||
}; | ||
export type Group = { | ||
id: string; | ||
name: string; | ||
@@ -11,8 +15,5 @@ description: string; | ||
members: string[]; | ||
credentials: { | ||
id: string; | ||
criteria: Record<string, any>; | ||
}; | ||
credentials: Credential | null; | ||
}; | ||
export type GroupRequest = { | ||
export type GroupCreationDetails = { | ||
name: string; | ||
@@ -22,18 +23,11 @@ description: string; | ||
fingerprintDuration: number; | ||
id?: string; | ||
credentials?: { | ||
id: string; | ||
criteria: Record<string, any>; | ||
}; | ||
credentials?: Credential; | ||
}; | ||
export type GroupUpdateRequest = { | ||
export type GroupUpdateDetails = { | ||
description: string; | ||
treeDepth: number; | ||
fingerprintDuration: number; | ||
credentials?: { | ||
id: string; | ||
criteria: Record<string, any>; | ||
}; | ||
credentials?: Credential; | ||
}; | ||
type Group = { | ||
type GroupSummary = { | ||
id: string; | ||
@@ -45,16 +39,11 @@ name: string; | ||
fingerprintDuration: number; | ||
credentials: { | ||
id: string; | ||
criteria: Record<string, any>; | ||
}; | ||
apiEnabled: boolean; | ||
apiKey: string; | ||
credentials: Credential | null; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
}; | ||
export type InviteResponse = { | ||
export type Invite = { | ||
code: string; | ||
isRedeemed: boolean; | ||
createdAt: Date; | ||
group: Group; | ||
group: GroupSummary; | ||
groupName: string; | ||
@@ -61,0 +50,0 @@ groupId: string; |
{ | ||
"name": "@bandada/api-sdk", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "A Typescript SDK for the Bandada API.", | ||
@@ -32,3 +32,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@bandada/utils": "2.2.0" | ||
"@bandada/utils": "2.2.1" | ||
}, | ||
@@ -35,0 +35,0 @@ "devDependencies": { |
146
README.md
@@ -74,17 +74,35 @@ <p align="center"> | ||
- Creates a new instance using the 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. | ||
```ts | ||
import { ApiSdk } from "@bandada/api-sdk" | ||
const apiSdk = new ApiSdk() | ||
``` | ||
- Creates a new instance using a custom API URL. | ||
- 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. | ||
```ts | ||
import { ApiSdk, SupportedUrl } from "@bandada/api-sdk" | ||
const apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
``` | ||
- Create a new instance using a custom API URL. | ||
```ts | ||
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" | ||
const url = "https://example.com/api" | ||
@@ -99,4 +117,111 @@ const config = { | ||
\# **getGroups**(): _Promise\<GroupResponse[]>_ | ||
\# **createGroup**(): _Promise\<Group>_ | ||
Creates a Bandada group. | ||
```ts | ||
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) | ||
``` | ||
\# **createGroups**(): _Promise\<Group[]>_ | ||
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) | ||
``` | ||
\# **removeGroup**(): _Promise\<void>_ | ||
Removes a specific Bandada group. | ||
```ts | ||
const groupId = "10402173435763029700781503965100" | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
await apiSdk.removeGroup(groupId, apiKey) | ||
``` | ||
\# **removeGroups**(): _Promise\<void>_ | ||
Removes one or many Bandada groups. | ||
```ts | ||
const groupIds = [ | ||
"10402173435763029700781503965100", | ||
"20402173435763029700781503965200" | ||
] | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
await apiSdk.removeGroups(groupIds, apiKey) | ||
``` | ||
\# **updateGroup**(): _Promise\<Group>_ | ||
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) | ||
``` | ||
\# **updateGroups**(): _Promise\<Group[]>_ | ||
Updates one or many Bandada groups. | ||
```ts | ||
const groupIds = [ | ||
"10402173435763029700781503965100", | ||
"20402173435763029700781503965200" | ||
] | ||
const updatedGroups: Array<GroupUpdateDetails> = [ | ||
{ | ||
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) | ||
``` | ||
\# **getGroups**(): _Promise\<Group[]>_ | ||
Returns the list of groups. | ||
@@ -108,3 +233,3 @@ | ||
\# **getGroup**(): _Promise\<GroupResponse>_ | ||
\# **getGroup**(): _Promise\<Group>_ | ||
@@ -200,1 +325,12 @@ Returns a specific group. | ||
``` | ||
\# **getInvite**(): _Promise\<Invite>_ | ||
Returns a specific invite. | ||
```ts | ||
const inviteCode = "C5VAG4HD" | ||
const apiKey = "70f07d0d-6aa2-4fe1-b4b9-06c271a641dc" | ||
const invite = await apiSdk.getInvite(inviteCode) | ||
``` |
import { | ||
SupportedUrl, | ||
GroupResponse, | ||
InviteResponse, | ||
GroupRequest, | ||
GroupUpdateRequest | ||
Group, | ||
Invite, | ||
GroupCreationDetails, | ||
GroupUpdateDetails | ||
} from "./types" | ||
@@ -82,3 +82,3 @@ import checkParameter from "./checkParameter" | ||
*/ | ||
async getGroups(): Promise<GroupResponse[]> { | ||
async getGroups(): Promise<Group[]> { | ||
const groups = await getGroups(this._config) | ||
@@ -91,3 +91,3 @@ | ||
* Creates a group using the API key. | ||
* @param groupData Data to create the group. | ||
* @param groupCreationDetails Data to create the group. | ||
* @param apiKey The API key of the admin of the group. | ||
@@ -97,6 +97,10 @@ * @returns The created group. | ||
async createGroup( | ||
groupData: GroupRequest, | ||
groupCreationDetails: GroupCreationDetails, | ||
apiKey: string | ||
): Promise<GroupResponse> { | ||
const groups = await createGroups(this._config, [groupData], apiKey) | ||
): Promise<Group> { | ||
const groups = await createGroups( | ||
this._config, | ||
[groupCreationDetails], | ||
apiKey | ||
) | ||
@@ -108,3 +112,3 @@ return groups[0] | ||
* Creates one or more groups using the API key. | ||
* @param groupsData Data to create the groups. | ||
* @param groupsCreationDetails Data to create the groups. | ||
* @param apiKey The API key of the admin of the groups. | ||
@@ -114,6 +118,10 @@ * @returns The created groups. | ||
async createGroups( | ||
groupsData: Array<GroupRequest>, | ||
groupsCreationDetails: Array<GroupCreationDetails>, | ||
apiKey: string | ||
): Promise<Array<GroupResponse>> { | ||
const groups = await createGroups(this._config, groupsData, apiKey) | ||
): Promise<Array<Group>> { | ||
const groups = await createGroups( | ||
this._config, | ||
groupsCreationDetails, | ||
apiKey | ||
) | ||
@@ -146,3 +154,3 @@ return groups | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param groupUpdateDetails Data to update the group. | ||
* @param apiKey The API key of the admin of the group. | ||
@@ -153,9 +161,9 @@ * @returns The updated group. | ||
groupId: string, | ||
groupData: GroupUpdateRequest, | ||
groupUpdateDetails: GroupUpdateDetails, | ||
apiKey: string | ||
): Promise<GroupResponse> { | ||
): Promise<Group> { | ||
const group = await updateGroup( | ||
this._config, | ||
groupId, | ||
groupData, | ||
groupUpdateDetails, | ||
apiKey | ||
@@ -170,3 +178,3 @@ ) | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param groupsUpdateDetails Data to update the groups. | ||
* @param apiKey The API key of the admin of the groups. | ||
@@ -177,9 +185,9 @@ * @returns The updated groups. | ||
groupIds: Array<string>, | ||
groupsData: Array<GroupUpdateRequest>, | ||
groupsUpdateDetails: Array<GroupUpdateDetails>, | ||
apiKey: string | ||
): Promise<Array<GroupResponse>> { | ||
): Promise<Array<Group>> { | ||
const groups = await updateGroups( | ||
this._config, | ||
groupIds, | ||
groupsData, | ||
groupsUpdateDetails, | ||
apiKey | ||
@@ -196,3 +204,3 @@ ) | ||
*/ | ||
async getGroup(groupId: string): Promise<GroupResponse> { | ||
async getGroup(groupId: string): Promise<Group> { | ||
const group = await getGroup(this._config, groupId) | ||
@@ -314,3 +322,3 @@ | ||
*/ | ||
async getInvite(inviteCode: string): Promise<InviteResponse> { | ||
async getInvite(inviteCode: string): Promise<Invite> { | ||
const invite = getInvite(this._config, inviteCode) | ||
@@ -317,0 +325,0 @@ |
import { request } from "@bandada/utils" | ||
import { GroupRequest, GroupResponse, GroupUpdateRequest } from "./types" | ||
import type { GroupCreationDetails, Group, GroupUpdateDetails } from "./types" | ||
@@ -10,3 +10,3 @@ const url = "/groups" | ||
*/ | ||
export async function getGroups(config: object): Promise<GroupResponse[]> { | ||
export async function getGroups(config: object): Promise<Group[]> { | ||
const groups = await request(url, config) | ||
@@ -24,3 +24,3 @@ | ||
* Creates one or more groups with the provided details. | ||
* @param groupsData Data to create the groups. | ||
* @param groupsCreationDetails Data to create the groups. | ||
* @param apiKey API Key of the admin. | ||
@@ -31,10 +31,8 @@ * @returns Array of the created groups. | ||
config: object, | ||
groupsData: Array<GroupRequest>, | ||
groupsCreationDetails: Array<GroupCreationDetails>, | ||
apiKey: string | ||
): Promise<Array<GroupResponse>> { | ||
): Promise<Array<Group>> { | ||
const newConfig: any = { | ||
method: "post", | ||
data: { | ||
groupsData | ||
}, | ||
data: groupsCreationDetails, | ||
...config | ||
@@ -102,3 +100,3 @@ } | ||
* @param groupId The group id. | ||
* @param groupData Data to update the group. | ||
* @param groupUpdateDetails Data to update the group. | ||
* @param apiKey API Key of the admin. | ||
@@ -110,5 +108,5 @@ * @return The updated group. | ||
groupId: string, | ||
groupData: GroupUpdateRequest, | ||
groupUpdateDetails: GroupUpdateDetails, | ||
apiKey: string | ||
): Promise<GroupResponse> { | ||
): Promise<Group> { | ||
const requestUrl = `${url}/${groupId}` | ||
@@ -119,3 +117,3 @@ | ||
data: { | ||
groupData | ||
groupUpdateDetails | ||
}, | ||
@@ -135,3 +133,3 @@ ...config | ||
* @param groupIds The group ids. | ||
* @param groupsData Data to update the groups. | ||
* @param groupsUpdateDetails Data to update the groups. | ||
* @param apiKey API Key of the admin. | ||
@@ -143,5 +141,5 @@ * @return The updated groups. | ||
groupIds: Array<string>, | ||
groupsData: Array<GroupUpdateRequest>, | ||
groupsUpdateDetails: Array<GroupUpdateDetails>, | ||
apiKey: string | ||
): Promise<Array<GroupResponse>> { | ||
): Promise<Array<Group>> { | ||
const newConfig: any = { | ||
@@ -151,3 +149,3 @@ method: "put", | ||
groupIds, | ||
groupsData | ||
groupsUpdateDetails | ||
}, | ||
@@ -172,3 +170,3 @@ ...config | ||
groupId: string | ||
): Promise<GroupResponse> { | ||
): Promise<Group> { | ||
const requestUrl = `${url}/${groupId}` | ||
@@ -175,0 +173,0 @@ |
import { request } from "@bandada/utils" | ||
import ApiSdk from "./apiSdk" | ||
import { | ||
GroupRequest, | ||
GroupResponse, | ||
GroupUpdateRequest, | ||
InviteResponse, | ||
GroupCreationDetails, | ||
Group, | ||
GroupUpdateDetails, | ||
Invite, | ||
SupportedUrl | ||
@@ -85,4 +85,3 @@ } from "./types" | ||
it("Should create a group", async () => { | ||
const expectedGroup: GroupRequest = { | ||
id: "10402173435763029700781503965100", | ||
const expectedGroup: GroupCreationDetails = { | ||
name: "Group1", | ||
@@ -112,3 +111,3 @@ description: "This is a new group", | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const group: GroupResponse = await apiSdk.createGroup( | ||
const group: Group = await apiSdk.createGroup( | ||
expectedGroup, | ||
@@ -118,3 +117,2 @@ apiKey | ||
expect(group.id).toBe(expectedGroup.id) | ||
expect(group.description).toBe(expectedGroup.description) | ||
@@ -132,5 +130,4 @@ expect(group.name).toBe(expectedGroup.name) | ||
it("Should create the groups", async () => { | ||
const expectedGroups: Array<GroupRequest> = [ | ||
const expectedGroups: Array<GroupCreationDetails> = [ | ||
{ | ||
id: "10402173435763029700781503965100", | ||
name: "Group1", | ||
@@ -142,3 +139,2 @@ description: "This is a new group", | ||
{ | ||
id: "20402173435763029700781503965200", | ||
name: "Group2", | ||
@@ -180,3 +176,3 @@ description: "This is a new group", | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const groups: Array<GroupResponse> = await apiSdk.createGroups( | ||
const groups: Array<Group> = await apiSdk.createGroups( | ||
[expectedGroups[0], expectedGroups[1]], | ||
@@ -186,4 +182,3 @@ apiKey | ||
groups.forEach((group: GroupResponse, i: number) => { | ||
expect(group.id).toBe(expectedGroups[i].id) | ||
groups.forEach((group: Group, i: number) => { | ||
expect(group.description).toBe( | ||
@@ -232,3 +227,3 @@ expectedGroups[i].description | ||
const groupId = "10402173435763029700781503965100" | ||
const updatedGroup: GroupUpdateRequest = { | ||
const updatedGroup: GroupUpdateDetails = { | ||
description: "This is a new group", | ||
@@ -255,3 +250,3 @@ treeDepth: 16, | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const group: GroupResponse = await apiSdk.updateGroup( | ||
const group: Group = await apiSdk.updateGroup( | ||
groupId, | ||
@@ -275,3 +270,3 @@ updatedGroup, | ||
] | ||
const updatedGroups: Array<GroupUpdateRequest> = [ | ||
const updatedGroups: Array<GroupUpdateDetails> = [ | ||
{ | ||
@@ -318,3 +313,3 @@ description: "This is a new group1", | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const groups: Array<GroupResponse> = await apiSdk.updateGroups( | ||
const groups: Array<Group> = await apiSdk.updateGroups( | ||
groupIds, | ||
@@ -325,3 +320,3 @@ updatedGroups, | ||
groups.forEach((group: GroupResponse, i: number) => { | ||
groups.forEach((group: Group, i: number) => { | ||
expect(group.description).toBe(updatedGroups[i].description) | ||
@@ -353,3 +348,3 @@ expect(group.treeDepth).toBe(updatedGroups[i].treeDepth) | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const groups: GroupResponse[] = await apiSdk.getGroups() | ||
const groups: Group[] = await apiSdk.getGroups() | ||
expect(groups).toHaveLength(1) | ||
@@ -376,3 +371,3 @@ }) | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const group: GroupResponse = await apiSdk.getGroup(groupId) | ||
const group: Group = await apiSdk.getGroup(groupId) | ||
expect(group.id).toBe(groupId) | ||
@@ -572,5 +567,3 @@ }) | ||
apiSdk = new ApiSdk(SupportedUrl.DEV) | ||
const invite: InviteResponse = await apiSdk.getInvite( | ||
inviteCode | ||
) | ||
const invite: Invite = await apiSdk.getInvite(inviteCode) | ||
expect(invite.code).toBe(inviteCode) | ||
@@ -577,0 +570,0 @@ }) |
import { request } from "@bandada/utils" | ||
import { InviteResponse } from "./types" | ||
import { Invite } from "./types" | ||
@@ -14,3 +14,3 @@ const url = "/invites" | ||
inviteCode: string | ||
): Promise<InviteResponse> { | ||
): Promise<Invite> { | ||
const requestUrl = `${url}/${inviteCode}` | ||
@@ -17,0 +17,0 @@ |
@@ -1,4 +0,7 @@ | ||
import { ApiKeyActions } from "@bandada/utils" | ||
export type Credential = { | ||
id: string | ||
criteria: Record<string, any> | ||
} | ||
export type GroupResponse = { | ||
export type Group = { | ||
id: string | ||
@@ -13,9 +16,6 @@ name: string | ||
members: string[] | ||
credentials: { | ||
id: string | ||
criteria: Record<string, any> | ||
} | ||
credentials: Credential | null | ||
} | ||
export type GroupRequest = { | ||
export type GroupCreationDetails = { | ||
name: string | ||
@@ -25,20 +25,13 @@ description: string | ||
fingerprintDuration: number | ||
id?: string | ||
credentials?: { | ||
id: string | ||
criteria: Record<string, any> | ||
} | ||
credentials?: Credential | ||
} | ||
export type GroupUpdateRequest = { | ||
export type GroupUpdateDetails = { | ||
description: string | ||
treeDepth: number | ||
fingerprintDuration: number | ||
credentials?: { | ||
id: string | ||
criteria: Record<string, any> | ||
} | ||
credentials?: Credential | ||
} | ||
type Group = { | ||
type GroupSummary = { | ||
id: string | ||
@@ -50,8 +43,3 @@ name: string | ||
fingerprintDuration: number | ||
credentials: { | ||
id: string | ||
criteria: Record<string, any> | ||
} | ||
apiEnabled: boolean | ||
apiKey: string | ||
credentials: Credential | null | ||
createdAt: Date | ||
@@ -61,7 +49,7 @@ updatedAt: Date | ||
export type InviteResponse = { | ||
export type Invite = { | ||
code: string | ||
isRedeemed: boolean | ||
createdAt: Date | ||
group: Group | ||
group: GroupSummary | ||
groupName: string | ||
@@ -68,0 +56,0 @@ groupId: string |
Sorry, the diff of this file is not supported yet
120061
333
3005
+ Added@bandada/utils@2.2.1(transitive)
- Removed@bandada/utils@2.2.0(transitive)
Updated@bandada/utils@2.2.1