salesforce-alm
Version:
This package contains tools, and APIs, for an improved salesforce.com developer experience.
61 lines (59 loc) • 2.76 kB
JavaScript
;
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrgShapeCreateCommand = void 0;
// This is the legacy converted command file. Ignoring code-coverage since this is generated.
// THIS SHOULD BE REMOVED WHEN CONVERTED TO EXTEND SfdxCommand
/* istanbul ignore file */
const os_1 = require("os");
const command_1 = require("@salesforce/command");
const core_1 = require("@salesforce/core");
const shapeRepApi_1 = require("../../../../lib/org/shapeRepApi");
core_1.Messages.importMessagesDirectory(__dirname);
const messages = core_1.Messages.loadMessages('salesforce-alm', 'org_shape');
const commandTimeOutInMS = 30e3;
class OrgShapeCreateCommand extends command_1.SfdxCommand {
async run() {
const api = new shapeRepApi_1.ShapeRepresentationApi(this.org);
if (!(await api.isFeatureEnabled())) {
throw new core_1.SfdxError(messages.getMessage('create_shape_command_no_access', [this.org.getUsername()]), 'noAccess');
}
let timeoutID;
const timeout = new Promise((_, reject) => {
timeoutID = setTimeout(() => {
reject(messages.getMessage('shapeCreateFailedMessage'));
}, commandTimeOutInMS);
});
const createShapeResponse = (await Promise.race([api.create(), timeout]));
clearTimeout(timeoutID);
if (createShapeResponse['success'] !== true) {
this.logger.error('Shape create failed', createShapeResponse['errors']);
throw Promise.reject(new core_1.SfdxError(messages.getMessage('shape_create_failed_message')));
}
const output = {
shapeId: createShapeResponse.id,
shapeFile: undefined,
success: true,
errors: [],
};
// this doesn't seem to be used anymore;
if (typeof output.shapeFile != 'undefined' && output.shapeFile) {
this.ux.log(messages.getMessage('create_shape_command_success_file', [output.shapeFile]));
}
else {
this.ux.log(messages.getMessage('create_shape_command_success_id', [output.shapeId]));
}
return output;
}
}
exports.OrgShapeCreateCommand = OrgShapeCreateCommand;
OrgShapeCreateCommand.description = messages.getMessage('create_shape_command_description');
OrgShapeCreateCommand.examples = messages.getMessage('create_shape_command_help').split(os_1.EOL);
OrgShapeCreateCommand.requiresUsername = true;
OrgShapeCreateCommand.varargs = true;
//# sourceMappingURL=create.js.map