From c3b64f85906a94e0065ae504a272355a38e4e284 Mon Sep 17 00:00:00 2001 From: vr-varad Date: Mon, 1 Jul 2024 21:07:37 +0530 Subject: [PATCH 1/2] Changed objects to classes --- apps/cli/src/http/auth.ts | 34 ++++++++++++++++++---------------- apps/cli/src/http/secret.ts | 6 ++++-- apps/cli/src/http/variable.ts | 6 ++++-- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/apps/cli/src/http/auth.ts b/apps/cli/src/http/auth.ts index bd8d9b41..2dd10ce9 100644 --- a/apps/cli/src/http/auth.ts +++ b/apps/cli/src/http/auth.ts @@ -1,22 +1,24 @@ import { Logger } from '@/util/logger' -const AuthController = { - async checkApiKeyValidity(baseUrl: string, apiKey: string): Promise { - Logger.info('Checking API key validity...') - const response = await fetch(`${baseUrl}/api/api-key/access/live-updates`, { - headers: { - 'x-keyshade-token': apiKey +class AuthControllerClass { + static async checkApiKeyValidity(baseUrl: string, apiKey: string): Promise { + Logger.info('Checking API key validity...') + const response = await fetch(`${baseUrl}/api/api-key/access/live-updates`, { + headers: { + 'x-keyshade-token': apiKey + } + }) + + if (!response.ok) { + throw new Error( + 'API key is not valid. Please check the key and try again.' + ) + } + + Logger.info('API key is valid!') } - }) - - if (!response.ok) { - throw new Error( - 'API key is not valid. Please check the key and try again.' - ) - } - - Logger.info('API key is valid!') - } } +const AuthController = new AuthControllerClass(); + export default AuthController diff --git a/apps/cli/src/http/secret.ts b/apps/cli/src/http/secret.ts index 80eabf09..026a850a 100644 --- a/apps/cli/src/http/secret.ts +++ b/apps/cli/src/http/secret.ts @@ -1,7 +1,7 @@ import type { Configuration } from '@/types/command/run.types' -const SecretController = { - async fetchSecrets( +class SecretControllerClass { + static async fetchSecrets( baseUrl: string, apiKey: string, projectId: string, @@ -25,4 +25,6 @@ const SecretController = { } } +const SecretController = new SecretControllerClass(); + export default SecretController diff --git a/apps/cli/src/http/variable.ts b/apps/cli/src/http/variable.ts index 03e0d210..7942d1e7 100644 --- a/apps/cli/src/http/variable.ts +++ b/apps/cli/src/http/variable.ts @@ -1,7 +1,7 @@ import type { Configuration } from '@/types/command/run.types' -const VariableController = { - async fetchVariables( +class VariableControllerClass{ + static async fetchVariables( baseUrl: string, apiKey: string, projectId: string, @@ -25,4 +25,6 @@ const VariableController = { } } +const VariableController = new VariableControllerClass(); + export default VariableController From 8d528348e575435cba13e39c789bdd7e4f37ac90 Mon Sep 17 00:00:00 2001 From: vr-varad Date: Tue, 2 Jul 2024 08:06:31 +0530 Subject: [PATCH 2/2] Minute Changes in Names and Initialization --- apps/cli/src/http/auth.ts | 3 +-- apps/cli/src/http/secret.ts | 3 +-- apps/cli/src/http/variable.ts | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/apps/cli/src/http/auth.ts b/apps/cli/src/http/auth.ts index 2dd10ce9..9c8a1b67 100644 --- a/apps/cli/src/http/auth.ts +++ b/apps/cli/src/http/auth.ts @@ -1,6 +1,6 @@ import { Logger } from '@/util/logger' -class AuthControllerClass { +class AuthController { static async checkApiKeyValidity(baseUrl: string, apiKey: string): Promise { Logger.info('Checking API key validity...') const response = await fetch(`${baseUrl}/api/api-key/access/live-updates`, { @@ -19,6 +19,5 @@ class AuthControllerClass { } } -const AuthController = new AuthControllerClass(); export default AuthController diff --git a/apps/cli/src/http/secret.ts b/apps/cli/src/http/secret.ts index 026a850a..63379467 100644 --- a/apps/cli/src/http/secret.ts +++ b/apps/cli/src/http/secret.ts @@ -1,6 +1,6 @@ import type { Configuration } from '@/types/command/run.types' -class SecretControllerClass { +class SecretController { static async fetchSecrets( baseUrl: string, apiKey: string, @@ -25,6 +25,5 @@ class SecretControllerClass { } } -const SecretController = new SecretControllerClass(); export default SecretController diff --git a/apps/cli/src/http/variable.ts b/apps/cli/src/http/variable.ts index 7942d1e7..6ae80ad1 100644 --- a/apps/cli/src/http/variable.ts +++ b/apps/cli/src/http/variable.ts @@ -1,6 +1,6 @@ import type { Configuration } from '@/types/command/run.types' -class VariableControllerClass{ +class VariableController{ static async fetchVariables( baseUrl: string, apiKey: string, @@ -25,6 +25,4 @@ class VariableControllerClass{ } } -const VariableController = new VariableControllerClass(); - export default VariableController