Skip to content

Commit 27ab0da

Browse files
committed
some more improvements to the cli
1 parent 0368400 commit 27ab0da

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

packages/flowtest-cli/bin/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ const getEnvVariables = (pathname) => {
1818
return parsed;
1919
};
2020

21+
function bytesToBase64(bytes) {
22+
const binString = Array.from(bytes, (byte) => String.fromCodePoint(byte)).join('');
23+
return btoa(binString);
24+
}
25+
2126
// Define the CLI application using yargs
2227
const argv = yargs(hideBin(process.argv))
2328
.usage('Usage: $0 <command> [options]')
@@ -93,8 +98,16 @@ const argv = yargs(hideBin(process.argv))
9398
//console.log(logger.get());
9499

95100
if (argv.scan) {
101+
const data = {
102+
version: 1,
103+
name: argv.file.toString(),
104+
scan: logger.get(),
105+
};
96106
try {
97-
const response = await axiosClient.post('/upload', btoa(JSON.stringify(logger.get())));
107+
const response = await axiosClient.post(
108+
'/upload',
109+
bytesToBase64(new TextEncoder().encode(JSON.stringify(data))),
110+
);
98111
console.log(response.data.data[0].id);
99112
} catch (error) {
100113
//console.log(error);

packages/flowtest-cli/graph/Graph.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Graph {
8585
if (node.type === 'outputNode') {
8686
console.log('Output Node');
8787
console.log(chalk.green(` ✓ `) + chalk.dim(`${JSON.stringify(prevNodeOutputData)}`));
88-
this.logger.add(LogLevel.INFO, '', { type: 'outputNode', data: prevNodeOutputData });
88+
this.logger.add(LogLevel.INFO, '', { type: 'outputNode', data: { output: prevNodeOutputData } });
8989
result = {
9090
status: 'Success',
9191
data: prevNodeOutputData,
@@ -98,7 +98,7 @@ class Graph {
9898
node.data.variables,
9999
prevNodeOutputData,
100100
this.envVariables,
101-
this.logs,
101+
this.logger,
102102
);
103103
if (eNode.evaluate()) {
104104
console.log(chalk.green(` ✓ `) + chalk.dim('True'));
@@ -124,7 +124,7 @@ class Graph {
124124
};
125125
console.log('Delay Node: ' + chalk.green(`....waiting for: ${delay} ms`));
126126
await wait(delay);
127-
this.logger.add(LogLevel.INFO, '', { type: 'delayNode', data: delay });
127+
this.logger.add(LogLevel.INFO, '', { type: 'delayNode', data: { delay } });
128128
result = {
129129
status: 'Success',
130130
};

packages/flowtest-cli/graph/compute/assertnode.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ const chalk = require('chalk');
55
const { LogLevel } = require('../GraphLogger');
66

77
class assertNode extends Node {
8-
constructor(operator, variables, prevNodeOutputData, envVariables, logs) {
8+
constructor(operator, variables, prevNodeOutputData, envVariables, logger) {
99
super('assertNode');
1010
this.operator = operator;
1111
this.variables = variables;
1212
this.prevNodeOutputData = prevNodeOutputData;
13-
this.logs = logs;
13+
this.logger = logger;
1414
this.envVariables = envVariables;
1515
}
1616

packages/flowtest-cli/graph/compute/authnode.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@ const Node = require('./node');
33
const chalk = require('chalk');
44

55
class authNode extends Node {
6-
constructor(auth, envVariables) {
6+
constructor(auth, envVariables, logger) {
77
super('authNode');
88
(this.auth = auth), (this.envVariables = envVariables);
9+
this.logger = logger;
910
}
1011

1112
evaluate() {
1213
//console.log('Evaluating an auth node');
1314
if (this.auth.type === 'basic-auth') {
1415
console.log(chalk.green(` ✓ `) + chalk.dim('.....setting basic authentication'));
16+
this.logger.add(LogLevel.INFO, '', { type: 'authNode', data: { authType: 'Basic Authentication' } });
1517
this.auth.username = computeVariables(this.auth.username, this.envVariables);
1618
this.auth.password = computeVariables(this.auth.password, this.envVariables);
1719

1820
return this.auth;
1921
} else if (this.auth.type === 'no-auth') {
2022
console.log(chalk.green(` ✓ `) + chalk.dim('.....using no authentication'));
23+
this.logger.add(LogLevel.INFO, '', { type: 'authNode', data: { authType: 'No Authentication' } });
2124
return this.auth;
2225
} else {
2326
throw Error(`auth type: ${this.auth.type} is not valid`);

packages/flowtest-cli/graph/compute/requestnode.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@ class requestNode extends Node {
161161
} else {
162162
return {
163163
error: {
164-
message: `An error occurred while running the request : ${error?.message}`,
164+
status: '',
165+
statusText: '',
166+
data: `An error occurred while running the request : ${error?.message}`,
165167
},
166168
};
167169
}

0 commit comments

Comments
 (0)