Skip to content

Commit

Permalink
Merging changes from PR 2129
Browse files Browse the repository at this point in the history
  • Loading branch information
yolih committed Nov 27, 2024
2 parents 5126491 + e0f471f commit 27ff515
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 46 deletions.
2 changes: 1 addition & 1 deletion __tests__/bin/vip-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ describe( 'getLogs', () => {

expect( exit.withError ).toHaveBeenCalledTimes( 1 );
expect( exit.withError ).toHaveBeenCalledWith(
'Invalid format: jso. The supported formats are: csv, json, table.'
'Invalid format: jso. The supported formats are: csv, json, table, text.'
);

expect( logsLib.getRecentLogs ).not.toHaveBeenCalled();
Expand Down
4 changes: 2 additions & 2 deletions assets/dev-env.lando.template.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ tooling:
nocopy: true
- type: volume
source: clientcode_vipconfig
target: /wp/wp-content/vip-config
target: /wp/vip-config
volume:
nocopy: true
<% } else { %>
Expand All @@ -342,6 +342,6 @@ tooling:
- <%= appCode.dir %>/plugins:/wp/wp-content/plugins
- <%= appCode.dir %>/private:/wp/wp-content/private
- <%= appCode.dir %>/themes:/wp/wp-content/themes
- <%= appCode.dir %>/vip-config:/wp/wp-content/vip-config
- <%= appCode.dir %>/vip-config:/wp/vip-config
<% } %>
<% } %>
15 changes: 13 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
## Changelog

### 3.9.0

* feat(dev-env): add support for PHP 8.4
* Provide dedicated error message for when a token is marked as disabled due to inactivity
* Set the mount path for vip-config to ABSPATH/vip-config to match production
* Add --format="text" option to vip logs
* build(deps-dev): bump typescript from 5.6.3 to 5.7.2
* build(deps-dev): bump @types/node from 22.9.1 to 22.10.0

**Full Changelog**: https://github.com/Automattic/vip-cli/compare/3.8.8...3.9.0

### 3.8.8

* build(deps-dev): bump @types/dockerode from 3.3.31 to 3.3.32
Expand Down Expand Up @@ -54,7 +65,7 @@
* build(deps): bump uuid from 11.0.2 to 11.0.3
* Update socket error handler
* Fix --limit arg handling in vip logs command
* New package release: v3.9.0 by
* New package release: v3.9.0 by
* Revert "New package release: v3.9.0"
* chore(deps): update Lando to 6ca2668
* fix: `table` format output
Expand Down Expand Up @@ -151,7 +162,7 @@
* build(deps-dev): bump @babel/core from 7.24.8 to 7.24.9 in the babel group
* build(deps-dev): bump @types/dockerode from 3.3.29 to 3.3.30
* update: media import validate-files

**Full Changelog**: https://github.com/Automattic/vip-cli/compare/3.6.0...3.7.0

