UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

105 lines 4.8 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _PpCardCloneCommand_instances, _PpCardCloneCommand_initTelemetry, _PpCardCloneCommand_initOptions, _PpCardCloneCommand_initOptionSets, _PpCardCloneCommand_initValidators; import { cli } from '../../../../cli/cli.js'; import request from '../../../../request.js'; import { powerPlatform } from '../../../../utils/powerPlatform.js'; import { validation } from '../../../../utils/validation.js'; import PowerPlatformCommand from '../../../base/PowerPlatformCommand.js'; import commands from '../../commands.js'; import ppCardGetCommand from './card-get.js'; class PpCardCloneCommand extends PowerPlatformCommand { get name() { return commands.CARD_CLONE; } get description() { return 'Clones a specific Microsoft Power Platform card in the specified Power Platform environment.'; } constructor() { super(); _PpCardCloneCommand_instances.add(this); __classPrivateFieldGet(this, _PpCardCloneCommand_instances, "m", _PpCardCloneCommand_initTelemetry).call(this); __classPrivateFieldGet(this, _PpCardCloneCommand_instances, "m", _PpCardCloneCommand_initOptions).call(this); __classPrivateFieldGet(this, _PpCardCloneCommand_instances, "m", _PpCardCloneCommand_initValidators).call(this); __classPrivateFieldGet(this, _PpCardCloneCommand_instances, "m", _PpCardCloneCommand_initOptionSets).call(this); } async commandAction(logger, args) { if (this.verbose) { await logger.logToStderr(`Cloning a card from '${args.options.id || args.options.name}'...`); } const res = await this.cloneCard(args); await logger.log(res); } async getCardId(args) { if (args.options.id) { return args.options.id; } const options = { environmentName: args.options.environmentName, name: args.options.name, output: 'json', debug: this.debug, verbose: this.verbose }; const output = await cli.executeCommandWithOutput(ppCardGetCommand, { options: { ...options, _: [] } }); const getCardOutput = JSON.parse(output.stdout); return getCardOutput.cardid; } async cloneCard(args) { try { const dynamicsApiUrl = await powerPlatform.getDynamicsInstanceApiUrl(args.options.environmentName, args.options.asAdmin); const cardId = await this.getCardId(args); const requestOptions = { url: `${dynamicsApiUrl}/api/data/v9.1/CardCreateClone`, headers: { accept: 'application/json;odata.metadata=none' }, responseType: 'json', data: { CardId: cardId, CardName: args.options.newName } }; const response = await request.post(requestOptions); return response; } catch (err) { this.handleRejectedODataJsonPromise(err); } } } _PpCardCloneCommand_instances = new WeakSet(), _PpCardCloneCommand_initTelemetry = function _PpCardCloneCommand_initTelemetry() { this.telemetry.push((args) => { Object.assign(this.telemetryProperties, { id: typeof args.options.id !== 'undefined', name: typeof args.options.name !== 'undefined', asAdmin: !!args.options.asAdmin }); }); }, _PpCardCloneCommand_initOptions = function _PpCardCloneCommand_initOptions() { this.options.unshift({ option: '-e, --environmentName <environmentName>' }, { option: '--newName <newName>' }, { option: '-i, --id [id]' }, { option: '-n, --name [name]' }, { option: '--asAdmin' }); }, _PpCardCloneCommand_initOptionSets = function _PpCardCloneCommand_initOptionSets() { this.optionSets.push({ options: ['id', 'name'] }); }, _PpCardCloneCommand_initValidators = function _PpCardCloneCommand_initValidators() { this.validators.push(async (args) => { if (args.options.id && !validation.isValidGuid(args.options.id)) { return `${args.options.id} is not a valid GUID`; } return true; }); }; export default new PpCardCloneCommand(); //# sourceMappingURL=card-clone.js.map