Skip to content

Commit

Permalink
feat(api-client): Create controller for Integration module (keyshade-…
Browse files Browse the repository at this point in the history
…xyz#397)

Co-authored-by: vr-varad <varadgupta21#gmail.com>
Co-authored-by: Rajdip Bhattacharya <agentR47@gmail.com>
  • Loading branch information
vr-varad and rajdip-b committed Sep 5, 2024
1 parent 096df2c commit 697d38b
Show file tree
Hide file tree
Showing 4 changed files with 395 additions and 1 deletion.
84 changes: 84 additions & 0 deletions packages/api-client/src/controllers/integration.ts
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)
}
}
8 changes: 7 additions & 1 deletion packages/api-client/src/index.ts
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
}
129 changes: 129 additions & 0 deletions packages/api-client/src/types/integration.types.d.ts
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
}> {}
Loading

0 comments on commit 697d38b

Please sign in to comment.