-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api-client): Added workspace-membership and related tests (#452)
- Loading branch information
Showing
4 changed files
with
455 additions
and
1 deletion.
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
packages/api-client/src/controllers/workspace-membership.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { APIClient } from '@api-client/core/client' | ||
import { parseResponse } from '@api-client/core/response-parser' | ||
import { parsePaginationUrl } from '@api-client/core/pagination-parser' | ||
import { | ||
TransferOwnershipRequest, | ||
TransferOwnershipResponse, | ||
InviteUsersRequest, | ||
InviteUsersResponse, | ||
RemoveUsersRequest, | ||
RemoveUsersResponse, | ||
UpdateMemberRoleRequest, | ||
UpdateMemberRoleResponse, | ||
AcceptInvitationRequest, | ||
AcceptInvitationResponse, | ||
DeclineInvitationRequest, | ||
DeclineInvitationResponse, | ||
CancelInvitationRequest, | ||
CancelInvitationResponse, | ||
LeaveWorkspaceRequest, | ||
LeaveWorkspaceResponse, | ||
IsMemberRequest, | ||
IsMemberResponse, | ||
GetMembersRequest, | ||
GetMembersResponse | ||
} from '@api-client/types/workspace-membership.types' | ||
import { ClientResponse } from '@api-client/types/index.types' | ||
|
||
export default class WorkspaceMembershipController { | ||
private apiClient: APIClient | ||
|
||
constructor(private readonly backendUrl: string) { | ||
this.apiClient = new APIClient(this.backendUrl) | ||
} | ||
|
||
async transferOwnership( | ||
request: TransferOwnershipRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<TransferOwnershipResponse>> { | ||
const response = await this.apiClient.put( | ||
`/api/workspace-membership/${request.workspaceSlug}/transfer-ownership/${request.userEmail}`, | ||
request, | ||
headers | ||
) | ||
return await parseResponse<TransferOwnershipResponse>(response) | ||
} | ||
|
||
async inviteUsers( | ||
request: InviteUsersRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<InviteUsersResponse>> { | ||
const response = await this.apiClient.post( | ||
`/api/workspace-membership/${request.workspaceSlug}/invite-users`, | ||
request, | ||
headers | ||
) | ||
return await parseResponse<InviteUsersResponse>(response) | ||
} | ||
|
||
async removeUsers( | ||
request: RemoveUsersRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<RemoveUsersResponse>> { | ||
const response = await this.apiClient.delete( | ||
`/api/workspace-membership/${request.workspaceSlug}/remove-users`, | ||
headers | ||
) | ||
return await parseResponse<RemoveUsersResponse>(response) | ||
} | ||
|
||
async updateMemberRoles( | ||
request: UpdateMemberRoleRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<UpdateMemberRoleResponse>> { | ||
const response = await this.apiClient.put( | ||
`/api/workspace-membership/${request.workspaceSlug}/update-member-role/${request.userEmail}`, | ||
request, | ||
headers | ||
) | ||
return await parseResponse<UpdateMemberRoleResponse>(response) | ||
} | ||
|
||
async acceptInvitation( | ||
request: AcceptInvitationRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<AcceptInvitationResponse>> { | ||
const response = await this.apiClient.post( | ||
`/api/workspace-membership/${request.workspaceSlug}/accept-invitation`, | ||
request, | ||
headers | ||
) | ||
return await parseResponse<AcceptInvitationResponse>(response) | ||
} | ||
|
||
async declineInvitation( | ||
request: DeclineInvitationRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<DeclineInvitationResponse>> { | ||
const response = await this.apiClient.delete( | ||
`/api/workspace-membership/${request.workspaceSlug}/decline-invitation`, | ||
headers | ||
) | ||
return await parseResponse<DeclineInvitationResponse>(response) | ||
} | ||
|
||
async cancelInvitation( | ||
request: CancelInvitationRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<CancelInvitationResponse>> { | ||
const response = await this.apiClient.delete( | ||
`/api/workspace-membership/${request.workspaceSlug}/cancel-invitation/${request.userEmail}`, | ||
headers | ||
) | ||
return await parseResponse<CancelInvitationResponse>(response) | ||
} | ||
|
||
async leaveWorkspace( | ||
request: LeaveWorkspaceRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<LeaveWorkspaceResponse>> { | ||
const response = await this.apiClient.delete( | ||
`/api/workspace-membership/${request.workspaceSlug}/leave`, | ||
headers | ||
) | ||
return await parseResponse<LeaveWorkspaceResponse>(response) | ||
} | ||
|
||
async isMember( | ||
request: IsMemberRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<IsMemberResponse>> { | ||
const response = await this.apiClient.get( | ||
`/api/workspace-membership/${request.workspaceSlug}/is-member/${request.userEmail}`, | ||
headers | ||
) | ||
return await parseResponse<IsMemberResponse>(response) | ||
} | ||
|
||
async getMembers( | ||
request: GetMembersRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<GetMembersResponse>> { | ||
let url = parsePaginationUrl( | ||
`/api/workspace-membership/${request.workspaceSlug}/members`, | ||
request | ||
) | ||
const response = await this.apiClient.get(url, headers) | ||
return await parseResponse<GetMembersResponse>(response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
packages/api-client/src/types/workspace-membership.types.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import { Page } from '../../../../apps/cli/src/types/index.types' | ||
|
||
enum Authority { | ||
CREATE_PROJECT, | ||
READ_USERS, | ||
ADD_USER, | ||
REMOVE_USER, | ||
UPDATE_USER_ROLE, | ||
READ_WORKSPACE, | ||
UPDATE_WORKSPACE, | ||
DELETE_WORKSPACE, | ||
CREATE_WORKSPACE_ROLE, | ||
READ_WORKSPACE_ROLE, | ||
UPDATE_WORKSPACE_ROLE, | ||
DELETE_WORKSPACE_ROLE, | ||
WORKSPACE_ADMIN, | ||
READ_PROJECT, | ||
UPDATE_PROJECT, | ||
DELETE_PROJECT, | ||
CREATE_SECRET, | ||
READ_SECRET, | ||
UPDATE_SECRET, | ||
DELETE_SECRET, | ||
CREATE_ENVIRONMENT, | ||
READ_ENVIRONMENT, | ||
UPDATE_ENVIRONMENT, | ||
DELETE_ENVIRONMENT, | ||
CREATE_VARIABLE, | ||
READ_VARIABLE, | ||
UPDATE_VARIABLE, | ||
DELETE_VARIABLE, | ||
CREATE_INTEGRATION, | ||
READ_INTEGRATION, | ||
UPDATE_INTEGRATION, | ||
DELETE_INTEGRATION, | ||
CREATE_WORKSPACE, | ||
CREATE_API_KEY, | ||
READ_API_KEY, | ||
UPDATE_API_KEY, | ||
DELETE_API_KEY, | ||
UPDATE_PROFILE, | ||
READ_SELF, | ||
UPDATE_SELF, | ||
READ_EVENT | ||
} | ||
|
||
export interface CreateWorkspaceMember { | ||
email: string | ||
roleSlugs: string[] | ||
} | ||
|
||
export interface TransferOwnershipRequest { | ||
workspaceSlug: string | ||
userEmail: string | ||
} | ||
|
||
export interface TransferOwnershipResponse {} | ||
|
||
export interface InviteUsersRequest { | ||
emails: string[] | ||
workspaceSlug: string | ||
members: CreateWorkspaceMember[] | ||
} | ||
|
||
export interface InviteUsersResponse {} | ||
|
||
export interface RemoveUsersRequest { | ||
workspaceSlug: string | ||
userEmails: string[] | ||
} | ||
|
||
export interface RemoveUsersResponse {} | ||
|
||
export interface UpdateMemberRoleRequest { | ||
workspaceSlug: string | ||
userEmail: string | ||
roleSlugs: string[] | ||
} | ||
|
||
export interface UpdateMemberRoleResponse {} | ||
|
||
export interface AcceptInvitationRequest { | ||
workspaceSlug: string | ||
} | ||
|
||
export interface AcceptInvitationResponse {} | ||
|
||
export interface DeclineInvitationRequest { | ||
workspaceSlug: string | ||
} | ||
|
||
export interface DeclineInvitationResponse {} | ||
|
||
export interface CancelInvitationRequest { | ||
workspaceSlug: string | ||
userEmail: string | ||
} | ||
|
||
export interface CancelInvitationResponse {} | ||
|
||
export interface LeaveWorkspaceRequest { | ||
workspaceSlug: string | ||
} | ||
|
||
export interface LeaveWorkspaceResponse {} | ||
|
||
export interface IsMemberRequest { | ||
workspaceSlug: string | ||
userEmail: string | ||
} | ||
|
||
export type IsMemberResponse = boolean | ||
|
||
export interface GetMembersRequest extends Page { | ||
workspaceSlug: string | ||
page?: number | ||
limit?: number | ||
sort?: string | ||
order?: string | ||
search?: string | ||
} | ||
|
||
export interface GetMembersResponse | ||
extends Page<{ | ||
metadata: Record<string, string> | ||
id: string | ||
user: { | ||
id: string | ||
email: string | ||
name: string | null | ||
} | ||
roles: { | ||
id: string | ||
role: { | ||
id: string | ||
name: string | ||
description: string | null | ||
colorCode: string | null | ||
authorities: Authority[] | ||
projects: { | ||
id: string | ||
}[] | ||
} | ||
}[] | ||
}> {} |
Oops, something went wrong.