@salesforce/plugin-packaging
Version:
SF plugin that support Salesforce Packaging Platform
71 lines • 3.23 kB
JavaScript
/*
* Copyright 2025, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, requiredOrgFlagWithDeprecations, SfCommand, } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { SubscriberPackageVersion } from '@salesforce/packaging';
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_install_report');
const installMsgs = Messages.loadMessages('@salesforce/plugin-packaging', 'package_install');
export class Report extends SfCommand {
static summary = messages.getMessage('summary');
static examples = messages.getMessages('examples');
static deprecateAliases = true;
static aliases = ['force:package:install:report'];
static org;
static flags = {
'target-org': requiredOrgFlagWithDeprecations,
'api-version': orgApiVersionFlagWithDeprecations,
loglevel,
'request-id': Flags.salesforceId({
startsWith: '0Hf',
length: 'both',
char: 'i',
deprecateAliases: true,
aliases: ['requestid'],
summary: messages.getMessage('flags.request-id.summary'),
required: true,
}),
};
static parseStatus(binName, request, username, alias) {
const pkgIdOrAlias = alias ?? request.SubscriberPackageVersionKey;
const { Status } = request;
if (Status === 'SUCCESS') {
return installMsgs.getMessage('package-install-success', [pkgIdOrAlias]);
}
else if (['IN_PROGRESS', 'UNKNOWN'].includes(Status)) {
return installMsgs.getMessage('packageInstallInProgress', [binName, request.Id, username]);
}
else {
let errorMessage = '<empty>';
const errors = request?.Errors?.errors;
if (errors?.length) {
errorMessage = 'Installation errors: ';
for (let i = 0; i < errors.length; i++) {
errorMessage += `\n${i + 1}) ${errors[i].message}`;
}
}
throw installMsgs.createError('packageInstallError', [errorMessage]);
}
}
async run() {
const { flags } = await this.parse(Report);
const connection = flags['target-org'].getConnection(flags['api-version']);
const pkgInstallRequest = await SubscriberPackageVersion.getInstallRequest(flags['request-id'], connection);
this.log(Report.parseStatus(this.config.bin, pkgInstallRequest, flags['target-org'].getUsername()));
return pkgInstallRequest;
}
}
//# sourceMappingURL=report.js.map