forked from keyshade-xyz/keyshade
-
Notifications
You must be signed in to change notification settings - Fork 0
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): Create controller for Integration module (keyshade-…
…xyz#397) Co-authored-by: vr-varad <varadgupta21#gmail.com> Co-authored-by: Rajdip Bhattacharya <agentR47@gmail.com>
- Loading branch information
Showing
4 changed files
with
395 additions
and
1 deletion.
There are no files selected for viewing
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,84 @@ | ||
import { | ||
CreateIntegrationRequest, | ||
CreateIntegrationResponse, | ||
DeleteIntegrationRequest, | ||
DeleteIntegrationResponse, | ||
GetAllIntegrationRequest, | ||
GetAllIntegrationResponse, | ||
GetIntegrationRequest, | ||
GetIntegrationResponse, | ||
UpdateIntegrationRequest, | ||
UpdateIntegrationResponse | ||
} from '../types/integration.types' | ||
import { APIClient } from '../core/client' | ||
import { ClientResponse } from '../types/index.types' | ||
import { parseResponse } from '../core/response-parser' | ||
|
||
export default class IntegrationController { | ||
private apiClient: APIClient | ||
|
||
constructor(private readonly backendUrl: string) { | ||
this.apiClient = new APIClient(this.backendUrl) | ||
} | ||
|
||
async createIntegration( | ||
request: CreateIntegrationRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<CreateIntegrationResponse>> { | ||
const response = await this.apiClient.post( | ||
`/api/integration/${request.workspaceId}`, | ||
request, | ||
headers | ||
) | ||
return await parseResponse<CreateIntegrationResponse>(response) | ||
} | ||
|
||
async updateIntegration( | ||
request: UpdateIntegrationRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<UpdateIntegrationResponse>> { | ||
const response = await this.apiClient.put( | ||
`/api/integration/${request.integrationId}`, | ||
request, | ||
headers | ||
) | ||
return await parseResponse<UpdateIntegrationResponse>(response) | ||
} | ||
|
||
async getIntegration( | ||
request: GetIntegrationRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<GetIntegrationResponse>> { | ||
const response = await this.apiClient.get( | ||
`/api/integration/${request.integrationId}`, | ||
headers | ||
) | ||
return await parseResponse<GetIntegrationResponse>(response) | ||
} | ||
|
||
async getAllIntegrations( | ||
request: GetAllIntegrationRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<GetAllIntegrationResponse>> { | ||
let url = `/api/integration/all/${request.workspaceId}` | ||
request.page && (url += `page=${request.page}&`) | ||
request.limit && (url += `limit=${request.limit}&`) | ||
request.sort && (url += `sort=${request.sort}&`) | ||
request.order && (url += `order=${request.order}&`) | ||
request.search && (url += `search=${request.search}&`) | ||
|
||
const response = await this.apiClient.get(url, headers) | ||
return await parseResponse<GetAllIntegrationResponse>(response) | ||
} | ||
|
||
async deleteIntegration( | ||
request: DeleteIntegrationRequest, | ||
headers?: Record<string, string> | ||
): Promise<ClientResponse<DeleteIntegrationResponse>> { | ||
const response = await this.apiClient.delete( | ||
`/api/integration/${request.integrationId}`, | ||
headers | ||
) | ||
return await parseResponse<DeleteIntegrationResponse>(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import EnvironmentController from './controllers/environment' | ||
import SecretController from './controllers/secret' | ||
import EventController from './controllers/event' | ||
import IntegrationController from './controllers/integration' | ||
|
||
export { EnvironmentController, SecretController, EventController } | ||
export { | ||
EnvironmentController, | ||
SecretController, | ||
EventController, | ||
IntegrationController | ||
} |
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,129 @@ | ||
import { Page } from '../../../../apps/cli/src/types/index.types' | ||
export enum IntegrationType { | ||
DISCORD, | ||
SLACK, | ||
GITHUB, | ||
GITLAB | ||
} | ||
|
||
export enum EventType { | ||
INVITED_TO_WORKSPACE, | ||
REMOVED_FROM_WORKSPACE, | ||
ACCEPTED_INVITATION, | ||
DECLINED_INVITATION, | ||
CANCELLED_INVITATION, | ||
LEFT_WORKSPACE, | ||
WORKSPACE_MEMBERSHIP_UPDATED, | ||
WORKSPACE_UPDATED, | ||
WORKSPACE_CREATED, | ||
WORKSPACE_ROLE_CREATED, | ||
WORKSPACE_ROLE_UPDATED, | ||
WORKSPACE_ROLE_DELETED, | ||
PROJECT_CREATED, | ||
PROJECT_UPDATED, | ||
PROJECT_DELETED, | ||
SECRET_UPDATED, | ||
SECRET_DELETED, | ||
SECRET_ADDED, | ||
VARIABLE_UPDATED, | ||
VARIABLE_DELETED, | ||
VARIABLE_ADDED, | ||
ENVIRONMENT_UPDATED, | ||
ENVIRONMENT_DELETED, | ||
ENVIRONMENT_ADDED, | ||
INTEGRATION_ADDED, | ||
INTEGRATION_UPDATED, | ||
INTEGRATION_DELETED | ||
} | ||
export interface CreateIntegrationRequest { | ||
workspaceId?: string | ||
projectId?: string | ||
name: string | ||
type: string | ||
notifyOn: [string] | ||
metadata: Record<string, string> | ||
environmentId: string | ||
} | ||
|
||
export interface CreateIntegrationResponse { | ||
id: string | ||
name: string | ||
metadata: Record<string, string> | ||
createdAt: string | ||
updatedAt: string | ||
type: IntegrationType | ||
notifyOn: EventType[] | ||
workspaceId: string | ||
projectId: string | ||
environmentId: string | ||
} | ||
|
||
export interface UpdateIntegrationRequest { | ||
integrationId: string | ||
workspaceId?: string | ||
projectId?: string | ||
name?: string | ||
type?: IntegrationType | ||
notifyOn?: EventType[] | ||
metadata?: Record<string, string> | ||
environmentId?: string | ||
} | ||
|
||
export interface UpdateIntegrationResponse { | ||
id: string | ||
name: string | ||
metadata: Record<string, string> | ||
createdAt: string | ||
updatedAt: string | ||
type: IntegrationType | ||
notifyOn: EventType[] | ||
workspaceId: string | ||
projectId: string | ||
environmentId: string | ||
} | ||
|
||
export interface DeleteIntegrationResponse {} | ||
|
||
export interface DeleteIntegrationRequest { | ||
integrationId: string | ||
} | ||
|
||
export interface GetIntegrationRequest { | ||
integrationId: string | ||
} | ||
|
||
export interface GetIntegrationResponse { | ||
id: string | ||
name: string | ||
metadata: Record<string, string> | ||
createdAt: string | ||
updatedAt: string | ||
type: IntegrationType | ||
notifyOn: EventType[] | ||
workspaceId: string | ||
projectId: string | ||
environmentId: string | ||
} | ||
|
||
export interface GetAllIntegrationRequest { | ||
page?: number | ||
limit?: number | ||
sort?: string | ||
order?: string | ||
search?: string | ||
workspaceId: string | ||
} | ||
|
||
export interface GetAllIntegrationResponse | ||
extends Page<{ | ||
id: string | ||
name: string | ||
metadata: Record<string, string> | ||
createdAt: string | ||
updatedAt: string | ||
type: IntegrationType | ||
notifyOn: EventType[] | ||
workspaceId: string | ||
projectId: string | ||
environmentId: string | ||
}> {} |
Oops, something went wrong.