Skip to content

Commit ff13436

Browse files
committed
Upgrade dependencies, Optional compression, Fix inspect command
1 parent f965126 commit ff13436

20 files changed

+2542
-1924
lines changed

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"bracketSpacing": false,
3+
"eslintIntegration": true,
4+
"singleQuote": true,
5+
"printWidth": 120
6+
}

bin/dropstack-account

Lines changed: 81 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,68 +16,96 @@ program
1616
.action(() => account({reset: program.reset, token: program.token}))
1717
.parse(process.argv);
1818

19-
if(!program.args.length) account(program.opts());
19+
if (!program.args.length) account(program.opts());
2020

2121
function account({reset, token}) {
2222
configuration
23-
.load()
24-
.then(settings => {
25-
console.log(chalk.green(`Account information for ${chalk.green.underline(settings.username || '-')} on ${chalk.green.underline(settings.url || '-')}`));
26-
if(!(settings.token && settings.username)) return Promise.reject(new Error('Sign in failed'))
27-
return settings;
28-
})
29-
.then(settings => reset ? credentials.reset(settings).then(data => Promise.reject(data)) : Promise.resolve(settings))
30-
.then(settings => {
31-
return fetch(`${settings.url}/auth/account`, { headers: { 'Authorization': `Bearer ${settings.token}`, timeout: 10, } })
32-
.then(response => response.status >= 400 ? Promise.reject(new Error(`Response error: ${response.statusText}`)) : response)
33-
.then(response => response.json().then(data => Object.assign({}, data, {version: response.headers.get('x-dropstack-version'), 'support-stateful': response.headers.get('x-dropstack-stateful')})))
34-
.then(data => Object.assign({}, data, settings));
35-
})
36-
.then(data => Boolean(data.message) ? Promise.reject(new Error(data.message)) : data)
37-
.then(data => {
38-
let message = `${chalk.gray(`${pad(15, 'Account ID', ' ')}: ${chalk.white(data.id)}`)}\n`;
39-
message += `${chalk.gray(`${pad(15, 'Server Version', ' ')}: ${chalk.white(data.version)}`)}\n`;
40-
message += `${chalk.gray(`${pad(15, 'Client Version', ' ')}: ${chalk.white(appPackage.version)}`)}\n`;
41-
message += `${chalk.gray(`${pad(15, 'Server URL', ' ')}: ${chalk.white(data.url)}`)}\n`;
42-
message += `${chalk.gray(`${pad(15, 'Signed up', ' ')}: ${chalk.white(new Date(data.signedUpAt))}`)}`;
43-
if(data['support-stateful']) message += `\n${chalk.gray(`${pad(15, 'Stateful', ' ')}: ${chalk.white(data['support-stateful'])}`)}`;
44-
if(data.metadata && data.metadata.plan) message += `\n${chalk.gray(`${pad(15, 'Plan (beta)', ' ')}: ${chalk.white(data.metadata && data.metadata.plan || '-')}`)}`;
45-
if(token) message += `\n${chalk.gray(`${pad(15, 'JSON Web Token', ' ')}: ${chalk.white(data.token)}`)}`;
46-
console.log(boxen(message, {padding: 1, borderColor: 'gray', margin: 1}));
23+
.load()
24+
.then(settings => {
25+
console.log(
26+
chalk.green(
27+
`Account information for ${chalk.green.underline(settings.username || '-')} on ${chalk.green.underline(
28+
settings.url || '-'
29+
)}`
30+
)
31+
);
32+
if (!(settings.token && settings.username)) return Promise.reject(new Error('Sign in failed'));
33+
return settings;
34+
})
35+
.then(
36+
settings => (reset ? credentials.reset(settings).then(data => Promise.reject(data)) : Promise.resolve(settings))
37+
)
38+
.then(settings => {
39+
return fetch(`${settings.url}/auth/account`, {
40+
headers: {Authorization: `Bearer ${settings.token}`, timeout: 10}
41+
})
42+
.then(
43+
response =>
44+
response.status >= 400 ? Promise.reject(new Error(`Response error: ${response.statusText}`)) : response
45+
)
46+
.then(response =>
47+
response.json().then(data =>
48+
Object.assign({}, data, {
49+
version: response.headers.get('x-dropstack-version')
50+
})
51+
)
52+
)
53+
.then(data => Object.assign({}, settings, data));
54+
})
55+
.then(data => (Boolean(data.message) ? Promise.reject(new Error(data.message)) : data))
56+
.then(data => {
57+
let message = `${chalk.gray(`${pad(15, 'Account ID', ' ')}: ${chalk.white(data.id)}`)}\n`;
58+
message += `${chalk.gray(`${pad(15, 'Server Version', ' ')}: ${chalk.white(data.version)}`)}\n`;
59+
message += `${chalk.gray(`${pad(15, 'Client Version', ' ')}: ${chalk.white(appPackage.version)}`)}\n`;
60+
message += `${chalk.gray(`${pad(15, 'Server URL', ' ')}: ${chalk.white(data.url)}`)}`;
61+
if (data.signedUpAt)
62+
message += `\n${chalk.gray(`${pad(15, 'Signed up', ' ')}: ${chalk.white(new Date(data.signedUpAt))}`)}`;
63+
if (data.metadata && data.metadata.plan)
64+
message += `\n${chalk.gray(
65+
`${pad(15, 'Plan (beta)', ' ')}: ${chalk.white((data.metadata && data.metadata.plan) || '-')}`
66+
)}`;
67+
if (token) message += `\n${chalk.gray(`${pad(15, 'JSON Web Token', ' ')}: ${chalk.white(data.token)}`)}`;
68+
console.log(boxen(message, {padding: 1, borderColor: 'gray', margin: 1}));
4769

48-
process.exit(0);
49-
})
50-
.catch(err => {
51-
if(err.message === 'We\'ve just sent you an email to reset your password.') {
52-
console.log(`\n${chalk.yellow(err.message)}`);
53-
return process.exit(0);
54-
}
70+
process.exit(0);
71+
})
72+
.catch(err => {
73+
if (err.message === "We've just sent you an email to reset your password.") {
74+
console.log(`\n${chalk.yellow(err.message)}`);
75+
return process.exit(0);
76+
}
5577

56-
if(err.message === 'canceled') {
57-
console.log(chalk.yellow('\nAborted operation.'));
58-
return process.exit(0);
59-
}
78+
if (err.message === 'canceled') {
79+
console.log(chalk.yellow('\nAborted operation.'));
80+
return process.exit(0);
81+
}
6082

61-
if(err.message === 'Sign in failed'){
62-
console.error(chalk.red(`\nCredentials not found. Use ${chalk.bold('dropstack login <url>')} to verifiy your credentials.`));
63-
process.exit(1);
64-
}
83+
if (err.message === 'Sign in failed') {
84+
console.error(
85+
chalk.red(`\nCredentials not found. Use ${chalk.bold('dropstack login <url>')} to verifiy your credentials.`)
86+
);
87+
process.exit(1);
88+
}
6589

66-
if(err.message === 'Unauthorized'){
67-
console.error(chalk.red(`\nUnauthorized. Use ${chalk.bold('dropstack login <url>')} to verifiy your credentials.`));
68-
process.exit(1);
69-
}
90+
if (err.message === 'Unauthorized') {
91+
console.error(
92+
chalk.red(`\nUnauthorized. Use ${chalk.bold('dropstack login <url>')} to verifiy your credentials.`)
93+
);
94+
process.exit(1);
95+
}
7096

71-
if(err.message === 'Not found') {
72-
console.error(chalk.red(`\nServer communication error occurred! Retry later please.\nError: ${chalk.gray(err.message)}`));
73-
process.exit(1);
74-
}
97+
if (err.message === 'Not found') {
98+
console.error(
99+
chalk.red(`\nServer communication error occurred! Retry later please.\nError: ${chalk.gray(err.message)}`)
100+
);
101+
process.exit(1);
102+
}
75103

76-
console.error(chalk.red(`\nAn unexpected error occurred!\nError: ${chalk.gray(err.message)}`));
77-
process.exit(1);
78-
});
104+
console.error(chalk.red(`\nAn unexpected error occurred!\nError: ${chalk.gray(err.message)}`));
105+
process.exit(1);
106+
});
79107
}
80108

