Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions opensource/cli/src/commands/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ async function listAllApplicationsHandler() {
prettyPrint(apps);
}

async function dbDumpHandler() {
const dump = await fetchCordManagementApi<ApplicationData[]>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it should be fetchCordManagementApi<string>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true I'll change it

'customer/dbdump',
'GET',
undefined,
'text',
);
console.log(dump);
}

async function whichApplicationHandler() {
const variables = await getEnvVariables().catch(() => {
/* no op, catch below instead */
Expand Down Expand Up @@ -196,6 +206,7 @@ export const projectCommand = {
(yargs) => yargs,
listAllApplicationsHandler,
)
.command('dbdump', 'Dumps all data from all projects', (yargs) => yargs, dbDumpHandler)
.command(
'get <id>',
'Get a project: GET https://api.cord.com/v1/projects/<ID>',
Expand Down
3 changes: 2 additions & 1 deletion opensource/cli/src/fetchCordRESTApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export async function fetchCordManagementApi<T>(
endpoint: string,
method: 'GET' | 'PUT' | 'POST' | 'DELETE' = 'GET',
body?: string,
type: 'json' | 'text' = 'json',
): Promise<T> {
const env = await getEnvVariables().catch(() => {
/*no-op. probably just doesn't exist yet*/
Expand Down Expand Up @@ -80,7 +81,7 @@ export async function fetchCordManagementApi<T>(
});

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(
Expand Down