Skip to content

Commit

Permalink
final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rajdip-b committed Aug 24, 2024
1 parent 0ce8890 commit df753a4
Show file tree
Hide file tree
Showing 18 changed files with 323 additions and 164 deletions.
2 changes: 1 addition & 1 deletion packages/api-client/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config: Config = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^@package/(.*)$': '<rootDir>/src/$1'
'^@api-client/(.*)$': '<rootDir>/src/$1'
}
}

Expand Down
8 changes: 4 additions & 4 deletions packages/api-client/src/controllers/environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ClientResponse } from '../types/index.types'
import { APIClient } from '../core/client'
import { parseResponse } from '../core/response-parser'
import { APIClient } from '@api-client/core/client'
import { parseResponse } from '@api-client/core/response-parser'
import {
CreateEnvironmentRequest,
CreateEnvironmentResponse,
Expand All @@ -12,7 +11,8 @@ import {
GetEnvironmentByIdResponse,
UpdateEnvironmentRequest,
UpdateEnvironmentResponse
} from '../types/environment.types'
} from '@api-client/types/environment.types'
import { ClientResponse } from '@api-client/types/index.types'

export default class EnvironmentController {
private apiClient: APIClient
Expand Down
9 changes: 6 additions & 3 deletions packages/api-client/src/controllers/event.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { GetEventsRequest, GetEventsResponse } from '../types/event.types'
import {
GetEventsRequest,
GetEventsResponse
} from '@api-client/types/event.types'
import { APIClient } from '../core/client'
import { ClientResponse } from '../types/index.types'
import { parseResponse } from '../core/response-parser'
import { ClientResponse } from '@api-client/types/index.types'
import { parseResponse } from '@api-client/core/response-parser'

export default class EventController {
private apiClient: APIClient
Expand Down
8 changes: 4 additions & 4 deletions packages/api-client/src/controllers/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
GetIntegrationResponse,
UpdateIntegrationRequest,
UpdateIntegrationResponse
} from '../types/integration.types'
import { APIClient } from '../core/client'
import { ClientResponse } from '../types/index.types'
import { parseResponse } from '../core/response-parser'
} from '@api-client/types/integration.types'
import { APIClient } from '@api-client/core/client'
import { ClientResponse } from '@api-client/types/index.types'
import { parseResponse } from '@api-client/core/response-parser'

