Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api-client): Create controller for Integration module #397

Merged
merged 18 commits into from
Aug 9, 2024
Merged
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
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
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 {
vr-varad marked this conversation as resolved.
Show resolved Hide resolved
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
Loading