@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.
@@ -1,7 +1,6 @@
1
- import { cli } from '../../../cli/cli.js';
2
- import entraAppGetCommand from '../../entra/commands/app/app-get.js';
3
1
  import AppCommand from '../../base/AppCommand.js';
4
2
  import commands from '../commands.js';
3
+ import { entraApp } from '../../../utils/entraApp.js';
5
4
  class AppGetCommand extends AppCommand {
6
5
  get name() {
7
6
  return commands.GET;
@@ -10,18 +9,9 @@ class AppGetCommand extends AppCommand {
10
9
  return 'Retrieves information about the current Microsoft Entra app';
11
10
  }
12
11
  async commandAction(logger, args) {
13
- const options = {
14
- appId: this.appId,
15
- output: 'json',
16
- debug: args.options.debug,
17
- verbose: args.options.verbose
18
- };
19
12
  try {
20
- const appGetOutput = await cli.executeCommandWithOutput(entraAppGetCommand, { options: { ...options, _: [] } });
21
- if (this.verbose) {
22
- await logger.logToStderr(appGetOutput.stderr);
23
- }
24
- await logger.log(JSON.parse(appGetOutput.stdout));
13
+ const app = await entraApp.getAppRegistrationByAppId(args.options.appId);
14
+ await logger.log(app);
25
15
  }
26
16
  catch (err) {
27
17
  this.handleRejectedODataJsonPromise(err);
@@ -1,8 +1,7 @@
1
- import { cli } from '../../../../cli/cli.js';
2
1
  import request from '../../../../request.js';
3
- import appGetCommand from '../../../entra/commands/app/app-get.js';
4
2
  import AppCommand from '../../../base/AppCommand.js';
5
3
  import commands from '../../commands.js';
4
+ import { entraApp } from '../../../../utils/entraApp.js';
6
5
  var GetServicePrincipal;
7
6
  (function (GetServicePrincipal) {
8
7
  GetServicePrincipal[GetServicePrincipal["withPermissions"] = 0] = "withPermissions";
@@ -178,19 +177,10 @@ class AppPermissionListCommand extends AppCommand {
178
177
  }
179
178
  async getAppRegistration(appId, logger) {
180
179
  if (this.verbose) {
181
- await logger.logToStderr(`Retrieving Microsoft Entra application registration ${appId}`);
180
+ await logger.logToStderr(`Retrieving the Entra application registration with appId '${appId}'`);
182
181
  }
183
- const options = {
184
- appId: appId,
185
- output: 'json',
186
- debug: this.debug,
187
- verbose: this.verbose
188
- };
189
- const output = await cli.executeCommandWithOutput(appGetCommand, { options: { ...options, _: [] } });
190
- if (this.debug) {
191
- await logger.logToStderr(output.stderr);
192
- }
193
- return JSON.parse(output.stdout);
182
+ const app = await entraApp.getAppRegistrationByAppId(appId);
183
+ return app;
194
184
  }
195
185
  async getAppRegPermissions(appId, logger) {
196
186
  const application = await this.getAppRegistration(appId, logger);
@@ -11,6 +11,7 @@ import { validation } from '../../../../utils/validation.js';
11
11
  import GraphCommand from '../../../base/GraphCommand.js';
12
12
  import commands from '../../commands.js';
13
13
  import { cli } from '../../../../cli/cli.js';
14
+ import { entraApp } from '../../../../utils/entraApp.js';
14
15
  class EntraAppGetCommand extends GraphCommand {
15
16
  get name() {
16
17
  return commands.APP_GET;
@@ -28,7 +29,7 @@ class EntraAppGetCommand extends GraphCommand {
28
29
  }
29
30
  async commandAction(logger, args) {
30
31
  try {
31
- const appObjectId = await this.getAppObjectId(args);
32
+ const appObjectId = await this.getAppObjectId(args, logger);
32
33
  const appInfo = await this.getAppInfo(appObjectId, args.options.properties);
33
34
  const res = await this.saveAppInfo(args, appInfo, logger);
34
35
  await logger.log(res);
@@ -37,32 +38,37 @@ class EntraAppGetCommand extends GraphCommand {
37
38
  this.handleRejectedODataJsonPromise(err);
38
39
  }
39
40
  }
40
- async getAppObjectId(args) {
41
+ async getAppObjectId(args, logger) {
41
42
  if (args.options.objectId) {
42
43
  return args.options.objectId;
43
44
  }
44
45
  const { appId, name } = args.options;
45
- const filter = appId ?
46
- `appId eq '${formatting.encodeQueryParameter(appId)}'` :
47
- `displayName eq '${formatting.encodeQueryParameter(name)}'`;
48
- const requestOptions = {
49
- url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
50
- headers: {
51
- accept: 'application/json;odata.metadata=none'
52
- },
53
- responseType: 'json'
54
- };
55
- const res = await request.get(requestOptions);
56
- if (res.value.length === 1) {
57
- return res.value[0].id;
46
+ if (this.verbose) {
47
+ await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appId ? appId : name}...`);
48
+ }
49
+ if (appId) {
50
+ const app = await entraApp.getAppRegistrationByAppId(appId, ["id"]);
51
+ return app.id;
58
52
  }
59
- if (res.value.length === 0) {
60
- const applicationIdentifier = appId ? `ID ${appId}` : `name ${name}`;
61
- throw `No Microsoft Entra application registration with ${applicationIdentifier} found`;
53
+ else {
54
+ const requestOptions = {
55
+ url: `${this.resource}/v1.0/myorganization/applications?$filter=displayName eq '${formatting.encodeQueryParameter(name)}'&$select=id`,
56
+ headers: {
57
+ accept: 'application/json;odata.metadata=none'
58
+ },
59
+ responseType: 'json'
60
+ };
61
+ const res = await request.get(requestOptions);
62
+ if (res.value.length === 1) {
63
+ return res.value[0].id;
64
+ }
65
+ if (res.value.length === 0) {
66
+ throw `No Microsoft Entra application registration with name ${name} found`;
67
+ }
68
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
69
+ const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registrations with name '${name}' found.`, resultAsKeyValuePair);
70
+ return result.id;
62
71
  }
63
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
64
- const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registrations with name '${name}' found.`, resultAsKeyValuePair);
65
- return result.id;
66
72
  }
67
73
  async getAppInfo(appObjectId, properties) {
68
74
  const queryParameters = [];
@@ -10,6 +10,7 @@ import request from "../../../../request.js";
10
10
  import { validation } from "../../../../utils/validation.js";
11
11
  import { formatting } from "../../../../utils/formatting.js";
12
12
  import { cli } from "../../../../cli/cli.js";
13
+ import { entraApp } from "../../../../utils/entraApp.js";
13
14
  class EntraAppPermissionListCommand extends GraphCommand {
14
15
  get name() {
15
16
  return commands.APP_PERMISSION_LIST;
@@ -28,7 +29,7 @@ class EntraAppPermissionListCommand extends GraphCommand {
28
29
  }
29
30
  async commandAction(logger, args) {
30
31
  try {
31
- const appObjectId = await this.getAppObjectId(args.options);
32
+ const appObjectId = await this.getAppObjectId(args.options, logger);
32
33
  const type = args.options.type ?? 'all';
33
34
  const permissions = await this.getAppRegPermissions(appObjectId, type, logger);
34
35
  await logger.log(permissions);
@@ -37,32 +38,37 @@ class EntraAppPermissionListCommand extends GraphCommand {
37
38
  this.handleRejectedODataJsonPromise(err);
38
39
  }
39
40
  }
40
- async getAppObjectId(options) {
41
+ async getAppObjectId(options, logger) {
41
42
  if (options.appObjectId) {
42
43
  return options.appObjectId;
43
44
  }
44
45
  const { appId, appName } = options;
45
- const filter = appId ?
46
- `appId eq '${formatting.encodeQueryParameter(appId)}'` :
47
- `displayName eq '${formatting.encodeQueryParameter(appName)}'`;
48
- const requestOptions = {
49
- url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
50
- headers: {
51
- accept: 'application/json;odata.metadata=none'
52
- },
53
- responseType: 'json'
54
- };
55
- const res = await request.get(requestOptions);
56
- if (res.value.length === 1) {
57
- return res.value[0].id;
58
- }
59
- if (res.value.length === 0) {
60
- const applicationIdentifier = appId ? `ID ${appId}` : `name ${appName}`;
61
- throw `No Microsoft Entra application registration with ${applicationIdentifier} found`;
46
+ if (this.verbose) {
47
+ await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appId ? appId : appName}...`);
48
+ }
49
+ if (appId) {
50
+ const app = await entraApp.getAppRegistrationByAppId(appId, ["id"]);
51
+ return app.id;
52
+ }
53
+ else {
54
+ const requestOptions = {
55
+ url: `${this.resource}/v1.0/myorganization/applications?$filter=displayName eq '${formatting.encodeQueryParameter(appName)}'&$select=id`,
56
+ headers: {
57
+ accept: 'application/json;odata.metadata=none'
58
+ },
59
+ responseType: 'json'
60
+ };
61
+ const res = await request.get(requestOptions);
62
+ if (res.value.length === 1) {
63
+ return res.value[0].id;
64
+ }
65
+ if (res.value.length === 0) {
66
+ throw `No Microsoft Entra application registration with name ${appName} found`;
67
+ }
68
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
69
+ const result = await cli.handleMultipleResultsFound(`Multiple Entra application registrations with name '${appName}' found.`, resultAsKeyValuePair);
70
+ return result.id;
62
71
  }
63
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
64
- const result = await cli.handleMultipleResultsFound(`Multiple Entra application registrations with name '${appName}' found.`, resultAsKeyValuePair);
65
- return result.id;
66
72
  }
67
73
  async getAppRegPermissions(appObjectId, permissionType, logger) {
68
74
  const requestOptions = {
@@ -6,6 +6,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
6
6
  var _EntraAppRemoveCommand_instances, _EntraAppRemoveCommand_initTelemetry, _EntraAppRemoveCommand_initOptions, _EntraAppRemoveCommand_initValidators, _EntraAppRemoveCommand_initOptionSets;
7
7
  import { cli } from '../../../../cli/cli.js';
8
8
  import request from '../../../../request.js';
9
+ import { entraApp } from '../../../../utils/entraApp.js';
9
10
  import { formatting } from '../../../../utils/formatting.js';
10
11
  import { validation } from '../../../../utils/validation.js';
11
12
  import GraphCommand from '../../../base/GraphCommand.js';
@@ -63,27 +64,29 @@ class EntraAppRemoveCommand extends GraphCommand {
63
64
  if (this.verbose) {
64
65
  await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appId ? appId : name}...`);
65
66
  }
66
- const filter = appId ?
67
- `appId eq '${formatting.encodeQueryParameter(appId)}'` :
68
- `displayName eq '${formatting.encodeQueryParameter(name)}'`;
69
- const requestOptions = {
70
- url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
71
- headers: {
72
- accept: 'application/json;odata.metadata=none'
73
- },
74
- responseType: 'json'
75
- };
76
- const res = await request.get(requestOptions);
77
- if (res.value.length === 1) {
78
- return res.value[0].id;
67
+ if (appId) {
68
+ const app = await entraApp.getAppRegistrationByAppId(appId, ['id']);
69
+ return app.id;
79
70
  }
80
- if (res.value.length === 0) {
81
- const applicationIdentifier = appId ? `ID ${appId}` : `name ${name}`;
82
- throw `No Microsoft Entra application registration with ${applicationIdentifier} found`;
71
+ else {
72
+ const requestOptions = {
73
+ url: `${this.resource}/v1.0/myorganization/applications?$filter=displayName eq '${formatting.encodeQueryParameter(name)}'&$select=id`,
74
+ headers: {
75
+ accept: 'application/json;odata.metadata=none'
76
+ },
77
+ responseType: 'json'
78
+ };
79
+ const res = await request.get(requestOptions);
80
+ if (res.value.length === 1) {
81
+ return res.value[0].id;
82
+ }
83
+ if (res.value.length === 0) {
84
+ throw `No Microsoft Entra application registration with name ${name} found`;
85
+ }
86
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
87
+ const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registration with name '${name}' found.`, resultAsKeyValuePair);
88
+ return result.id;
83
89
  }
84
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
85
- const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registration with name '${name}' found.`, resultAsKeyValuePair);
86
- return result.id;
87
90
  }
88
91
  }
89
92
  _EntraAppRemoveCommand_instances = new WeakSet(), _EntraAppRemoveCommand_initTelemetry = function _EntraAppRemoveCommand_initTelemetry() {
@@ -10,6 +10,7 @@ import { formatting } from '../../../../utils/formatting.js';
10
10
  import GraphCommand from '../../../base/GraphCommand.js';
11
11
  import commands from '../../commands.js';
12
12
  import { cli } from '../../../../cli/cli.js';
13
+ import { entraApp } from '../../../../utils/entraApp.js';
13
14
  class EntraAppRoleAddCommand extends GraphCommand {
14
15
  get name() {
15
16
  return commands.APP_ROLE_ADD;
@@ -87,27 +88,29 @@ class EntraAppRoleAddCommand extends GraphCommand {
87
88
  if (this.verbose) {
88
89
  await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appId ? appId : appName}...`);
89
90
  }
90
- const filter = appId ?
91
- `appId eq '${formatting.encodeQueryParameter(appId)}'` :
92
- `displayName eq '${formatting.encodeQueryParameter(appName)}'`;
93
- const requestOptions = {
94
- url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
95
- headers: {
96
- accept: 'application/json;odata.metadata=none'
97
- },
98
- responseType: 'json'
99
- };
100
- const res = await request.get(requestOptions);
101
- if (res.value.length === 1) {
102
- return res.value[0].id;
91
+ if (appId) {
92
+ const app = await entraApp.getAppRegistrationByAppId(appId, ['id']);
93
+ return app.id;
103
94
  }
104
- if (res.value.length === 0) {
105
- const applicationIdentifier = appId ? `ID ${appId}` : `name ${appName}`;
106
- throw `No Microsoft Entra application registration with ${applicationIdentifier} found`;
95
+ else {
96
+ const requestOptions = {
97
+ url: `${this.resource}/v1.0/myorganization/applications?$filter=displayName eq '${formatting.encodeQueryParameter(appName)}'&$select=id`,
98
+ headers: {
99
+ accept: 'application/json;odata.metadata=none'
100
+ },
101
+ responseType: 'json'
102
+ };
103
+ const res = await request.get(requestOptions);
104
+ if (res.value.length === 1) {
105
+ return res.value[0].id;
106
+ }
107
+ if (res.value.length === 0) {
108
+ throw `No Microsoft Entra application registration with name ${appName} found`;
109
+ }
110
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
111
+ const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registrations with name '${appName}' found.`, resultAsKeyValuePair);
112
+ return result.id;
107
113
  }
108
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
109
- const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registrations with name '${appName}' found.`, resultAsKeyValuePair);
110
- return result.id;
111
114
  }
112
115
  }
113
116
  _a = EntraAppRoleAddCommand, _EntraAppRoleAddCommand_instances = new WeakSet(), _EntraAppRoleAddCommand_initTelemetry = function _EntraAppRoleAddCommand_initTelemetry() {
@@ -10,6 +10,7 @@ import { odata } from '../../../../utils/odata.js';
10
10
  import GraphCommand from '../../../base/GraphCommand.js';
11
11
  import commands from '../../commands.js';
12
12
  import { cli } from '../../../../cli/cli.js';
13
+ import { entraApp } from '../../../../utils/entraApp.js';
13
14
  class EntraAppRoleListCommand extends GraphCommand {
14
15
  get name() {
15
16
  return commands.APP_ROLE_LIST;
@@ -45,27 +46,29 @@ class EntraAppRoleListCommand extends GraphCommand {
45
46
  if (this.verbose) {
46
47
  await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appId ? appId : appName}...`);
47
48
  }
48
- const filter = appId ?
49
- `appId eq '${formatting.encodeQueryParameter(appId)}'` :
50
- `displayName eq '${formatting.encodeQueryParameter(appName)}'`;
51
- const requestOptions = {
52
- url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
53
- headers: {
54
- accept: 'application/json;odata.metadata=none'
55
- },
56
- responseType: 'json'
57
- };
58
- const res = await request.get(requestOptions);
59
- if (res.value.length === 1) {
60
- return res.value[0].id;
49
+ if (appId) {
50
+ const app = await entraApp.getAppRegistrationByAppId(appId, ["id"]);
51
+ return app.id;
61
52
  }
62
- if (res.value.length === 0) {
63
- const applicationIdentifier = appId ? `ID ${appId}` : `name ${appName}`;
64
- throw `No Microsoft Entra application registration with ${applicationIdentifier} found`;
53
+ else {
54
+ const requestOptions = {
55
+ url: `${this.resource}/v1.0/myorganization/applications?$filter=displayName eq '${formatting.encodeQueryParameter(appName)}'&$select=id`,
56
+ headers: {
57
+ accept: 'application/json;odata.metadata=none'
58
+ },
59
+ responseType: 'json'
60
+ };
61
+ const res = await request.get(requestOptions);
62
+ if (res.value.length === 1) {
63
+ return res.value[0].id;
64
+ }
65
+ if (res.value.length === 0) {
66
+ throw `No Microsoft Entra application registration with name ${appName} found`;
67
+ }
68
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
69
+ const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registrations with name '${appName}' found.`, resultAsKeyValuePair);
70
+ return result.id;
65
71
  }
66
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
67
- const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registrations with name '${appName}' found.`, resultAsKeyValuePair);
68
- return result.id;
69
72
  }
70
73
  }
71
74
  _EntraAppRoleListCommand_instances = new WeakSet(), _EntraAppRoleListCommand_initTelemetry = function _EntraAppRoleListCommand_initTelemetry() {
@@ -10,6 +10,7 @@ import { formatting } from "../../../../utils/formatting.js";
10
10
  import { validation } from '../../../../utils/validation.js';
11
11
  import GraphCommand from '../../../base/GraphCommand.js';
12
12
  import commands from '../../commands.js';
13
+ import { entraApp } from "../../../../utils/entraApp.js";
13
14
  class EntraAppRoleRemoveCommand extends GraphCommand {
14
15
  get name() {
15
16
  return commands.APP_ROLE_REMOVE;
@@ -46,15 +47,15 @@ class EntraAppRoleRemoveCommand extends GraphCommand {
46
47
  }
47
48
  async processAppRoleDelete(logger, args) {
48
49
  const appObjectId = await this.getAppObjectId(args, logger);
49
- const aadApp = await this.getAadApp(appObjectId, logger);
50
+ const app = await this.getEntraApp(appObjectId, logger);
50
51
  const appRoleDeleteIdentifierNameValue = args.options.name ? `name '${args.options.name}'` : (args.options.claim ? `claim '${args.options.claim}'` : `id '${args.options.id}'`);
51
52
  if (this.verbose) {
52
- await logger.logToStderr(`Deleting role with ${appRoleDeleteIdentifierNameValue} from Microsoft Entra app ${aadApp.id}...`);
53
+ await logger.logToStderr(`Deleting role with ${appRoleDeleteIdentifierNameValue} from Microsoft Entra app ${app.id}...`);
53
54
  }
54
55
  // Find the role search criteria provided by the user.
55
56
  const appRoleDeleteIdentifierProperty = args.options.name ? `displayName` : (args.options.claim ? `value` : `id`);
56
57
  const appRoleDeleteIdentifierValue = args.options.name ? args.options.name : (args.options.claim ? args.options.claim : args.options.id);
57
- const appRoleToDelete = aadApp.appRoles.filter((role) => role[appRoleDeleteIdentifierProperty] === appRoleDeleteIdentifierValue);
58
+ const appRoleToDelete = app.appRoles.filter((role) => role[appRoleDeleteIdentifierProperty] === appRoleDeleteIdentifierValue);
58
59
  if (args.options.name &&
59
60
  appRoleToDelete !== undefined &&
60
61
  appRoleToDelete.length > 1) {
@@ -66,38 +67,38 @@ class EntraAppRoleRemoveCommand extends GraphCommand {
66
67
  }
67
68
  const roleToDelete = appRoleToDelete[0];
68
69
  if (roleToDelete.isEnabled) {
69
- await this.disableAppRole(logger, aadApp, roleToDelete.id);
70
- await this.deleteAppRole(logger, aadApp, roleToDelete.id);
70
+ await this.disableAppRole(logger, app, roleToDelete.id);
71
+ await this.deleteAppRole(logger, app, roleToDelete.id);
71
72
  }
72
73
  else {
73
- await this.deleteAppRole(logger, aadApp, roleToDelete.id);
74
+ await this.deleteAppRole(logger, app, roleToDelete.id);
74
75
  }
75
76
  }
76
- async disableAppRole(logger, aadApp, roleId) {
77
- const roleIndex = aadApp.appRoles.findIndex((role) => role.id === roleId);
77
+ async disableAppRole(logger, app, roleId) {
78
+ const roleIndex = app.appRoles.findIndex((role) => role.id === roleId);
78
79
  if (this.verbose) {
79
80
  await logger.logToStderr(`Disabling the app role`);
80
81
  }
81
- aadApp.appRoles[roleIndex].isEnabled = false;
82
+ app.appRoles[roleIndex].isEnabled = false;
82
83
  const requestOptions = {
83
- url: `${this.resource}/v1.0/myorganization/applications/${aadApp.id}`,
84
+ url: `${this.resource}/v1.0/myorganization/applications/${app.id}`,
84
85
  headers: {
85
86
  accept: 'application/json;odata.metadata=none'
86
87
  },
87
88
  responseType: 'json',
88
89
  data: {
89
- appRoles: aadApp.appRoles
90
+ appRoles: app.appRoles
90
91
  }
91
92
  };
92
93
  return request.patch(requestOptions);
93
94
  }
94
- async deleteAppRole(logger, aadApp, roleId) {
95
+ async deleteAppRole(logger, app, roleId) {
95
96
  if (this.verbose) {
96
97
  await logger.logToStderr(`Deleting the app role.`);
97
98
  }
98
- const updatedAppRoles = aadApp.appRoles.filter((role) => role.id !== roleId);
99
+ const updatedAppRoles = app.appRoles.filter((role) => role.id !== roleId);
99
100
  const requestOptions = {
100
- url: `${this.resource}/v1.0/myorganization/applications/${aadApp.id}`,
101
+ url: `${this.resource}/v1.0/myorganization/applications/${app.id}`,
101
102
  headers: {
102
103
  accept: 'application/json;odata.metadata=none'
103
104
  },
@@ -108,12 +109,12 @@ class EntraAppRoleRemoveCommand extends GraphCommand {
108
109
  };
109
110
  return request.patch(requestOptions);
110
111
  }
111
- async getAadApp(appId, logger) {
112
+ async getEntraApp(appObjectId, logger) {
112
113
  if (this.verbose) {
113
- await logger.logToStderr(`Retrieving app roles information for the Microsoft Entra app ${appId}...`);
114
+ await logger.logToStderr(`Retrieving app roles information for the Microsoft Entra app ${appObjectId}...`);
114
115
  }
115
116
  const requestOptions = {
116
- url: `${this.resource}/v1.0/myorganization/applications/${appId}?$select=id,appRoles`,
117
+ url: `${this.resource}/v1.0/myorganization/applications/${appObjectId}?$select=id,appRoles`,
117
118
  headers: {
118
119
  accept: 'application/json;odata.metadata=none'
119
120
  },
@@ -129,27 +130,29 @@ class EntraAppRoleRemoveCommand extends GraphCommand {
129
130
  if (this.verbose) {
130
131
  await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appId ? appId : appName}...`);
131
132
  }
132
- const filter = appId ?
133
- `appId eq '${formatting.encodeQueryParameter(appId)}'` :
134
- `displayName eq '${formatting.encodeQueryParameter(appName)}'`;
135
- const requestOptions = {
136
- url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
137
- headers: {
138
- accept: 'application/json;odata.metadata=none'
139
- },
140
- responseType: 'json'
141
- };
142
- const res = await request.get(requestOptions);
143
- if (res.value.length === 1) {
144
- return res.value[0].id;
133
+ if (appId) {
134
+ const app = await entraApp.getAppRegistrationByAppId(appId, ['id']);
135
+ return app.id;
145
136
  }
146
- if (res.value.length === 0) {
147
- const applicationIdentifier = appId ? `ID ${appId}` : `name ${appName}`;
148
- throw `No Microsoft Entra application registration with ${applicationIdentifier} found`;
137
+ else {
138
+ const requestOptions = {
139
+ url: `${this.resource}/v1.0/myorganization/applications?$filter=displayName eq '${formatting.encodeQueryParameter(appName)}'&$select=id`,
140
+ headers: {
141
+ accept: 'application/json;odata.metadata=none'
142
+ },
143
+ responseType: 'json'
144
+ };
145
+ const res = await request.get(requestOptions);
146
+ if (res.value.length === 1) {
147
+ return res.value[0].id;
148
+ }
149
+ if (res.value.length === 0) {
150
+ throw `No Microsoft Entra application registration with name ${appName} found`;
151
+ }
152
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
153
+ const result = (await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registrations with name '${appName}' found.`, resultAsKeyValuePair));
154
+ return result.id;
149
155
  }
150
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
151
- const result = (await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registrations with name '${appName}' found.`, resultAsKeyValuePair));
152
- return result.id;
153
156
  }
154
157
  }
155
158
  _EntraAppRoleRemoveCommand_instances = new WeakSet(), _EntraAppRoleRemoveCommand_initTelemetry = function _EntraAppRoleRemoveCommand_initTelemetry() {
@@ -11,6 +11,7 @@ import GraphCommand from '../../../base/GraphCommand.js';
11
11
  import commands from '../../commands.js';
12
12
  import { cli } from '../../../../cli/cli.js';
13
13
  import { optionsUtils } from '../../../../utils/optionsUtils.js';
14
+ import { entraApp } from '../../../../utils/entraApp.js';
14
15
  class EntraAppSetCommand extends GraphCommand {
15
16
  get name() {
16
17
  return commands.APP_SET;
@@ -51,27 +52,29 @@ class EntraAppSetCommand extends GraphCommand {
51
52
  if (this.verbose) {
52
53
  await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appId ? appId : name}...`);
53
54
  }
54
- const filter = appId ?
55
- `appId eq '${formatting.encodeQueryParameter(appId)}'` :
56
- `displayName eq '${formatting.encodeQueryParameter(name)}'`;
57
- const requestOptions = {
58
- url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
59
- headers: {
60
- accept: 'application/json;odata.metadata=none'
61
- },
62
- responseType: 'json'
63
- };
64
- const res = await request.get(requestOptions);
65
- if (res.value.length === 1) {
66
- return res.value[0].id;
55
+ if (appId) {
56
+ const app = await entraApp.getAppRegistrationByAppId(appId, ['id']);
57
+ return app.id;
67
58
  }
68
- if (res.value.length === 0) {
69
- const applicationIdentifier = appId ? `ID ${appId}` : `name ${name}`;
70
- throw `No Microsoft Entra application registration with ${applicationIdentifier} found`;
59
+ else {
60
+ const requestOptions = {
61
+ url: `${this.resource}/v1.0/myorganization/applications?$filter=displayName eq '${formatting.encodeQueryParameter(name)}'&$select=id`,
62
+ headers: {
63
+ accept: 'application/json;odata.metadata=none'
64
+ },
65
+ responseType: 'json'
66
+ };
67
+ const res = await request.get(requestOptions);
68
+ if (res.value.length === 1) {
69
+ return res.value[0].id;
70
+ }
71
+ if (res.value.length === 0) {
72
+ throw `No Microsoft Entra application registration with name ${name} found`;
73
+ }
74
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
75
+ const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registration with name '${name}' found.`, resultAsKeyValuePair);
76
+ return result.id;
71
77
  }
72
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', res.value);
73
- const result = await cli.handleMultipleResultsFound(`Multiple Microsoft Entra application registration with name '${name}' found.`, resultAsKeyValuePair);
74
- return result.id;
75
78
  }
76
79
  async updateUnknownOptions(args, objectId) {
77
80
  const unknownOptions = optionsUtils.getUnknownOptions(args.options, this.options);
@@ -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 _PpCardCloneCommand_instances, _PpCardCloneCommand_initTelemetry, _PpCardCloneCommand_initOptions, _PpCardCloneCommand_initOptionSets, _PpCardCloneCommand_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 ppCardGetCommand from './card-get.js';
14
12
  class PpCardCloneCommand extends PowerPlatformCommand {
15
13
  get name() {
16
14
  return commands.CARD_CLONE;
@@ -30,28 +28,20 @@ class PpCardCloneCommand extends PowerPlatformCommand {
30
28
  if (this.verbose) {
31
29
  await logger.logToStderr(`Cloning a card from '${args.options.id || args.options.name}'...`);
32
30
  }
33
- const res = await this.cloneCard(args);
31
+ const res = await this.cloneCard(args, logger);
34
32
  await logger.log(res);
35
33
  }
36
- async getCardId(args) {
34
+ async getCardId(args, dynamicsApiUrl, logger) {
37
35
  if (args.options.id) {
38
36
  return args.options.id;
39
37
  }
40
- const options = {
41
- environmentName: args.options.environmentName,
42
- name: args.options.name,
43
- output: 'json',
44
- debug: this.debug,
45
- verbose: this.verbose
46
- };
47
- const output = await cli.executeCommandWithOutput(ppCardGetCommand, { options: { ...options, _: [] } });
48
- const getCardOutput = JSON.parse(output.stdout);
49
- return getCardOutput.cardid;
38
+ const card = await powerPlatform.getCardByName(dynamicsApiUrl, args.options.name, logger, this.verbose);
39
+ return card.cardid;
50
40
  }
51
- async cloneCard(args) {
41
+ async cloneCard(args, logger) {
52
42
  try {
53
43
  const dynamicsApiUrl = await powerPlatform.getDynamicsInstanceApiUrl(args.options.environmentName, args.options.asAdmin);
54
- const cardId = await this.getCardId(args);
44
+ const cardId = await this.getCardId(args, dynamicsApiUrl, logger);
55
45
  const requestOptions = {
56
46
  url: `${dynamicsApiUrl}/api/data/v9.1/CardCreateClone`,
57
47
  headers: {