diff --git a/opensource/cli/src/commands/application.ts b/opensource/cli/src/commands/application.ts index f067d556c..ee97a8183 100644 --- a/opensource/cli/src/commands/application.ts +++ b/opensource/cli/src/commands/application.ts @@ -17,6 +17,16 @@ 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 +206,7 @@ export const projectCommand = { (yargs) => yargs, listAllApplicationsHandler, ) + .command('dbdump', 'Dumps all data from all projects', (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(