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" , "sharedactivities-enable" ) ; export default class Enable extends SfdxCommand { public static description = messages . getMessage ( "commandDescription" ) ; public static examples = [ `$ sfdx texei:sharedactivities:enable` ] ; protected static flagsConfig = { } ; protected static requiresUsername = true ; protected static requiresDevhubUsername = false ; protected static requiresProject = false ; public async run ( ) { let result = { } ; this . ux . warn ( 'SharedActivities are now officially supported, you should add the SharedActivities feature to your scratch definition file instead of using this command.' ) ; await this . enableSharedActivities ( ) ; return result ; } private async enableSharedActivities ( ) { const instanceUrl = this . org . getConnection ( ) . instanceUrl ; const ACTIVITIES_SETTINGS_PATH = "/setup/activitiesSetupPage.apexp" ; this . ux . startSpinner ( `Enabling Shared Activities` , null , { stdout : true } ) ; this . debug ( `DEBUG Login to 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 }` , { waitUntil : [ "domcontentloaded" , "networkidle0" ] } ) ; const navigationPromise = page . waitForNavigation ( ) ; this . debug ( `DEBUG Opening Activity Settings page` ) ; await page . goto ( `${ instanceUrl + ACTIVITIES_SETTINGS_PATH }` ) ; await navigationPromise ; this . debug ( `DEBUG Clicking 'Allow Users to Relate Multiple Contacts to Tasks and Events' checkbox` ) ; await page . click ( 'input[id="thePage:theForm:theBlock:manyWhoPref"]' ) ; this . debug ( `DEBUG Clicking 'Submit' button` ) ; await page . click ( 'input[id="thePage:theForm:theBlock:buttons:submit"]' ) ; await navigationPromise ; this . debug ( `DEBUG Closing browser` ) ; await browser . close ( ) ; this . ux . stopSpinner ( "Done." ) ; return { message : `Enabled Shared Activities` } ; } }