Skip to content

Commit

Permalink
Added Environment controller via api-client
Browse files Browse the repository at this point in the history
  • Loading branch information
vr-varad committed Jul 16, 2024
1 parent 44d9d6c commit ba5ea23
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 48 deletions.
2 changes: 1 addition & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"e2e:prepare": "cd ../../ && docker compose down && docker compose -f docker-compose-test.yml up -d && cd apps/api && pnpm db:generate-types && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' pnpm run db:deploy-migrations",
"e2e": "pnpm run e2e:prepare && cross-env NODE_ENV='e2e' DATABASE_URL='postgresql://prisma:prisma@localhost:5432/tests' jest --runInBand --config=jest.e2e-config.ts --coverage --coverageDirectory=../../coverage-e2e/api --coverageReporters=json && pnpm run e2e:teardown",
"e2e:teardown": "cd ../../ && docker compose -f docker-compose-test.yml down",
"unit": "pnpm db:generate-types && jest --config=jest.config.ts"
"unit": "pnpm db:generate-types && jest --detectOpenHandles --config=jest.config.ts"
},
"dependencies": {
"@nestjs/common": "^10.0.0",
Expand Down
21 changes: 10 additions & 11 deletions apps/cli/src/commands/environment/create.env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import {
CommandActionData,
CommandOption
} from 'src/types/command/command.types'
import { EnvironmentData } from 'src/types/command/environment.types'
import { text } from '@clack/prompts'
import { EnvironmentController } from '@keyshade/api-client'
import {
CreateEnvironmentRequest,
CreateEnvironmentResponse
} from '../../../../../packages/api-client/src/types/environment.types'
export class CreateEnvironment extends BaseCommand {
getName(): string {
return 'create'
Expand All @@ -21,21 +24,21 @@ export class CreateEnvironment extends BaseCommand {
}

async action({ options, args }: CommandActionData): Promise<void> {
const [project_id] = args
const [projectId] = args
const { name, description } = await this.parseInput(options)

if (!project_id) {
if (!projectId) {
Logger.error('Project ID is required')
return
}

const baseUrl = this.baseUrl
const apiKey = this.apiKey

const environmentData: EnvironmentData = {
const environmentData: CreateEnvironmentRequest = {
name: name,
description: description,
project_id: project_id
projectId: projectId
}

const headers = {
Expand All @@ -44,15 +47,11 @@ export class CreateEnvironment extends BaseCommand {
}

try {
const createdEnvironment = await EnvironmentController.createEnvironment(
environmentData,
headers
)
const createdEnvironment: CreateEnvironmentResponse =
await EnvironmentController.createEnvironment(environmentData, headers)
Logger.log(`Created environment:`)
Logger.log(`- Name: ${createdEnvironment.name}`)
Logger.log(`- ID: ${createdEnvironment.id}`)
Logger.log(`- API Key: ${createdEnvironment.apiKey}`)
Logger.log(`- Base URL: ${createdEnvironment.baseUrl}`)
} catch (error) {
Logger.error(error.message)
}
Expand Down
13 changes: 8 additions & 5 deletions apps/cli/src/commands/environment/delete.env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BaseCommand from '../base.command'
import Logger from '../../util/logger'
import EnvironmentController from '../../../../../packages/api-client/src/controllers/environment/environment'
import { EnvironmentController } from '@keyshade/api-client'
import {
CommandActionData,
CommandOption
Expand All @@ -20,9 +20,9 @@ export class DeleteEnvironment extends BaseCommand {
}

async action({ args }: CommandActionData): Promise<void> {
const [environment_id] = args
const [environmentId] = args

if (!environment_id) {
if (!environmentId) {
Logger.error('Environment ID is required')
return
}
Expand All @@ -36,8 +36,11 @@ export class DeleteEnvironment extends BaseCommand {
}

try {
await EnvironmentController.deleteEnvironment({ environment_id }, headers)
Logger.log(`Environment ${environment_id} has been deleted successfully.`)
await EnvironmentController.deleteEnvironment(
{ id: environmentId },
headers
)
Logger.log(`Environment ${environmentId} has been deleted successfully.`)
} catch (error) {
Logger.error(error.message)
}
Expand Down
18 changes: 10 additions & 8 deletions apps/cli/src/commands/environment/get.env.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import BaseCommand from '../base.command'
import Logger from '../../util/logger'
import EnvironmentController from '../../../../../packages/api-client/src/controllers/environment/environment'
import { EnvironmentController } from '@keyshade/api-client'
import {
CommandActionData,
CommandOption
} from 'src/types/command/command.types'
import { GetEnvironmentByIdResponse } from '../../../../../packages/api-client/src/types/environment.types'

export class GetEnvironment extends BaseCommand {
getName(): string {
Expand All @@ -20,9 +21,9 @@ export class GetEnvironment extends BaseCommand {
}

async action({ args }: CommandActionData): Promise<void> {
const [environment_id] = args
const [environmentId] = args

if (!environment_id) {
if (!environmentId) {
Logger.error('Environment ID is required')
return
}
Expand All @@ -36,11 +37,12 @@ export class GetEnvironment extends BaseCommand {
}

try {
const environment = await EnvironmentController.getEnvironmentById(
{ environment_id },
headers
)
Logger.log(`Environment ${environment_id}:`)
const environment: GetEnvironmentByIdResponse =
await EnvironmentController.getEnvironmentById(
{ id: environmentId },
headers
)
Logger.log(`Environment ${environmentId}:`)
Logger.log(`- Name: ${environment.name}`)
Logger.log(`- Description: ${environment.description}`)
} catch (error) {
Expand Down
13 changes: 7 additions & 6 deletions apps/cli/src/commands/environment/list.env.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import BaseCommand from '../base.command'
import Logger from '../../util/logger'
import EnvironmentController from '../../../../../packages/api-client/src/controllers/environment/environment'
import { EnvironmentController } from '@keyshade/api-client'
import {
CommandActionData,
CommandOption
} from 'src/types/command/command.types'
import { GetAllEnvironmentsOfProjectResponse } from '../../../../../packages/api-client/src/types/environment.types'

export class ListEnvironment extends BaseCommand {
getName(): string {
Expand All @@ -20,9 +21,9 @@ export class ListEnvironment extends BaseCommand {
}

async action({ args }: CommandActionData): Promise<void> {
const [project_id] = args
const [projectId] = args

if (!project_id) {
if (!projectId) {
Logger.error('Project ID is required')
return
}
Expand All @@ -41,12 +42,12 @@ export class ListEnvironment extends BaseCommand {
}

try {
const environments =
const environments: GetAllEnvironmentsOfProjectResponse =
await EnvironmentController.getAllEnvironmentsOfProject(
{ project_id },
{ projectId },
headers
)
Logger.log(`Environments for project ${project_id}:`)
Logger.log(`Environments for project ${projectId}:`)
environments.forEach((environment: any) => {
Logger.log(
`- ${environment.name} (Description: ${environment.description})`
Expand Down
23 changes: 12 additions & 11 deletions apps/cli/src/commands/environment/update.env.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import BaseCommand from '../base.command'
import Logger from '../../util/logger'
import EnvironmentController from '../../../../../packages/api-client/src/controllers/environment/environment'
import { EnvironmentController } from '@keyshade/api-client'
import {
CommandActionData,
CommandOption
} from 'src/types/command/command.types'
import { EnvironmentData } from 'src/types/command/environment.types'
import {
UpdateEnvironmentRequest,
UpdateEnvironmentResponse
} from '../../../../../packages/api-client/src/types/environment.types'

export class UpdateEnvironment extends BaseCommand {
getName(): string {
Expand All @@ -20,10 +23,10 @@ export class UpdateEnvironment extends BaseCommand {
}

async action({ options, args }: CommandActionData): Promise<void> {
const [environment_id] = args
const [environmentId] = args
const { name, description } = options

if (!environment_id) {
if (!environmentId) {
Logger.error('Environment ID is required')
return
}
Expand All @@ -36,18 +39,16 @@ export class UpdateEnvironment extends BaseCommand {
apiKey
}

const environmentData: EnvironmentData = {
const environmentData: UpdateEnvironmentRequest = {
name: name,
description: description,
environment_id: environment_id
id: environmentId
}

try {
const environments = await EnvironmentController.updateEnvironment(
environmentData,
headers
)
Logger.log(`Environments for project ${environment_id}:`)
const environments: UpdateEnvironmentResponse =
await EnvironmentController.updateEnvironment(environmentData, headers)
Logger.log(`Environments for project ${environmentId}:`)
environments.forEach((environment: any) => {
Logger.log(`- ${environment.name} (ID: ${environment.id})`)
})
Expand Down
6 changes: 0 additions & 6 deletions apps/cli/src/types/command/environment.types.d.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/api-client/src/types/environment.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface UpdateEnvironmentRequest {
}

export interface UpdateEnvironmentResponse {
forEach(arg0: (environment: any) => void): unknown
id: string
name: string
description: string | null
Expand Down

0 comments on commit ba5ea23

Please sign in to comment.