export default class IntegrationController {
private apiClient: APIClient
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import client from '@package/client'
import { ClientResponse } from '@api-client/types/index.types'
import { APIClient } from '@api-client/core/client'
import {
CreateProjectRequest,
CreateProjectResponse,
Expand All @@ -18,105 +19,131 @@ import {
UnlinkProjectResponse,
UpdateProjectRequest,
UpdateProjectResponse
} from '@package/types/project.types'
} from '@api-client/types/project.types'
import { parseResponse } from '@api-client/core/response-parser'

export default class ProjectController {
private static apiClient = client
private apiClient: APIClient

static async createProject(
constructor(private readonly backendUrl: string) {
this.apiClient = new APIClient(this.backendUrl)
}

async createProject(
request: CreateProjectRequest,
headers: Record<string, string>
): Promise<CreateProjectResponse> {
return this.apiClient.post<CreateProjectResponse>(
): Promise<ClientResponse<CreateProjectResponse>> {
const response = await this.apiClient.post(
`/api/project/${request.workspaceId}`,
request,
headers
)

return await parseResponse<CreateProjectResponse>(response)
}

static async updateProject(
async updateProject(
request: UpdateProjectRequest,
headers: Record<string, string>
): Promise<UpdateProjectResponse> {
return this.apiClient.put<UpdateProjectResponse>(
): Promise<ClientResponse<UpdateProjectResponse>> {
const response = await this.apiClient.put(
`/api/project/${request.projectId}`,
request,
headers
)

return await parseResponse<UpdateProjectResponse>(response)
}

static async deleteProject(
async deleteProject(
request: DeleteProjectRequest,
headers: Record<string, string>
): Promise<DeleteProjectResponse> {
return this.apiClient.delete(`/api/project/${request.projectId}`, headers)
): Promise<ClientResponse<DeleteProjectResponse>> {
const response = await this.apiClient.delete(
`/api/project/${request.projectId}`,
headers
)

return await parseResponse<DeleteProjectResponse>(response)
}

static async getProject(
async getProject(
request: GetProjectRequest,
headers: Record<string, string>
): Promise<GetProjectResponse> {
return this.apiClient.get<GetProjectResponse>(
): Promise<ClientResponse<GetProjectResponse>> {
const response = await this.apiClient.get(
`/api/project/${request.projectId}`,
headers
)

return await parseResponse<GetProjectResponse>(response)
}

static async forkProject(
async forkProject(
request: ForkProjectRequest,
headers: Record<string, string>
): Promise<ForkProjectResponse> {
return this.apiClient.post<ForkProjectResponse>(
): Promise<ClientResponse<ForkProjectResponse>> {
const response = await this.apiClient.post(
`/api/project/${request.projectId}/fork`,
request,
headers
)

return await parseResponse<ForkProjectResponse>(response)
}

static async syncFork(
async syncFork(
request: SyncProjectRequest,
headers: Record<string, string>
): Promise<SyncProjectResponse> {
return this.apiClient.put(
): Promise<ClientResponse<SyncProjectResponse>> {
const response = await this.apiClient.put(
`/project/${request.projectId}/fork`,
request,
headers
)

return await parseResponse<SyncProjectResponse>(response)
}

static async unlinkFork(
async unlinkFork(
request: UnlinkProjectRequest,
headers: Record<string, string>
): Promise<UnlinkProjectResponse> {
return this.apiClient.delete(
): Promise<ClientResponse<UnlinkProjectResponse>> {
const response = await this.apiClient.delete(
`/api/project/${request.projectId}/fork`,
headers
)

return await parseResponse<UnlinkProjectResponse>(response)
}

static async getForks(
async getForks(
request: GetForkRequest,
headers: Record<string, string>
): Promise<[GetForkResponse]> {
): Promise<ClientResponse<GetForkResponse>> {
let url = `/api/project/${request.projectId}/forks`
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}&`)
return this.apiClient.get(url, headers)
const response = await this.apiClient.get(url, headers)

return await parseResponse<GetForkResponse>(response)
}

static async getAllProjects(
async getAllProjects(
request: GetAllProjectsRequest,
headers: Record<string, string>
): Promise<[GetAllProjectsResponse]> {
): Promise<ClientResponse<GetAllProjectsResponse>> {
let url = `/api/project/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}&`)
return this.apiClient.get(url, headers)
const response = await this.apiClient.get(url, headers)

return await parseResponse<GetAllProjectsResponse>(response)
}
}
8 changes: 4 additions & 4 deletions packages/api-client/src/controllers/secret.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { APIClient } from '../core/client'
import { ClientResponse } from '../types/index.types'
import { parseResponse } from '../core/response-parser'
import { APIClient } from '@api-client/core/client'
import { ClientResponse } from '@api-client/types/index.types'
import { parseResponse } from '@api-client/core/response-parser'
import {
CreateSecretRequest,
CreateSecretResponse,
Expand All @@ -14,7 +14,7 @@ import {
RollBackSecretResponse,
UpdateSecretRequest,
UpdateSecretResponse
} from '../types/secret.types'
} from '@api-client/types/secret.types'

export default class SecretController {
private apiClient: APIClient
Expand Down
8 changes: 4 additions & 4 deletions packages/api-client/src/controllers/variable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { APIClient } from '../core/client'
import { parseResponse } from '../core/response-parser'
import { ClientResponse } from '../types/index.types'
import { APIClient } from '@api-client/core/client'
import { parseResponse } from '@api-client/core/response-parser'
import { ClientResponse } from '@api-client/types/index.types'
import {
CreateVariableRequest,
CreateVariableResponse,
Expand All @@ -14,7 +14,7 @@ import {
RollBackVariableResponse,
UpdateVariableRequest,
UpdateVariableResponse
} from '../types/variable.types'
} from '@api-client/types/variable.types'

export default class VariableController {
private apiClient: APIClient
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/core/response-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientResponse, ResponseError } from '../types/index.types'
import { ClientResponse, ResponseError } from '@api-client/types/index.types'

export async function parseResponse<T>(
response: Response
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/types/environment.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from '../../../../apps/cli/src/types/index.types'
import { Page } from './index.types'

export interface CreateEnvironmentRequest {
name: string
Expand Down
2 changes: 1 addition & 1 deletion packages/api-client/src/types/event.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from '../../../../apps/cli/src/types/index.types'
import { Page } from './index.types'

export enum EventSource {
SECRET,
Expand Down
3 changes: 2 additions & 1 deletion packages/api-client/src/types/integration.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Page } from '../../../../apps/cli/src/types/index.types'
import { Page } from './index.types'

export enum IntegrationType {
DISCORD,
SLACK,
Expand Down
44 changes: 26 additions & 18 deletions packages/api-client/src/types/project.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Page } from './index.types'

export interface CreateProjectRequest {
name: string
workspaceId: string
Expand Down Expand Up @@ -124,23 +126,25 @@ export interface GetForkRequest {
search?: string
}

export interface GetForkResponse {
id: string
name: string
description: string
createdAt: string
updatedAt: string
publicKey: string
privateKey: string
storePrivateKey: boolean
isDisabled: boolean
accessLevel: string
pendingCreation: boolean
isForked: boolean
lastUpdatedById: string
workspaceId: string
forkedFromId: string
}
export interface GetForkResponse
extends Page<{
id: string
name: string
description: string
createdAt: string
updatedAt: string
publicKey: string
privateKey: string
storePrivateKey: boolean
isDisabled: boolean
accessLevel: string
pendingCreation: boolean
isForked: boolean
lastUpdatedById: string
workspaceId: string
forkedFromId: string
}> {}

export interface GetAllProjectsRequest {
workspaceId: string
page?: number
Expand All @@ -150,4 +154,8 @@ export interface GetAllProjectsRequest {
search?: string
}

export interface GetAllProjectsResponse {}
export interface GetAllProjectsResponse
extends Page<{
id: string
name: string
}> {}
13 changes: 6 additions & 7 deletions packages/api-client/src/types/secret.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from '../../../../apps/cli/src/types/index.types'
import { Page } from './index.types'

export interface CreateSecretRequest {
projectId: string
Expand Down Expand Up @@ -119,9 +119,8 @@ export interface GetAllSecretsOfEnvironmentRequest {
order?: string
search?: string
}
export interface GetAllSecretsOfEnvironmentResponse
extends Page<{
name: string
value: string
isPlaintext: boolean
}> {}
export interface GetAllSecretsOfEnvironmentResponse {
name: string
value: string
isPlaintext: boolean
}
2 changes: 1 addition & 1 deletion packages/api-client/src/types/variable.types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Page } from '../../../../apps/cli/src/types/index.types'
import { Page } from './index.types'

export interface CreateVariableRequest {
projectId: string
Expand Down
4 changes: 2 additions & 2 deletions packages/api-client/tests/environment.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIClient } from '../src/core/client'
import EnvironmentController from '../src/controllers/environment'
import { APIClient } from '@api-client/core/client'
import EnvironmentController from '@api-client/controllers/environment'

describe('Environments Controller Tests', () => {
const backendUrl = process.env.BACKEND_URL
Expand Down
Loading

0 comments on commit df753a4

Please sign in to comment.