### 3.6.0
Expand Down
44 changes: 22 additions & 22 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@automattic/vip",
"version": "3.8.9-dev.0",
"version": "3.9.1-dev.0",
"description": "The VIP Javascript library & CLI",
"main": "index.js",
"bin": {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/vip-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import app from '../lib/api/app';
import command, { getEnvIdentifier } from '../lib/cli/command';
import { trackEvent } from '../lib/tracker';

command( { requiredArgs: 1, format: true } )
command( { requiredArgs: 1 } )
.example(
'vip app list',
'Retrieve a list of applications that can be accessed by the current authenticated VIP-CLI user.'
Expand Down
15 changes: 12 additions & 3 deletions src/bin/vip-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const LIMIT_MIN = 1;
const LIMIT_MAX = 5000;
const LIMIT_DEFAULT = 500;
const ALLOWED_TYPES = [ 'app', 'batch' ];
const ALLOWED_FORMATS = [ 'csv', 'json', 'table' ];
const ALLOWED_FORMATS = [ 'csv', 'json', 'table', 'text' ];
const DEFAULT_POLLING_DELAY_IN_SECONDS = 30;
const MIN_POLLING_DELAY_IN_SECONDS = 5;
const MAX_POLLING_DELAY_IN_SECONDS = 300;
Expand Down Expand Up @@ -148,7 +148,7 @@ function printLogs( logs, format ) {
} );

let output = '';
if ( format && 'table' === format ) {
if ( 'table' === format ) {
const options = {
wordWrap: true,
wrapOnWordBoundary: true,
Expand Down Expand Up @@ -179,6 +179,12 @@ function printLogs( logs, format ) {
}

output = table.toString();
} else if ( 'text' === format ) {
const rows = [];
for ( const { timestamp, message } of logs ) {
rows.push( `${ timestamp } ${ message }` );
output = rows.join( '\n' );
}
} else {
output = formatData( logs, format );
}
Expand Down Expand Up @@ -243,7 +249,10 @@ command( {
`The maximum number of entries to return. Accepts an integer value between 1 and 5000 (defaults to ${ LIMIT_DEFAULT }).`
)
.option( 'follow', 'Output new entries as they are generated.' )
.option( 'format', 'Render output in a particular format. Accepts “csv” and “json”.', 'table' )
.option(
'format',
'Render output in a particular format. Accepts “table“ (default), “csv“, “json“, and “text”.'
)
.examples( [
{
usage: 'vip @example-app.production logs',
Expand Down
3 changes: 1 addition & 2 deletions src/bin/vip-slowlogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void command( {
appContext: true,
appQuery,
envContext: true,
format: false,
format: true,
module: 'slowlogs',
usage: baseUsage,
} )
Expand All @@ -199,7 +199,6 @@ void command( {
'Set the maximum number of log entries. Accepts an integer value between 1 and 500.',
500
)
.option( 'format', 'Render output in a particular format. Accepts “csv” and “json”.', 'table' )
.examples( [
{
description:
Expand Down
4 changes: 2 additions & 2 deletions src/bin/vip-validate-preflight.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ function sanitizeArgsForTracking( args ) {

let commandOpts = {
module: 'harmonia',
format: true,
};

// The @app.env selector is optional, so we need to check if it was passed
Expand Down Expand Up @@ -605,8 +606,7 @@ command( { commandOpts, usage } )
[ 'p', 'port' ],
'Set a port for the application. (Defaults to a random value between 3001 and 3999)'
)
.option( 'format', 'Render output in a particular format. Accepts “csv” and “json”.', 'table' )
.option( [ 'P', 'path' ], 'Path to a local Node.js application directory.', process.cwd() )
.option( [ 'P', 'path' ], 'Path to the app to be tested', process.cwd() )
.examples( [
{
usage: 'vip validate preflight',
Expand Down
2 changes: 2 additions & 0 deletions src/commands/export-sql.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ export type AppBackupAndJobStatusQuery = {
environments?: Array< {
__typename?: 'AppEnvironment';
id?: number | null;
backupsSqlDumpTool?: string | null;
latestBackup?: {
__typename?: 'Backup';
id?: number | null;
type?: string | null;
size?: number | null;
filename?: string | null;
sqlDumpTool?: string | null;
createdAt?: string | null;
} | null;
jobs?: Array<
Expand Down
23 changes: 21 additions & 2 deletions src/commands/export-sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ const BACKUP_AND_JOB_STATUS_QUERY = gql`
id
environments(id: $envId) {
id
backupsSqlDumpTool
latestBackup {
id
type
size
filename
sqlDumpTool
createdAt
}
jobs(jobTypes: [db_backup_copy]) {
Expand Down Expand Up @@ -98,6 +100,7 @@ async function fetchLatestBackupAndJobStatusBase(
): Promise< {
latestBackup: Backup | undefined;
jobs: Job[];
envSqlDumpTool: string | null | undefined;
} > {
const api = API();

Expand All @@ -108,11 +111,12 @@ async function fetchLatestBackupAndJobStatusBase(
} );

const environments = response.data.app?.environments;
const envSqlDumpTool = environments?.[ 0 ]?.backupsSqlDumpTool;

const latestBackup: Backup | undefined = environments?.[ 0 ]?.latestBackup as Backup;
const jobs: Job[] = ( environments?.[ 0 ]?.jobs || [] ) as Job[];

return { latestBackup, jobs };
return { latestBackup, jobs, envSqlDumpTool };
}

async function fetchLatestBackupAndJobStatus(
Expand Down Expand Up @@ -412,7 +416,10 @@ export class ExportSQLCommand {
await this.runBackupJob();
}

const { latestBackup } = await fetchLatestBackupAndJobStatus( this.app.id, this.env.id );
const { latestBackup, envSqlDumpTool } = await fetchLatestBackupAndJobStatus(
this.app.id,
this.env.id
);

if ( ! latestBackup ) {
await this.track( 'error', {
Expand All @@ -436,6 +443,18 @@ export class ExportSQLCommand {
);
}

const showMyDumperWarning = ( latestBackup.sqlDumpTool ?? envSqlDumpTool ) === 'mydumper';
if ( showMyDumperWarning ) {
console.warn(
chalk.yellow.bold( 'WARNING:' ),
chalk.yellow(
'This is a large or complex database. The backup file for this database is generated with MyDumper. ' +
'The file can only be loaded with MyLoader. ' +
'For more information: https://github.com/mydumper/mydumper'
)
);
}

if ( await this.getExportJob() ) {
console.log(
`Attaching to an existing export for the backup with timestamp ${ latestBackup.createdAt }`
Expand Down
1 change: 1 addition & 0 deletions src/graphqlTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ export type Backup = {
filename?: Maybe< Scalars[ 'String' ][ 'output' ] >;
id?: Maybe< Scalars[ 'Float' ][ 'output' ] >;
size?: Maybe< Scalars[ 'Float' ][ 'output' ] >;
sqlDumpTool?: Maybe< Scalars[ 'String' ][ 'output' ] >;
type?: Maybe< Scalars[ 'String' ][ 'output' ] >;
};

Expand Down
26 changes: 21 additions & 5 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
} from '@apollo/client/core';
import { setContext } from '@apollo/client/link/context';
import { ApolloLink } from '@apollo/client/link/core';
import { onError } from '@apollo/client/link/error';
import { ErrorResponse, onError } from '@apollo/client/link/error';
import { ServerError } from '@apollo/client/link/utils';
import chalk from 'chalk';

import http from './api/http';
Expand All @@ -30,17 +31,32 @@ export function enableGlobalGraphQLErrorHandling(): void {
globalGraphQLErrorHandlingEnabled = true;
}

function isServerError(
networkError: ErrorResponse[ 'networkError' ]
): networkError is ServerError {
if ( ! networkError ) {
return false;
}
return 'result' in networkError;
}

export default function API( {
exitOnError = true,
}: {
exitOnError?: boolean;
} = {} ): ApolloClient< NormalizedCacheObject > {
const errorLink = onError( ( { networkError, graphQLErrors } ) => {
if ( networkError && 'statusCode' in networkError && networkError.statusCode === 401 ) {
console.error(
chalk.red( 'Unauthorized:' ),
'You are unauthorized to perform this request, please logout with `vip logout` then try again.'
);
let message =
'You are not authorized to perform this request; please logout with `vip logout`, then try again.';
if (
isServerError( networkError ) &&
networkError.result?.code === 'token-disabled-inactivity'
) {
message =
'Your token has been disabled due to inactivity; please log out with `vip logout`, then try again.';
}
console.error( chalk.red( 'Unauthorized:' ), message );
process.exit( 1 );
}

Expand Down
Loading

0 comments on commit 27ff515

Please sign in to comment.