From 6becd86f89964b5e1f7f9786b867dbbea23c9b94 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Fri, 19 Jul 2024 14:08:35 +0100 Subject: [PATCH 1/3] feat: add dbdump REST API to cord SDK cli --- opensource/cli/src/commands/application.ts | 10 ++++++++++ opensource/cli/src/fetchCordRESTApi.ts | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/opensource/cli/src/commands/application.ts b/opensource/cli/src/commands/application.ts index f067d556c..e88c4050c 100644 --- a/opensource/cli/src/commands/application.ts +++ b/opensource/cli/src/commands/application.ts @@ -17,6 +17,15 @@ async function listAllApplicationsHandler() { prettyPrint(apps); } +async function dbDumpHandler() { + const dump = await fetchCordManagementApi( + 'customer/dbdump', + 'GET', + undefined, + 'text', + ); + console.log(dump); + async function whichApplicationHandler() { const variables = await getEnvVariables().catch(() => { /* no op, catch below instead */ @@ -196,6 +205,7 @@ export const projectCommand = { (yargs) => yargs, listAllApplicationsHandler, ) + .command('dbdump', 'Bump DB', (yargs) => yargs, dbDumpHandler) .command( 'get ', 'Get a project: GET https://api.cord.com/v1/projects/', diff --git a/opensource/cli/src/fetchCordRESTApi.ts b/opensource/cli/src/fetchCordRESTApi.ts index be28f843f..73fd4b2c8 100644 --- a/opensource/cli/src/fetchCordRESTApi.ts +++ b/opensource/cli/src/fetchCordRESTApi.ts @@ -50,6 +50,7 @@ export async function fetchCordManagementApi( endpoint: string, method: 'GET' | 'PUT' | 'POST' | 'DELETE' = 'GET', body?: string, + type: 'json' | 'text' = 'json', ): Promise { const env = await getEnvVariables().catch(() => { /*no-op. probably just doesn't exist yet*/ @@ -80,7 +81,7 @@ export async function fetchCordManagementApi( }); if (response.ok) { - return response.json() as T; + return type === 'text' ? (await response.text() as T) : (await response.json() as T); } else { const responseText = await response.text(); throw new Error( From 2bcc944b41c5b08889e27324eb5a9903b0b45d79 Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Fri, 19 Jul 2024 14:22:24 +0100 Subject: [PATCH 2/3] feat: add dbdump REST API to cord SDK cli --- opensource/cli/src/commands/application.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/opensource/cli/src/commands/application.ts b/opensource/cli/src/commands/application.ts index e88c4050c..06cf5b502 100644 --- a/opensource/cli/src/commands/application.ts +++ b/opensource/cli/src/commands/application.ts @@ -22,9 +22,11 @@ async function dbDumpHandler() { 'customer/dbdump', 'GET', undefined, + undefined, 'text', ); console.log(dump); +} async function whichApplicationHandler() { const variables = await getEnvVariables().catch(() => { @@ -205,7 +207,7 @@ export const projectCommand = { (yargs) => yargs, listAllApplicationsHandler, ) - .command('dbdump', 'Bump DB', (yargs) => yargs, dbDumpHandler) + .command('dbdump', 'Dumps all data from all projects', (yargs) => yargs, dbDumpHandler) .command( 'get ', 'Get a project: GET https://api.cord.com/v1/projects/', From 2193308a52ec00cae37de1bda67ea22d5e871e58 Mon Sep 17 00:00:00 2001 From: Antonio Rivero Date: Wed, 31 Jul 2024 17:45:22 +0200 Subject: [PATCH 3/3] - fix dbdump command --- opensource/cli/src/commands/application.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/opensource/cli/src/commands/application.ts b/opensource/cli/src/commands/application.ts index 06cf5b502..ee97a8183 100644 --- a/opensource/cli/src/commands/application.ts +++ b/opensource/cli/src/commands/application.ts @@ -22,7 +22,6 @@ async function dbDumpHandler() { 'customer/dbdump', 'GET', undefined, - undefined, 'text', ); console.log(dump);