81109
function pad(width, string, padding) {
82-
return (width <= string.length) ? string : pad(width, string + padding, padding)
83-
}
110+
return width <= string.length ? string : pad(width, string + padding, padding);
111+
}

bin/dropstack-activities

Lines changed: 95 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,75 +11,113 @@ program
1111
.action(() => activities({raw: program.raw}))
1212
.parse(process.argv);
1313

14-
if(!program.args.length) activities(program.opts());
14+
if (!program.args.length) activities(program.opts());
1515

1616
function activities({raw}) {
1717
configuration
18-
.load()
19-
.then(settings => { if(!raw) {console.log(`Activities for ${chalk.green.underline(settings.username || '-')} on ${chalk.green.underline(settings.url || '-')}`);} return settings;})
20-
.then(settings => Boolean(!(settings.token && settings.username)) ? Promise.reject(new Error('Sign in failed')) : settings)
21-
.then(settings => {
22-
process.stderr.write('\x1B[?25l'); //hide terminal cursor
23-
const es = new EventSource(`${settings.url}/activities/live`, {headers: {connection: 'keep-alive', 'cache-control': 'no-cache', authorization: `Bearer ${settings.token}`}});
24-
if(!raw) process.stdout.write(chalk.gray(`Connecting...`));
25-
26-
es.onopen = () => {
27-
if(!raw) {
28-
process.stdout.cursorTo(0);
29-
process.stdout.clearLine();
30-
process.stdout.write(`${chalk.green('Connected!')} ${chalk.gray('Receiving data ...')}\n`);
18+
.load()
19+
.then(settings => {
20+
if (!raw) {
21+
console.log(
22+
`Activities for ${chalk.green.underline(settings.username || '-')} on ${chalk.green.underline(
23+
settings.url || '-'
24+
)}`
25+
);
3126
}
32-
};
27+
return settings;
28+
})
29+
.then(
30+
settings =>
31+
Boolean(!(settings.token && settings.username)) ? Promise.reject(new Error('Sign in failed')) : settings
32+
)
33+
.then(settings => {
34+
process.stderr.write('\x1B[?25l'); //hide terminal cursor
35+
const es = new EventSource(`${settings.url}/activities/live`, {
36+
headers: {connection: 'keep-alive', 'cache-control': 'no-cache', authorization: `Bearer ${settings.token}`}
37+
});
38+
if (!raw) process.stdout.write(chalk.gray(`Connecting...`));
39+
40+
es.onopen = () => {
41+
if (!raw) {
42+
process.stdout.cursorTo(0);
43+
process.stdout.clearLine();
44+
process.stdout.write(`${chalk.green('Connected!')} ${chalk.gray('Receiving data ...')}\n`);
45+
}
46+
};
3347

34-
es.onerror = () => {
48+
es.onerror = () => {
49+
process.stderr.write('\x1B[?25h'); //show terminal cursor
50+
console.error('Activity-Stream error occurred. Retry...');
51+
};
52+
53+
es.onmessage = e => {
54+
if (raw && e.data && e.data !== '{}') return console.log(e.data);
55+
try {
56+
const logEntry = JSON.parse(e.data);
57+
if (!logEntry) return;
58+
if (!logEntry.timestamp) return;
59+
console.log(
60+
chalk.gray(
61+
`${chalk.yellow(logEntry.timestamp)} | ${chalk.white(logEntry.id)} | ${chalk.white(
62+
logEntry.topic
63+
)} | ${chalk.white(logEntry.activity)} | ${chalk.white(logEntry.state)}`
64+
)
65+
);
66+
} catch (e) {}
67+
};
68+
})
69+
.catch(err => {
3570
process.stderr.write('\x1B[?25h'); //show terminal cursor
36-
console.error('Activity-Stream error occurred. Retry...');
37-
}
3871

39-
es.onmessage = e => {
40-
if(raw && e.data && e.data !== '{}') return console.log(e.data);
41-
try {
42-
const logEntry = JSON.parse(e.data);
43-
if(!logEntry) return;
44-
if(!logEntry.timestamp) return;
45-
console.log(chalk.gray(`${chalk.yellow(logEntry.timestamp)} | ${chalk.white(logEntry.id)} | ${chalk.white(logEntry.topic)} | ${chalk.white(logEntry.activity)} | ${chalk.white(logEntry.state)}`));
46-
} catch(e){}
47-
}
48-
})
49-
.catch(err => {
50-
process.stderr.write('\x1B[?25h'); //show terminal cursor
72+
if (err.message === 'canceled') {
73+
console.log(chalk.yellow('\nAborted operation.'));
74+
return process.exit(0);
75+
}
5176

52-
if(err.message === 'canceled') {
53-
console.log(chalk.yellow('\nAborted operation.'));
54-
return process.exit(0);
55-
}
77+
if (err.message === 'Error fetching service') {
78+
console.error(
79+
chalk.red(
80+
`\nService not found. Wrong account? Use ${chalk.bold(
81+
'dropstack login <url>'
82+
)} to verifiy your credentials.`
83+
)
84+
);
85+
process.exit(1);
86+
}
5687

57-
if(err.message === 'Error fetching service') {
58-
console.error(chalk.red(`\nService not found. Wrong account? Use ${chalk.bold('dropstack login <url>')} to verifiy your credentials.`));
59-
process.exit(1);
60-
}
88+
if (err.message === 'Sign in failed') {
89+
console.error(
90+
chalk.red(`\nCredentials not found. Use ${chalk.bold('dropstack login <url>')} to verifiy your credentials.`)
91+
);
92+
process.exit(1);
93+
}
6194

62-
if(err.message === 'Sign in failed') {
63-
console.error(chalk.red(`\nCredentials not found. Use ${chalk.bold('dropstack login <url>')} to verifiy your credentials.`));
64-
process.exit(1);
65-
}
95+
if (err.message === 'Unauthorized') {
96+
console.error(
97+
chalk.red(`\nUnauthorized. Use ${chalk.bold('dropstack login <url>')} to verifiy your credentials.`)
98+
);
99+
process.exit(1);
100+
}
66101

67-
if(err.message === 'Unauthorized') {
68-
console.error(chalk.red(`\nUnauthorized. Use ${chalk.bold('dropstack login <url>')} to verifiy your credentials.`));
69-
process.exit(1);
70-
}
102+
if (err.message === 'Service not found') {
103+
console.error(
104+
chalk.red(
105+
`\nService not found. Wrong account? Use ${chalk.bold(
106+
'dropstack login <url>'
107+
)} to verifiy your credentials.`
108+
)
109+
);
110+
process.exit(1);
111+
}
71112

72-
if(err.message === 'Service not found') {
73-
console.error(chalk.red(`\nService not found. Wrong account? Use ${chalk.bold('dropstack login <url>')} to verifiy your credentials.`));
74-
process.exit(1);
75-
}
113+
if (err.message === 'Not found') {
114+
console.error(
115+
chalk.red(`\nServer communication error occurred! Retry later please.\nError: ${chalk.gray(err.message)}`)
116+
);
117+
process.exit(1);
118+
}
76119

77-
if(err.message === 'Not found') {
78-
console.error(chalk.red(`\nServer communication error occurred! Retry later please.\nError: ${chalk.gray(err.message)}`));
120+
console.error(chalk.red(`\nAn unexpected error occurred!\nError: ${chalk.gray(err.message)}`));
79121
process.exit(1);
80-
}
81-
82-
console.error(chalk.red(`\nAn unexpected error occurred!\nError: ${chalk.gray(err.message)}`));
83-
process.exit(1);
84-
});
122+
});
85123
}

0 commit comments

Comments
 (0)