UNPKG

@curvenote/cli

Version:
57 lines (56 loc) 2.09 kB
import CLIENT_VERSION from '../../version.js'; import chalk from 'chalk'; import boxen from 'boxen'; export function logUpdateRequired({ current, minimum, upgradeCommand, twitter, }) { 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(`@${twitter}`)} for updates!\nhttps://twitter.com/${twitter}`, { 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) { var _a; // Check for client version rejection api.curvenote.com if (response.status === 400) { log.debug(`Request failed: ${JSON.stringify(body)}`); if (((_a = body === null || body === void 0 ? void 0 : body.errors) === null || _a === void 0 ? void 0 : _a[0].code) === 'outdated_client') { logUpdateRequired({ current: CLIENT_VERSION, minimum: 'latest', upgradeCommand: 'npm i -g curvenote@latest', twitter: 'curvenote', }); } } } /** * 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', twitter: 'curvenote', })); process.exit(1); } } }