Skip to content

Commit

Permalink
Merge branch 'master' into profile-empty
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienTaillon authored Mar 25, 2024
2 parents 14c99c0 + 4135755 commit 6fff732
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
6 changes: 5 additions & 1 deletion messages/package.dependencies.install.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ comma-separated list of the packages to install related dependencies

# flags.securitytype.summary

security access type for the installed package (see force:package:install for default value)
security access type for the installed package (see sf packageinstall for default value)

# flags.namespaces.summary

Expand All @@ -33,3 +33,7 @@ allow Remote Site Settings and Content Security Policy websites to send or recei
# flags.apexcompile.summary

compile all Apex in the org and package, or only Apex in the package (see force:package:install for default value)

# flags.upgrade-type.summary

upgrade type for the package installation; available only for unlocked packages (see sf packageinstall for default value)
24 changes: 18 additions & 6 deletions src/commands/texei/cpqsettings/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
requiredOrgFlagWithDeprecations,
loglevel,
} from '@salesforce/sf-plugins-core';
import { Messages, SfError } from '@salesforce/core';
import { Connection, Messages, Org, SfError } from '@salesforce/core';
import * as puppeteer from 'puppeteer';
import { ElementHandle } from 'puppeteer';

Expand All @@ -42,9 +42,15 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
loglevel,
};

private org!: Org;
private conn!: Connection;

public async run(): Promise<CpqSettingsSetResult> {
const { flags } = await this.parse(Set);

this.org = flags['target-org'];
this.conn = this.org.getConnection(flags['api-version']);

this.log(
'[Warning] This command is based on HTML parsing because of a lack of supported APIs, but may break at anytime. Use at your own risk.'
);
Expand All @@ -56,7 +62,8 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
const cpqSettings = JSON.parse((await fs.readFile(filePath)).toString());

// Get Org URL
const instanceUrl = flags['target-org'].getConnection(flags['api-version']).instanceUrl;
const instanceUrl = this.conn.instanceUrl;
const frontdoorUrl = await this.getFrontdoorURL();
const cpqSettingsUrl = await this.getSettingURL(instanceUrl);

// Init browser
Expand All @@ -67,10 +74,7 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
const page = await browser.newPage();

this.log(`Logging in to instance ${instanceUrl}`);
await page.goto(
`${instanceUrl}/secur/frontdoor.jsp?sid=${flags['target-org'].getConnection(flags['api-version']).accessToken}`,
{ waitUntil: ['domcontentloaded', 'networkidle0'] }
);
await page.goto(frontdoorUrl, { waitUntil: ['domcontentloaded', 'networkidle0'] });
const navigationPromise = page.waitForNavigation();

this.log(`Navigating to CPQ Settings Page ${cpqSettingsUrl}`);
Expand Down Expand Up @@ -208,6 +212,14 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
return result;
}

private async getFrontdoorURL(): Promise<string> {
await this.org.refreshAuth(); // we need a live accessToken for the frontdoor url
const accessToken = this.conn.accessToken;
const instanceUrl = this.conn.instanceUrl;
const instanceUrlClean = instanceUrl.replace(/\/$/, '');
return `${instanceUrlClean}/secur/frontdoor.jsp?sid=${accessToken}`;
}

// eslint-disable-next-line class-methods-use-this
private async getSettingURL(urlOfInstance: string) {
return `${urlOfInstance.substring(0, urlOfInstance.indexOf('.'))}--sbqq.visualforce.com/apex/EditSettings`;
Expand Down
11 changes: 11 additions & 0 deletions src/commands/texei/package/dependencies/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export default class Install extends SfCommand<PackageDependenciesInstallResult>
summary: messages.getMessage('flags.apexcompile.summary'),
required: false,
}),
'upgrade-type': Flags.string({
char: 't',
summary: messages.getMessage('flags.upgrade-type.summary'),
required: false,
}),
// loglevel is a no-op, but this flag is added to avoid breaking scripts and warn users who are using it
loglevel,
};
Expand Down Expand Up @@ -261,6 +266,12 @@ export default class Install extends SfCommand<PackageDependenciesInstallResult>
args.push(`${flags.apexcompile}`);
}

// UPGRADE TYPE
if (flags['upgrade-type']) {
args.push('--upgrade-type');
args.push(`${flags['upgrade-type']}`);
}

// WAIT
const wait = flags.wait != null ? flags.wait : defaultWait;
args.push('--wait');
Expand Down

0 comments on commit 6fff732

Please sign in to comment.