@curvenote/cli
Version:
CLI Client library for Curvenote
56 lines (55 loc) • 1.99 kB
JavaScript
import CLIENT_VERSION from '../../version.js';
import chalk from 'chalk';
import boxen from 'boxen';
function logUpdateRequired({ current, minimum, upgradeCommand, bluesky, }) {
return boxen(`Upgrade Required! ${chalk.dim(`v${current}`)} ≫ ${chalk.green.bold(`v${minimum} (minimum)`)}\n\nRun \`${chalk.cyanBright.bold(upgradeCommand)}\` to update.\n\nFollow ${chalk.yellowBright(`@${bluesky}`)} for updates!\nhttps://bsky.app/profile/${bluesky}`, {
padding: 1,
margin: 1,
borderColor: 'red',
borderStyle: 'round',
textAlignment: 'center',
});
}
/**
* This requires the body to be decoded as json and so is called later in the response handling chain
*
* @param log
* @param response
* @param body
*/
export function checkForCurvenoteAPIClientVersionRejection(log, response, body) {
// Check for client version rejection api.curvenote.com
if (response.status === 400) {
log.debug(`Request failed: ${JSON.stringify(body)}`);
if (body?.errors?.[0].code === 'outdated_client') {
logUpdateRequired({
current: CLIENT_VERSION,
minimum: 'latest',
upgradeCommand: 'npm i -g curvenote@latest',
bluesky: 'curvenote.com',
});
}
}
}
/**
* This should be called immedately after the fetch
*
* @param log
* @param response
*/
export function checkForPlatformAPIClientVersionRejection(log, response) {
// Check for client version rejection sites.curvenote.com
if (response.status === 403) {
const minimum = response.headers.get('x-minimum-client-version');
if (minimum != null) {
log.debug(response.statusText);
log.error(logUpdateRequired({
current: CLIENT_VERSION,
minimum,
upgradeCommand: 'npm i -g curvenote@latest',
bluesky: 'curvenote.com',
}));
process.exit(1);
}
}
}