@pnp/cli-microsoft365 10.6.0-beta.3facb8f → 10.6.0-beta.7205e34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,13 +4,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _PpCardGetCommand_instances, _PpCardGetCommand_initTelemetry, _PpCardGetCommand_initOptions, _PpCardGetCommand_initOptionSets, _PpCardGetCommand_initValidators;
7
- import { cli } from '../../../../cli/cli.js';
8
7
  import request from '../../../../request.js';
9
8
  import { powerPlatform } from '../../../../utils/powerPlatform.js';
10
9
  import { validation } from '../../../../utils/validation.js';
11
10
  import PowerPlatformCommand from '../../../base/PowerPlatformCommand.js';
12
11
  import commands from '../../commands.js';
13
- import { formatting } from '../../../../utils/formatting.js';
14
12
  class PpCardGetCommand extends PowerPlatformCommand {
15
13
  get name() {
16
14
  return commands.CARD_GET;
@@ -32,35 +30,28 @@ class PpCardGetCommand extends PowerPlatformCommand {
32
30
  }
33
31
  try {
34
32
  const dynamicsApiUrl = await powerPlatform.getDynamicsInstanceApiUrl(args.options.environmentName, args.options.asAdmin);
35
- const res = await this.getCard(dynamicsApiUrl, args.options);
33
+ const res = await this.getCard(dynamicsApiUrl, args.options, logger);
36
34
  await logger.log(res);
37
35
  }
38
36
  catch (err) {
39
37
  this.handleRejectedODataJsonPromise(err);
40
38
  }
41
39
  }
42
- async getCard(dynamicsApiUrl, options) {
40
+ async getCard(dynamicsApiUrl, options, logger) {
41
+ if (options.name) {
42
+ return await powerPlatform.getCardByName(dynamicsApiUrl, options.name, logger, this.verbose);
43
+ }
44
+ if (this.verbose) {
45
+ await logger.logToStderr(`Retrieving the card with id ${options.id}`);
46
+ }
43
47
  const requestOptions = {
48
+ url: `${dynamicsApiUrl}/api/data/v9.1/cards(${options.id})`,
44
49
  headers: {
45
50
  accept: 'application/json;odata.metadata=none'
46
51
  },
47
52
  responseType: 'json'
48
53
  };
49
- if (options.id) {
50
- requestOptions.url = `${dynamicsApiUrl}/api/data/v9.1/cards(${options.id})`;
51
- const result = await request.get(requestOptions);
52
- return result;
53
- }
54
- requestOptions.url = `${dynamicsApiUrl}/api/data/v9.1/cards?$filter=name eq '${options.name}'`;
55
- const result = await request.get(requestOptions);
56
- if (result.value.length === 0) {
57
- throw `The specified card '${options.name}' does not exist.`;
58
- }
59
- if (result.value.length > 1) {
60
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('cardid', result.value);
61
- return cli.handleMultipleResultsFound(`Multiple cards with name '${options.name}' found`, resultAsKeyValuePair);
62
- }
63
- return result.value[0];
54
+ return await request.get(requestOptions);
64
55
  }
65
56
  }
66
57
  _PpCardGetCommand_instances = new WeakSet(), _PpCardGetCommand_initTelemetry = function _PpCardGetCommand_initTelemetry() {
@@ -10,7 +10,6 @@ import { powerPlatform } from '../../../../utils/powerPlatform.js';
10
10
  import { validation } from '../../../../utils/validation.js';
11
11
  import PowerPlatformCommand from '../../../base/PowerPlatformCommand.js';
12
12
  import commands from '../../commands.js';
13
- import ppCardGetCommand from './card-get.js';
14
13
  class PpCardRemoveCommand extends PowerPlatformCommand {
15
14
  get name() {
16
15
  return commands.CARD_REMOVE;
@@ -31,34 +30,26 @@ class PpCardRemoveCommand extends PowerPlatformCommand {
31
30
  await logger.logToStderr(`Removing card '${args.options.id || args.options.name}'...`);
32
31
  }
33
32
  if (args.options.force) {
34
- await this.deleteCard(args);
33
+ await this.deleteCard(args, logger);
35
34
  }
36
35
  else {
37
36
  const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove card '${args.options.id || args.options.name}'?` });
38
37
  if (result) {
39
- await this.deleteCard(args);
38
+ await this.deleteCard(args, logger);
40
39
  }
41
40
  }
42
41
  }
43
- async getCardId(args) {
42
+ async getCardId(args, dynamicsApiUrl, logger) {
44
43
  if (args.options.id) {
45
44
  return args.options.id;
46
45
  }
47
- const options = {
48
- environmentName: args.options.environmentName,
49
- name: args.options.name,
50
- output: 'json',
51
- debug: this.debug,
52
- verbose: this.verbose
53
- };
54
- const output = await cli.executeCommandWithOutput(ppCardGetCommand, { options: { ...options, _: [] } });
55
- const getCardOutput = JSON.parse(output.stdout);
56
- return getCardOutput.cardid;
46
+ const card = await powerPlatform.getCardByName(dynamicsApiUrl, args.options.name, logger, this.verbose);
47
+ return card.cardid;
57
48
  }
58
- async deleteCard(args) {
49
+ async deleteCard(args, logger) {
59
50
  try {
60
51
  const dynamicsApiUrl = await powerPlatform.getDynamicsInstanceApiUrl(args.options.environmentName, args.options.asAdmin);
61
- const cardId = await this.getCardId(args);
52
+ const cardId = await this.getCardId(args, dynamicsApiUrl, logger);
62
53
  const requestOptions = {
63
54
  url: `${dynamicsApiUrl}/api/data/v9.1/cards(${cardId})`,
64
55
  headers: {
@@ -51,7 +51,7 @@ export const powerPlatform = {
51
51
  }
52
52
  if (items.length > 1) {
53
53
  const resultAsKeyValuePair = formatting.convertArrayToHashTable('websiteUrl', items);
54
- return cli.handleMultipleResultsFound(`Multiple Power Page websites with name '${websiteName}' found`, resultAsKeyValuePair);
54
+ return cli.handleMultipleResultsFound(`Multiple Power Page websites with name '${websiteName}' found.`, resultAsKeyValuePair);
55
55
  }
56
56
  return items[0];
57
57
  },
@@ -62,6 +62,35 @@ export const powerPlatform = {
62
62
  throw Error(`The specified Power Page website with url '${url}' does not exist.`);
63
63
  }
64
64
  return items[0];
65
+ },
66
+ /**
67
+ * Get a card by name
68
+ * Returns a card object
69
+ * @param dynamicsApiUrl The dynamics api url of the environment
70
+ * @param name The name of the card
71
+ * @param logger The logger object
72
+ * @param verbose Set for verbose logging
73
+ */
74
+ async getCardByName(dynamicsApiUrl, name, logger, verbose) {
75
+ if (verbose && logger) {
76
+ await logger.logToStderr(`Retrieving the card with name ${name}`);
77
+ }
78
+ const requestOptions = {
79
+ url: `${dynamicsApiUrl}/api/data/v9.1/cards?$filter=name eq '${name}'`,
80
+ headers: {
81
+ accept: 'application/json;odata.metadata=none'
82
+ },
83
+ responseType: 'json'
84
+ };
85
+ const result = await request.get(requestOptions);
86
+ if (result.value.length === 0) {
87
+ throw Error(`The specified card '${name}' does not exist.`);
88
+ }
89
+ if (result.value.length > 1) {
90
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('cardid', result.value);
91
+ return cli.handleMultipleResultsFound(`Multiple cards with name '${name}' found.`, resultAsKeyValuePair);
92
+ }
93
+ return result.value[0];
65
94
  }
66
95
  };
67
96
  //# sourceMappingURL=powerPlatform.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "10.6.0-beta.3facb8f",
3
+ "version": "10.6.0-beta.7205e34",
4
4
  "description": "Manage Microsoft 365 and SharePoint Framework projects on any platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/api.js",