import { SfdxCommand } from "@salesforce/command" ; import { Messages } from '@salesforce/core' ; import * as puppeteer from "puppeteer" ; Messages . importMessagesDirectory ( __dirname ) ; const messages = Messages . loadMessages ( "texei-sfdx-plugin" , "org-contractfieldhistory-fix" ) ; export default class Fix extends SfdxCommand { public static description = messages . getMessage ( "commandDescription" ) ; public static examples = [ `$ sfdx texei:org:contractfieldhistory:fix" \nHistory tracking fixed.\n` ] ; protected static flagsConfig = { } ; protected static requiresUsername = true ; protected static requiresDevhubUsername = false ; protected static requiresProject = false ; public async run ( ) { let result = { } ; await this . fixContract ( ) ; return result ; } private async fixContract ( ) { const instanceUrl = this . org . getConnection ( ) . instanceUrl ; const POST_LOGIN_PATH = "/ui/setup/layout/FieldHistoryTracking?pEntity=Contract" ; this . ux . startSpinner ( 'Fixing Contract Field History' , null , { stdout : true } ) ; this . debug ( `DEBUG Login to Scratch Org` ) ; const browser = await puppeteer . launch ( { args : [ '--no-sandbox' , '--disable-setuid-sandbox' ] , headless : ! ( process . env . BROWSER_DEBUG === 'true' ) } ) ; const page = await browser . newPage ( ) ; await page . goto ( `${ instanceUrl }/secur/frontdoor.jsp?sid=${ this . org . getConnection ( ) . accessToken }&startURL=${ encodeURIComponent ( POST_LOGIN_PATH ) }` , { waitUntil : [ "domcontentloaded" , "networkidle0" ] } ) ; const navigationPromise = page . waitForNavigation ( ) ; this . debug ( `DEBUG Opening Contract Field History Tracking page` ) ; await page . goto ( `${ instanceUrl }/ui/setup/layout/FieldHistoryTracking?pEntity=Contract` ) ; await navigationPromise ; this . debug ( `DEBUG Clicking 'Save' button` ) ; await page . click ( "table > tbody > tr > #topButtonRow > .btn:nth-child(1)" ) ; await navigationPromise ; this . debug ( `DEBUG Closing browser` ) ; await browser . close ( ) ; this . ux . stopSpinner ( 'Done.' ) ; return { message : 'Fixed Contract Fied History Tracking' } ; } }