From de6e9456533561d9ca2c097c57b2c4a1def7501f Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Wed, 1 May 2024 23:05:33 +1000 Subject: [PATCH 01/22] Add failureDetailsUrl to import media files --- src/bin/vip-import-media.js | 2 +- src/graphqlTypes.d.ts | 2 + src/lib/media-import/status.generated.d.ts | 1 + src/lib/media-import/status.ts | 53 +++++++++++++--------- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/bin/vip-import-media.js b/src/bin/vip-import-media.js index 84489b3f0..35d3a5cfa 100755 --- a/src/bin/vip-import-media.js +++ b/src/bin/vip-import-media.js @@ -84,8 +84,8 @@ ${ chalk.red.bold( ${ chalk.red.bold( 'only the files present inside that directory will be imported and the rest will be ignored.' ) } -${ chalk.red.bold( 'If no `uploads/` directory is found, all files will be imported, as is.' ) } +${ chalk.red.bold( 'If no `uploads/` directory is found, all files will be imported, as is.' ) } Are you sure you want to import the contents of the url? `, } ) diff --git a/src/graphqlTypes.d.ts b/src/graphqlTypes.d.ts index 66d7f91d4..6b938e956 100644 --- a/src/graphqlTypes.d.ts +++ b/src/graphqlTypes.d.ts @@ -793,6 +793,8 @@ export type AppEnvironmentMediaImportStatus = { siteId?: Maybe< Scalars[ 'Int' ][ 'output' ] >; /** The actual status of the Media Import */ status?: Maybe< Scalars[ 'String' ][ 'output' ] >; + /** URL for the failure details */ + failureDetailsUrl?: Maybe< Scalars[ 'String' ][ 'output' ] >; }; /** Response payload for executing a status change action on a Media Import */ diff --git a/src/lib/media-import/status.generated.d.ts b/src/lib/media-import/status.generated.d.ts index d9febbeaf..cd783adb7 100644 --- a/src/lib/media-import/status.generated.d.ts +++ b/src/lib/media-import/status.generated.d.ts @@ -22,6 +22,7 @@ export type AppQuery = { status?: string | null; filesTotal?: number | null; filesProcessed?: number | null; + failureDetailsUrl?: string | null; failureDetails?: { __typename?: 'AppEnvironmentMediaImportStatusFailureDetails'; previousStatus?: string | null; diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 8b5cf1e6e..8db074f51 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -38,6 +38,7 @@ const IMPORT_MEDIA_PROGRESS_QUERY = gql` status filesTotal filesProcessed + failureDetailsUrl failureDetails { previousStatus globalErrors @@ -280,29 +281,37 @@ ${ maybeExitPrompt } setProgressTrackerSuffix(); progressTracker.print(); - const fileErrors = results.failureDetails?.fileErrors ?? []; - if ( fileErrors.length > 0 ) { - progressTracker.suffix += `${ chalk.yellow( - `⚠️ ${ fileErrors.length } file error(s) have been extracted` - ) }`; - if ( ( results.filesTotal ?? 0 ) - ( results.filesProcessed ?? 0 ) !== fileErrors.length ) { - progressTracker.suffix += `. ${ chalk.italic.yellow( - 'File-errors report size threshold reached.' + if ( results.failureDetailsUrl ) { + progressTracker.suffix += `\n\n${ chalk.yellow( + `⚠️ All errors have been exported to ${ chalk.bold( + results.failureDetailsUrl + ) }. Please check the link for more details.` + ) }\n\n`; + } else { + const fileErrors = results.failureDetails?.fileErrors ?? []; + if ( fileErrors.length > 0 ) { + progressTracker.suffix += `${ chalk.yellow( + `⚠️ ${ fileErrors.length } file error(s) have been extracted` ) }`; - } - const formattedData = buildFileErrors( fileErrors, exportFileErrorsToJson ); - const errorsFile = `media-import-${ app.name ?? '' }-${ Date.now() }${ - exportFileErrorsToJson ? '.json' : '.txt' - }`; - try { - await writeFile( errorsFile, formattedData ); - progressTracker.suffix += `\n\n${ chalk.yellow( - `All errors have been exported to ${ chalk.bold( resolve( errorsFile ) ) }` - ) }\n\n`; - } catch ( writeFileErr ) { - progressTracker.suffix += `\n\n${ chalk.red( - `Could not export errors to file\n${ ( writeFileErr as Error ).message }` - ) }\n\n`; + if ( ( results.filesTotal ?? 0 ) - ( results.filesProcessed ?? 0 ) !== fileErrors.length ) { + progressTracker.suffix += `. ${ chalk.italic.yellow( + 'File-errors report size threshold reached.' + ) }`; + } + const formattedData = buildFileErrors( fileErrors, exportFileErrorsToJson ); + const errorsFile = `media-import-${ app.name ?? '' }-${ Date.now() }${ + exportFileErrorsToJson ? '.json' : '.txt' + }`; + try { + await writeFile( errorsFile, formattedData ); + progressTracker.suffix += `\n\n${ chalk.yellow( + `All errors have been exported to ${ chalk.bold( resolve( errorsFile ) ) }` + ) }\n\n`; + } catch ( writeFileErr ) { + progressTracker.suffix += `\n\n${ chalk.red( + `Could not export errors to file\n${ ( writeFileErr as Error ).message }` + ) }\n\n`; + } } } From ee7e456ed6823dc8e505ac44744a4c4a329442c9 Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Thu, 2 May 2024 12:28:37 +1000 Subject: [PATCH 02/22] graphqlTypes change with codegen --- src/bin/vip-import-media.js | 2 +- src/graphqlTypes.d.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/vip-import-media.js b/src/bin/vip-import-media.js index 35d3a5cfa..84489b3f0 100755 --- a/src/bin/vip-import-media.js +++ b/src/bin/vip-import-media.js @@ -84,8 +84,8 @@ ${ chalk.red.bold( ${ chalk.red.bold( 'only the files present inside that directory will be imported and the rest will be ignored.' ) } - ${ chalk.red.bold( 'If no `uploads/` directory is found, all files will be imported, as is.' ) } + Are you sure you want to import the contents of the url? `, } ) diff --git a/src/graphqlTypes.d.ts b/src/graphqlTypes.d.ts index 6b938e956..e76c31c51 100644 --- a/src/graphqlTypes.d.ts +++ b/src/graphqlTypes.d.ts @@ -783,6 +783,8 @@ export type AppEnvironmentMediaImportStatus = { __typename?: 'AppEnvironmentMediaImportStatus'; /** Media Import failure details */ failureDetails?: Maybe< AppEnvironmentMediaImportStatusFailureDetails >; + /** URL to download the media import error log */ + failureDetailsUrl?: Maybe< Scalars[ 'String' ][ 'output' ] >; /** Total number of media files that were imported */ filesProcessed?: Maybe< Scalars[ 'Int' ][ 'output' ] >; /** Total number of media files that are to be import */ @@ -793,8 +795,6 @@ export type AppEnvironmentMediaImportStatus = { siteId?: Maybe< Scalars[ 'Int' ][ 'output' ] >; /** The actual status of the Media Import */ status?: Maybe< Scalars[ 'String' ][ 'output' ] >; - /** URL for the failure details */ - failureDetailsUrl?: Maybe< Scalars[ 'String' ][ 'output' ] >; }; /** Response payload for executing a status change action on a Media Import */ From a4f22b20ca52fd158c4921132a49aeac01918b64 Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Thu, 2 May 2024 23:29:50 +1000 Subject: [PATCH 03/22] Add prompt to ask user if they want to download the errors from the URL Prettier --- src/lib/media-import/status.ts | 83 +++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 21 deletions(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 8db074f51..1dba776a5 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -1,5 +1,6 @@ import { ApolloClient, NormalizedCacheObject } from '@apollo/client'; import chalk from 'chalk'; +import { prompt } from 'enquirer'; import gql from 'graphql-tag'; import { writeFile } from 'node:fs/promises'; import { resolve } from 'node:path'; @@ -13,7 +14,7 @@ import { Maybe, } from '../../graphqlTypes'; import API from '../../lib/api'; -import { capitalize, formatEnvironment, formatData, RunningSprite } from '../../lib/cli/format'; +import { capitalize, formatData, formatEnvironment, RunningSprite } from '../../lib/cli/format'; import { AppForMediaImport, currentUserCanImportForApp, @@ -272,8 +273,63 @@ ${ maybeExitPrompt } void checkStatus( IMPORT_MEDIA_PROGRESS_POLL_INTERVAL ); } ); + async function exportFailureDetails( + fileErrors: Maybe< AppEnvironmentMediaImportStatusFailureDetailsFileErrors >[] + ) { + const formattedData = buildFileErrors( fileErrors, exportFileErrorsToJson ); + const errorsFile = `media-import-${ app.name ?? '' }-${ Date.now() }${ + exportFileErrorsToJson ? '.json' : '.txt' + }`; + try { + await writeFile( errorsFile, formattedData ); + progressTracker.suffix += `${ chalk.yellow( + `⚠️ All errors have been exported to ${ chalk.bold( resolve( errorsFile ) ) }` + ) }`; + } catch ( writeFileErr ) { + progressTracker.suffix += `${ chalk.red( + `Could not export errors to file\n${ ( writeFileErr as Error ).message }` + ) }`; + } + } + + async function fetchFailureDetails( failureDetailsUrl: string ) { + progressTracker.suffix += ` +============================================================= +Downloading errors details from ${ failureDetailsUrl }... +\n`; + try { + const response = await fetch( failureDetailsUrl ); + return ( await response.json() ) as AppEnvironmentMediaImportStatusFailureDetailsFileErrors[]; + } catch ( err ) { + progressTracker.suffix += `${ chalk.red( + `Could not download error details\n${ ( err as Error ).message }` + ) }`; + throw err; + } + } + + async function promptFailureDetailsDownload( failureDetailsUrl: string ) { + progressTracker.suffix += `${ chalk.yellow( + `⚠️ Error details can be found on ${ chalk.bold( failureDetailsUrl ) }. ` + ) }\n`; + progressTracker.print( { clearAfter: true } ); + + const failureDetails = await prompt( { + type: 'confirm', + name: 'download', + message: 'Do you want to download them now?', + } ); + + if ( ! failureDetails.download ) { + return; + } + + const failureDetailsErrors = await fetchFailureDetails( failureDetailsUrl ); + await exportFailureDetails( failureDetailsErrors ); + } + try { - const results = await getResults(); + const results: AppEnvironmentMediaImportStatus = await getResults(); overallStatus = results.status ?? 'unknown'; progressTracker.stopPrinting(); @@ -282,36 +338,21 @@ ${ maybeExitPrompt } progressTracker.print(); if ( results.failureDetailsUrl ) { - progressTracker.suffix += `\n\n${ chalk.yellow( - `⚠️ All errors have been exported to ${ chalk.bold( - results.failureDetailsUrl - ) }. Please check the link for more details.` - ) }\n\n`; + await promptFailureDetailsDownload( results.failureDetailsUrl as unknown as string ); } else { + // Falls back to exporting errors to a local file const fileErrors = results.failureDetails?.fileErrors ?? []; if ( fileErrors.length > 0 ) { progressTracker.suffix += `${ chalk.yellow( `⚠️ ${ fileErrors.length } file error(s) have been extracted` ) }`; + if ( ( results.filesTotal ?? 0 ) - ( results.filesProcessed ?? 0 ) !== fileErrors.length ) { progressTracker.suffix += `. ${ chalk.italic.yellow( 'File-errors report size threshold reached.' ) }`; } - const formattedData = buildFileErrors( fileErrors, exportFileErrorsToJson ); - const errorsFile = `media-import-${ app.name ?? '' }-${ Date.now() }${ - exportFileErrorsToJson ? '.json' : '.txt' - }`; - try { - await writeFile( errorsFile, formattedData ); - progressTracker.suffix += `\n\n${ chalk.yellow( - `All errors have been exported to ${ chalk.bold( resolve( errorsFile ) ) }` - ) }\n\n`; - } catch ( writeFileErr ) { - progressTracker.suffix += `\n\n${ chalk.red( - `Could not export errors to file\n${ ( writeFileErr as Error ).message }` - ) }\n\n`; - } + await exportFailureDetails( fileErrors ); } } From fe958bda62b50b75a509d3e7e01aabeb60ce6eaa Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Fri, 3 May 2024 15:51:57 +1000 Subject: [PATCH 04/22] Add unique link expiration message to the output --- src/lib/media-import/status.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 1dba776a5..eb323888d 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -310,7 +310,9 @@ Downloading errors details from ${ failureDetailsUrl }... async function promptFailureDetailsDownload( failureDetailsUrl: string ) { progressTracker.suffix += `${ chalk.yellow( - `⚠️ Error details can be found on ${ chalk.bold( failureDetailsUrl ) }. ` + `⚠️ Error details can be found on ${ chalk.bold( + failureDetailsUrl + ) } ${ chalk.italic.yellow( '(unique link expires in 15 minutes)' ) }. ` ) }\n`; progressTracker.print( { clearAfter: true } ); From 2e4a8327a526bd056d3bb50c3f7556e20e917f61 Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Mon, 6 May 2024 17:17:19 +1000 Subject: [PATCH 05/22] Reword error details url message --- src/lib/media-import/status.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index eb323888d..0fe6eb1ec 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -312,14 +312,16 @@ Downloading errors details from ${ failureDetailsUrl }... progressTracker.suffix += `${ chalk.yellow( `⚠️ Error details can be found on ${ chalk.bold( failureDetailsUrl - ) } ${ chalk.italic.yellow( '(unique link expires in 15 minutes)' ) }. ` + ) } ${ chalk.italic.yellow( + '(file will be stored in the server for 7 days and its unique link expires in 15 minutes)' + ) }. ` ) }\n`; progressTracker.print( { clearAfter: true } ); const failureDetails = await prompt( { type: 'confirm', name: 'download', - message: 'Do you want to download them now?', + message: 'Download error details now?', } ); if ( ! failureDetails.download ) { From fd9843f414f3294f892d1ecdbb120b1aa582a248 Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Mon, 6 May 2024 21:29:44 +1000 Subject: [PATCH 06/22] Add api version variable to StartMediaImport call --- src/bin/vip-import-media.js | 3 +++ src/graphqlTypes.d.ts | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/bin/vip-import-media.js b/src/bin/vip-import-media.js index 84489b3f0..dd8985a72 100755 --- a/src/bin/vip-import-media.js +++ b/src/bin/vip-import-media.js @@ -12,6 +12,8 @@ import { MediaImportProgressTracker } from '../lib/media-import/progress'; import { mediaImportCheckStatus } from '../lib/media-import/status'; import { trackEventWithEnv } from '../lib/tracker'; +const API_VERSION = 'v2'; + const appQuery = ` id, name, @@ -142,6 +144,7 @@ Importing Media into your App... archiveUrl: url, overwriteExistingFiles, importIntermediateImages, + apiVersion: API_VERSION, }, }, } ); diff --git a/src/graphqlTypes.d.ts b/src/graphqlTypes.d.ts index e76c31c51..4efd8e84d 100644 --- a/src/graphqlTypes.d.ts +++ b/src/graphqlTypes.d.ts @@ -946,6 +946,8 @@ export type AppEnvironmentStartDbBackupCopyPayload = { /** Mutation request input to start a Media Import */ export type AppEnvironmentStartMediaImportInput = { + /** API version to be used for the media import */ + apiVersion?: InputMaybe< Scalars[ 'String' ][ 'input' ] >; /** The unique ID of the Application */ applicationId: Scalars[ 'Int' ][ 'input' ]; /** Publicly accessible URL that contains an archive of the media files to be imported */ From 1d2e88d2e85781e4fa835b3ea467b8b9cbe88215 Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Wed, 8 May 2024 11:07:11 +1000 Subject: [PATCH 07/22] Address wording feedback --- src/lib/media-import/status.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 0fe6eb1ec..38f5ae185 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -302,7 +302,7 @@ Downloading errors details from ${ failureDetailsUrl }... return ( await response.json() ) as AppEnvironmentMediaImportStatusFailureDetailsFileErrors[]; } catch ( err ) { progressTracker.suffix += `${ chalk.red( - `Could not download error details\n${ ( err as Error ).message }` + `Could not download file import errors report\n${ ( err as Error ).message }` ) }`; throw err; } @@ -313,7 +313,7 @@ Downloading errors details from ${ failureDetailsUrl }... `⚠️ Error details can be found on ${ chalk.bold( failureDetailsUrl ) } ${ chalk.italic.yellow( - '(file will be stored in the server for 7 days and its unique link expires in 15 minutes)' + '(This link will be valid for the next 15 minutes. The report is retained for 7 days since the import was run.)' ) }. ` ) }\n`; progressTracker.print( { clearAfter: true } ); @@ -321,7 +321,7 @@ Downloading errors details from ${ failureDetailsUrl }... const failureDetails = await prompt( { type: 'confirm', name: 'download', - message: 'Download error details now?', + message: 'Download file import errors report now?', } ); if ( ! failureDetails.download ) { @@ -348,7 +348,7 @@ Downloading errors details from ${ failureDetailsUrl }... const fileErrors = results.failureDetails?.fileErrors ?? []; if ( fileErrors.length > 0 ) { progressTracker.suffix += `${ chalk.yellow( - `⚠️ ${ fileErrors.length } file error(s) have been extracted` + `⚠️ ${ fileErrors.length } file import error(s) were found` ) }`; if ( ( results.filesTotal ?? 0 ) - ( results.filesProcessed ?? 0 ) !== fileErrors.length ) { From e3ee5401d0f8f7df7213846b5818a1e304705d25 Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Wed, 8 May 2024 17:02:24 +1000 Subject: [PATCH 08/22] Add message about expired link --- src/lib/media-import/status.ts | 50 +++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 38f5ae185..d9fbce707 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -332,37 +332,61 @@ Downloading errors details from ${ failureDetailsUrl }... await exportFailureDetails( failureDetailsErrors ); } + function linkExpiredOutput( results: AppEnvironmentMediaImportStatus ) { + if ( + results.filesTotal && + results.filesProcessed && + results.filesTotal !== results.filesProcessed + ) { + const errorsFound = results.filesTotal - results.filesProcessed; + progressTracker.suffix += `${ chalk.yellow( + `⚠️ ${ errorsFound } error(s) were found. File import errors report link expired.` + ) }`; + } + } + + async function exportLocallyOutput( + fileErrors: Maybe< AppEnvironmentMediaImportStatusFailureDetailsFileErrors >[], + results: AppEnvironmentMediaImportStatus + ) { + progressTracker.suffix += `${ chalk.yellow( + `⚠️ ${ fileErrors.length } file import error(s) were found` + ) }`; + + if ( ( results.filesTotal ?? 0 ) - ( results.filesProcessed ?? 0 ) !== fileErrors.length ) { + progressTracker.suffix += `. ${ chalk.italic.yellow( + 'File import errors report size threshold reached.' + ) }`; + } + await exportFailureDetails( fileErrors ); + } + try { const results: AppEnvironmentMediaImportStatus = await getResults(); overallStatus = results.status ?? 'unknown'; progressTracker.stopPrinting(); - setProgressTrackerSuffix(); progressTracker.print(); if ( results.failureDetailsUrl ) { await promptFailureDetailsDownload( results.failureDetailsUrl as unknown as string ); } else { - // Falls back to exporting errors to a local file const fileErrors = results.failureDetails?.fileErrors ?? []; + if ( fileErrors.length > 0 ) { - progressTracker.suffix += `${ chalk.yellow( - `⚠️ ${ fileErrors.length } file import error(s) were found` - ) }`; - - if ( ( results.filesTotal ?? 0 ) - ( results.filesProcessed ?? 0 ) !== fileErrors.length ) { - progressTracker.suffix += `. ${ chalk.italic.yellow( - 'File-errors report size threshold reached.' - ) }`; - } - await exportFailureDetails( fileErrors ); + // Errors were observed and are present in the dto + // Fall back to exporting errors to local file + await exportLocallyOutput( fileErrors, results ); + } else { + // Errors are not present in the dto + // And file error details report link is not available + linkExpiredOutput( results ); } } // Print one final time progressTracker.print( { clearAfter: true } ); - process.exit( 0 ); } catch ( importFailed ) { progressTracker.stopPrinting(); From 63d000a9d778a47dd57c3d1339fb4f2dc0751e66 Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Thu, 9 May 2024 10:46:08 +1000 Subject: [PATCH 09/22] Apply suggestions from code review Modify expiration message Rename output functions signatures Co-authored-by: Sarosh Aga --- src/lib/media-import/status.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index d9fbce707..3327c029f 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -313,7 +313,7 @@ Downloading errors details from ${ failureDetailsUrl }... `⚠️ Error details can be found on ${ chalk.bold( failureDetailsUrl ) } ${ chalk.italic.yellow( - '(This link will be valid for the next 15 minutes. The report is retained for 7 days since the import was run.)' + '(This link will be valid for the next 15 minutes. The report is retained for 7 days from the completion of the import.)' ) }. ` ) }\n`; progressTracker.print( { clearAfter: true } ); @@ -332,7 +332,7 @@ Downloading errors details from ${ failureDetailsUrl }... await exportFailureDetails( failureDetailsErrors ); } - function linkExpiredOutput( results: AppEnvironmentMediaImportStatus ) { + function printFileErrorsReportLinkExpiredError( results: AppEnvironmentMediaImportStatus ) { if ( results.filesTotal && results.filesProcessed && @@ -345,7 +345,7 @@ Downloading errors details from ${ failureDetailsUrl }... } } - async function exportLocallyOutput( + async function printFailureDetails( fileErrors: Maybe< AppEnvironmentMediaImportStatusFailureDetailsFileErrors >[], results: AppEnvironmentMediaImportStatus ) { From fe5dc28f6ddfbac689b06c4b7b5337e3ac3ec3be Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Thu, 9 May 2024 10:59:54 +1000 Subject: [PATCH 10/22] Fix errors caused by change of the signature and not applying it to the function call --- src/lib/media-import/status.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 3327c029f..f7424d501 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -377,11 +377,11 @@ Downloading errors details from ${ failureDetailsUrl }... if ( fileErrors.length > 0 ) { // Errors were observed and are present in the dto // Fall back to exporting errors to local file - await exportLocallyOutput( fileErrors, results ); + await printFailureDetails( fileErrors, results ); } else { // Errors are not present in the dto // And file error details report link is not available - linkExpiredOutput( results ); + printFileErrorsReportLinkExpiredError( results ); } } From 215be5f5360c250e69f20f7eb230664849ade65b Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Thu, 9 May 2024 13:29:05 +1000 Subject: [PATCH 11/22] Add break line in expiration message --- src/lib/media-import/status.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index f7424d501..0ff5a6256 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -312,7 +312,7 @@ Downloading errors details from ${ failureDetailsUrl }... progressTracker.suffix += `${ chalk.yellow( `⚠️ Error details can be found on ${ chalk.bold( failureDetailsUrl - ) } ${ chalk.italic.yellow( + ) }\n${ chalk.italic.yellow( '(This link will be valid for the next 15 minutes. The report is retained for 7 days from the completion of the import.)' ) }. ` ) }\n`; From 17a4e93d3525ff69254cea3554e7148186eb8fd9 Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Thu, 9 May 2024 14:30:33 +1000 Subject: [PATCH 12/22] Move failureDetailsURL to failureDetails.fileErrorURL --- src/graphqlTypes.d.ts | 4 ++-- src/lib/media-import/status.generated.d.ts | 2 +- src/lib/media-import/status.ts | 20 +++++++++++--------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/graphqlTypes.d.ts b/src/graphqlTypes.d.ts index 4efd8e84d..fa0efd905 100644 --- a/src/graphqlTypes.d.ts +++ b/src/graphqlTypes.d.ts @@ -783,8 +783,6 @@ export type AppEnvironmentMediaImportStatus = { __typename?: 'AppEnvironmentMediaImportStatus'; /** Media Import failure details */ failureDetails?: Maybe< AppEnvironmentMediaImportStatusFailureDetails >; - /** URL to download the media import error log */ - failureDetailsUrl?: Maybe< Scalars[ 'String' ][ 'output' ] >; /** Total number of media files that were imported */ filesProcessed?: Maybe< Scalars[ 'Int' ][ 'output' ] >; /** Total number of media files that are to be import */ @@ -815,6 +813,8 @@ export type AppEnvironmentMediaImportStatusFailureDetails = { __typename?: 'AppEnvironmentMediaImportStatusFailureDetails'; /** List of errors per file */ fileErrors?: Maybe< Array< Maybe< AppEnvironmentMediaImportStatusFailureDetailsFileErrors > > >; + /** URL to download the media import error log */ + fileErrorsUrl?: Maybe< Scalars[ 'String' ][ 'output' ] >; /** List of global errors per import */ globalErrors?: Maybe< Array< Maybe< Scalars[ 'String' ][ 'output' ] > > >; /** Status of the Media Import prior to failing */ diff --git a/src/lib/media-import/status.generated.d.ts b/src/lib/media-import/status.generated.d.ts index cd783adb7..883911bc2 100644 --- a/src/lib/media-import/status.generated.d.ts +++ b/src/lib/media-import/status.generated.d.ts @@ -22,11 +22,11 @@ export type AppQuery = { status?: string | null; filesTotal?: number | null; filesProcessed?: number | null; - failureDetailsUrl?: string | null; failureDetails?: { __typename?: 'AppEnvironmentMediaImportStatusFailureDetails'; previousStatus?: string | null; globalErrors?: Array< string | null > | null; + fileErrorsUrl?: string | null; fileErrors?: Array< { __typename?: 'AppEnvironmentMediaImportStatusFailureDetailsFileErrors'; fileName?: string | null; diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 0ff5a6256..28ace111a 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -39,7 +39,6 @@ const IMPORT_MEDIA_PROGRESS_QUERY = gql` status filesTotal filesProcessed - failureDetailsUrl failureDetails { previousStatus globalErrors @@ -47,6 +46,7 @@ const IMPORT_MEDIA_PROGRESS_QUERY = gql` fileName errors } + fileErrorsUrl } } } @@ -292,13 +292,13 @@ ${ maybeExitPrompt } } } - async function fetchFailureDetails( failureDetailsUrl: string ) { + async function fetchFailureDetails( fileErrorsUrl: string ) { progressTracker.suffix += ` ============================================================= -Downloading errors details from ${ failureDetailsUrl }... +Downloading errors details from ${ fileErrorsUrl }... \n`; try { - const response = await fetch( failureDetailsUrl ); + const response = await fetch( fileErrorsUrl ); return ( await response.json() ) as AppEnvironmentMediaImportStatusFailureDetailsFileErrors[]; } catch ( err ) { progressTracker.suffix += `${ chalk.red( @@ -308,10 +308,10 @@ Downloading errors details from ${ failureDetailsUrl }... } } - async function promptFailureDetailsDownload( failureDetailsUrl: string ) { + async function promptFailureDetailsDownload( fileErrorsUrl: string ) { progressTracker.suffix += `${ chalk.yellow( `⚠️ Error details can be found on ${ chalk.bold( - failureDetailsUrl + fileErrorsUrl ) }\n${ chalk.italic.yellow( '(This link will be valid for the next 15 minutes. The report is retained for 7 days from the completion of the import.)' ) }. ` @@ -328,7 +328,7 @@ Downloading errors details from ${ failureDetailsUrl }... return; } - const failureDetailsErrors = await fetchFailureDetails( failureDetailsUrl ); + const failureDetailsErrors = await fetchFailureDetails( fileErrorsUrl ); await exportFailureDetails( failureDetailsErrors ); } @@ -369,8 +369,10 @@ Downloading errors details from ${ failureDetailsUrl }... setProgressTrackerSuffix(); progressTracker.print(); - if ( results.failureDetailsUrl ) { - await promptFailureDetailsDownload( results.failureDetailsUrl as unknown as string ); + if ( results.failureDetails?.fileErrorsUrl ) { + await promptFailureDetailsDownload( + results.failureDetails.fileErrorsUrl as unknown as string + ); } else { const fileErrors = results.failureDetails?.fileErrors ?? []; From ee6c2fe84239f4984174be09e249cce6205ebe6d Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Thu, 9 May 2024 14:58:20 +1000 Subject: [PATCH 13/22] Prettier --- src/lib/media-import/status.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 28ace111a..c4c475bc2 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -310,9 +310,7 @@ Downloading errors details from ${ fileErrorsUrl }... async function promptFailureDetailsDownload( fileErrorsUrl: string ) { progressTracker.suffix += `${ chalk.yellow( - `⚠️ Error details can be found on ${ chalk.bold( - fileErrorsUrl - ) }\n${ chalk.italic.yellow( + `⚠️ Error details can be found on ${ chalk.bold( fileErrorsUrl ) }\n${ chalk.italic.yellow( '(This link will be valid for the next 15 minutes. The report is retained for 7 days from the completion of the import.)' ) }. ` ) }\n`; From cabbf65e90b53855c3f12c79755cd4dd3bb2e87e Mon Sep 17 00:00:00 2001 From: Sarosh Aga Date: Thu, 9 May 2024 17:13:22 +0400 Subject: [PATCH 14/22] Space out the s3 link to make it more distinct --- src/lib/media-import/status.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index c4c475bc2..56c5b2e93 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -309,13 +309,6 @@ Downloading errors details from ${ fileErrorsUrl }... } async function promptFailureDetailsDownload( fileErrorsUrl: string ) { - progressTracker.suffix += `${ chalk.yellow( - `⚠️ Error details can be found on ${ chalk.bold( fileErrorsUrl ) }\n${ chalk.italic.yellow( - '(This link will be valid for the next 15 minutes. The report is retained for 7 days from the completion of the import.)' - ) }. ` - ) }\n`; - progressTracker.print( { clearAfter: true } ); - const failureDetails = await prompt( { type: 'confirm', name: 'download', @@ -323,6 +316,14 @@ Downloading errors details from ${ fileErrorsUrl }... } ); if ( ! failureDetails.download ) { + progressTracker.suffix += `${ chalk.yellow( + `⚠️ Click on the following link to download the file import errors report` + ) }`; + progressTracker.suffix += `\n${ chalk.italic.yellow( + '(The link will be valid for the next 15 minutes & the data is retained for 7 days since the completion of the import)' + ) } `; + progressTracker.suffix += `\n\n${ chalk.bold.yellow( fileErrorsUrl ) }`; + progressTracker.print( { clearAfter: true } ); return; } @@ -381,6 +382,7 @@ Downloading errors details from ${ fileErrorsUrl }... } else { // Errors are not present in the dto // And file error details report link is not available + // do not print this message if the import was aborted printFileErrorsReportLinkExpiredError( results ); } } From 6f2c23ca253185ecc45d4cded2ce4731f34e6be8 Mon Sep 17 00:00:00 2001 From: Sarosh Aga Date: Thu, 9 May 2024 17:13:54 +0400 Subject: [PATCH 15/22] Do not print link expired message if status is ABORTED --- src/lib/media-import/status.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 56c5b2e93..62bb01141 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -379,7 +379,7 @@ Downloading errors details from ${ fileErrorsUrl }... // Errors were observed and are present in the dto // Fall back to exporting errors to local file await printFailureDetails( fileErrors, results ); - } else { + } else if ( 'ABORTED' !== overallStatus ) { // Errors are not present in the dto // And file error details report link is not available // do not print this message if the import was aborted From 357a4ac07f6b1c7b7762b38140cbf52c4205088f Mon Sep 17 00:00:00 2001 From: Sarosh Aga Date: Thu, 9 May 2024 17:49:33 +0400 Subject: [PATCH 16/22] Bump dev version --- npm-shrinkwrap.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 69a1b1cc6..5a31bf0c4 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "@automattic/vip", - "version": "2.39.7-dev.0", + "version": "2.40.0-dev.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@automattic/vip", - "version": "2.39.7-dev.0", + "version": "2.40.0-dev.0", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 8cd0410da..d0865ef6f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@automattic/vip", - "version": "2.39.7-dev.0", + "version": "2.40.0-dev.0", "description": "The VIP Javascript library & CLI", "main": "index.js", "bin": { From c261f1f2971e3be97c3ee8f09372fffccb8650e7 Mon Sep 17 00:00:00 2001 From: Sarosh Aga Date: Thu, 9 May 2024 18:43:07 +0400 Subject: [PATCH 17/22] Bump version to 2.40.0-dev.1 --- npm-shrinkwrap.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 5a31bf0c4..bb4b3dc5c 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "@automattic/vip", - "version": "2.40.0-dev.0", + "version": "2.40.0-dev.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@automattic/vip", - "version": "2.40.0-dev.0", + "version": "2.40.0-dev.1", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index d0865ef6f..19670fbc3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@automattic/vip", - "version": "2.40.0-dev.0", + "version": "2.40.0-dev.1", "description": "The VIP Javascript library & CLI", "main": "index.js", "bin": { From 468ed2648d0d237b6228a4d7bb97a8b920665b1e Mon Sep 17 00:00:00 2001 From: Todd Wright <4177859+t-wright@users.noreply.github.com> Date: Fri, 10 May 2024 21:03:29 +1000 Subject: [PATCH 18/22] Add new lines after error file URLs (#1830) * Add new lines after error file URLs * Add note about 7 day downloadability to prompt --------- Co-authored-by: Sarosh Aga --- src/lib/media-import/status.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 62bb01141..1d68d5ec9 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -283,7 +283,7 @@ ${ maybeExitPrompt } try { await writeFile( errorsFile, formattedData ); progressTracker.suffix += `${ chalk.yellow( - `⚠️ All errors have been exported to ${ chalk.bold( resolve( errorsFile ) ) }` + `⚠️ All errors have been exported to ${ chalk.bold( resolve( errorsFile ) ) }\n` ) }`; } catch ( writeFileErr ) { progressTracker.suffix += `${ chalk.red( @@ -312,7 +312,8 @@ Downloading errors details from ${ fileErrorsUrl }... const failureDetails = await prompt( { type: 'confirm', name: 'download', - message: 'Download file import errors report now?', + message: + 'Download file import errors report now? (Report will be downloadable for up to 7 days from the completion of the import)', } ); if ( ! failureDetails.download ) { @@ -320,9 +321,9 @@ Downloading errors details from ${ fileErrorsUrl }... `⚠️ Click on the following link to download the file import errors report` ) }`; progressTracker.suffix += `\n${ chalk.italic.yellow( - '(The link will be valid for the next 15 minutes & the data is retained for 7 days since the completion of the import)' + '(The link will be valid for the next 15 minutes & the report will be downloadable for up to 7 days from the completion of the import)' ) } `; - progressTracker.suffix += `\n\n${ chalk.bold.yellow( fileErrorsUrl ) }`; + progressTracker.suffix += `\n\n${ chalk.bold.yellow( fileErrorsUrl ) }\n`; progressTracker.print( { clearAfter: true } ); return; } From f991e49310967f54c8e57f5cb7ce34d131e27407 Mon Sep 17 00:00:00 2001 From: Sarosh Aga Date: Tue, 14 May 2024 13:58:00 +0400 Subject: [PATCH 19/22] Bump version to 2.40.0-dev.2 --- npm-shrinkwrap.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index bb4b3dc5c..34b9dc9cd 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "@automattic/vip", - "version": "2.40.0-dev.1", + "version": "2.40.0-dev.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@automattic/vip", - "version": "2.40.0-dev.1", + "version": "2.40.0-dev.2", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 19670fbc3..82ea5457d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@automattic/vip", - "version": "2.40.0-dev.1", + "version": "2.40.0-dev.2", "description": "The VIP Javascript library & CLI", "main": "index.js", "bin": { From e78ca9592e947ece82332bbb914c39d4e5affd26 Mon Sep 17 00:00:00 2001 From: Ariana Kataoka Date: Wed, 22 May 2024 16:22:25 +1000 Subject: [PATCH 20/22] Update src/lib/media-import/status.ts Co-authored-by: Todd Wright <4177859+t-wright@users.noreply.github.com> --- src/lib/media-import/status.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 1d68d5ec9..36a7aad5e 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -295,7 +295,7 @@ ${ maybeExitPrompt } async function fetchFailureDetails( fileErrorsUrl: string ) { progressTracker.suffix += ` ============================================================= -Downloading errors details from ${ fileErrorsUrl }... +Downloading errors details from ${ fileErrorsUrl } ... \n`; try { const response = await fetch( fileErrorsUrl ); From 97ded11194f74d244d7aac4393e37cbc65c7c709 Mon Sep 17 00:00:00 2001 From: Sarosh Aga Date: Wed, 22 May 2024 12:20:58 +0530 Subject: [PATCH 21/22] Expand on media import error report messaging (#1839) * Address error messaging feedback * Remove ellipses with conflicts with URL * Revert v1 flow error messages * Call progress tracker print to show downloading message --- src/lib/media-import/status.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/lib/media-import/status.ts b/src/lib/media-import/status.ts index 36a7aad5e..5b7e68789 100644 --- a/src/lib/media-import/status.ts +++ b/src/lib/media-import/status.ts @@ -295,14 +295,15 @@ ${ maybeExitPrompt } async function fetchFailureDetails( fileErrorsUrl: string ) { progressTracker.suffix += ` ============================================================= -Downloading errors details from ${ fileErrorsUrl } ... +Downloading errors details from ${ fileErrorsUrl } \n`; + progressTracker.print( { clearAfter: true } ); try { const response = await fetch( fileErrorsUrl ); return ( await response.json() ) as AppEnvironmentMediaImportStatusFailureDetailsFileErrors[]; } catch ( err ) { progressTracker.suffix += `${ chalk.red( - `Could not download file import errors report\n${ ( err as Error ).message }` + `Could not download import errors report\n${ ( err as Error ).message }` ) }`; throw err; } @@ -313,17 +314,22 @@ Downloading errors details from ${ fileErrorsUrl } ... type: 'confirm', name: 'download', message: - 'Download file import errors report now? (Report will be downloadable for up to 7 days from the completion of the import)', + 'Download import errors report now? (Report will be downloadable for up to 7 days from the completion of the import)', } ); if ( ! failureDetails.download ) { progressTracker.suffix += `${ chalk.yellow( - `⚠️ Click on the following link to download the file import errors report` + `⚠️ An error report file has been generated for this media import. Access it within the next 15 minutes by clicking on the URL below.` ) }`; - progressTracker.suffix += `\n${ chalk.italic.yellow( - '(The link will be valid for the next 15 minutes & the report will be downloadable for up to 7 days from the completion of the import)' + progressTracker.suffix += `\n${ chalk.yellow( + `Or, generate a new URL by running the ${ chalk.bgYellow( + 'vip import media status' + ) } command.` ) } `; - progressTracker.suffix += `\n\n${ chalk.bold.yellow( fileErrorsUrl ) }\n`; + progressTracker.suffix += `\n${ chalk.yellow( + 'The report will be downloadable for up to 7 days after the completion of the import or until a new media import is performed.' + ) }`; + progressTracker.suffix += `\n\n${ chalk.underline( fileErrorsUrl ) }\n`; progressTracker.print( { clearAfter: true } ); return; } From a3ab1cb84a0de84289869274b4ec2c8785ebe2ab Mon Sep 17 00:00:00 2001 From: Sarosh Aga Date: Thu, 23 May 2024 17:25:26 +0400 Subject: [PATCH 22/22] Bump dev version to 2.40.0-dev.3 --- npm-shrinkwrap.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 34b9dc9cd..710cea2a6 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "@automattic/vip", - "version": "2.40.0-dev.2", + "version": "2.40.0-dev.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@automattic/vip", - "version": "2.40.0-dev.2", + "version": "2.40.0-dev.3", "hasInstallScript": true, "license": "MIT", "dependencies": { diff --git a/package.json b/package.json index 82ea5457d..b89da3bf4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@automattic/vip", - "version": "2.40.0-dev.2", + "version": "2.40.0-dev.3", "description": "The VIP Javascript library & CLI", "main": "index.js", "bin": {