@pnp/cli-microsoft365 10.11.0-beta.5e075e5 → 10.11.0-beta.b1eeb91

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.
Files changed (87) hide show
  1. package/.eslintrc.cjs +2 -0
  2. package/Dockerfile +2 -2
  3. package/allCommands.json +1 -1
  4. package/allCommandsFull.json +1 -1
  5. package/dist/m365/base/GraphApplicationCommand.js +17 -0
  6. package/dist/m365/base/{DelegatedGraphCommand.js → GraphDelegatedCommand.js} +4 -4
  7. package/dist/m365/base/PowerAppsCommand.js +1 -1
  8. package/dist/m365/base/PowerAutomateCommand.js +1 -1
  9. package/dist/m365/base/PowerBICommand.js +1 -1
  10. package/dist/m365/base/PowerPlatformCommand.js +1 -1
  11. package/dist/m365/base/VivaEngageCommand.js +1 -1
  12. package/dist/m365/entra/commands/app/app-get.js +11 -52
  13. package/dist/m365/entra/commands/app/app-permission-add.js +19 -30
  14. package/dist/m365/entra/commands/app/app-permission-list.js +2 -19
  15. package/dist/m365/entra/commands/app/app-permission-remove.js +22 -31
  16. package/dist/m365/entra/commands/app/app-remove.js +2 -18
  17. package/dist/m365/entra/commands/app/app-role-add.js +10 -43
  18. package/dist/m365/entra/commands/app/app-role-list.js +2 -20
  19. package/dist/m365/entra/commands/app/app-role-remove.js +9 -40
  20. package/dist/m365/entra/commands/app/app-set.js +2 -19
  21. package/dist/m365/outlook/commands/message/message-move.js +1 -1
  22. package/dist/m365/pp/commands/managementapp/managementapp-add.js +7 -21
  23. package/dist/m365/spe/commands/container/container-recyclebinitem-restore.js +96 -0
  24. package/dist/m365/spe/commands.js +1 -0
  25. package/dist/m365/spfx/commands/project/base-project-command.js +1 -0
  26. package/dist/m365/spfx/commands/project/project-doctor/doctor-1.22.0-beta.1.js +19 -0
  27. package/dist/m365/spfx/commands/project/project-doctor.js +2 -1
  28. package/dist/m365/spfx/commands/project/project-model/SassJson.js +2 -0
  29. package/dist/m365/spfx/commands/project/project-model/index.js +1 -0
  30. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN002001_DEVDEP_microsoft_sp_build_web.js +2 -2
  31. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN002004_DEVDEP_gulp.js +2 -2
  32. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN002007_DEVDEP_ajv.js +2 -2
  33. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN002029_DEVDEP_microsoft_rush_stack_compiler_5_3.js +2 -2
  34. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN002030_DEVDEP_microsoft_spfx_web_build_rig.js +10 -0
  35. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN002031_DEVDEP_rushstack_heft.js +10 -0
  36. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN002032_DEVDEP_typescript_eslint_parser.js +10 -0
  37. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN002033_DEVDEP_jest_junit.js +10 -0
  38. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN010011_YORC_useGulp.js +40 -0
  39. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN015010_FILE_gulpfile_js.js +10 -0
  40. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN015011_FILE_tsconfig_json.js +10 -0
  41. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN015012_FILE_config_heft_json.js +10 -0
  42. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN015013_FILE_config_jest_config_json.js +10 -0
  43. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN015014_FILE_config_rig_json.js +10 -0
  44. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN015015_FILE_config_typescript_json.js +10 -0
  45. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN021004_PKG_scripts_build.js +45 -0
  46. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN021005_PKG_scripts_test.js +45 -0
  47. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN021006_PKG_scripts_clean.js +45 -0
  48. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN021007_PKG_scripts_deploy.js +45 -0
  49. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN021008_PKG_scripts_start.js +45 -0
  50. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN021009_PKG_scripts_build_watch.js +45 -0
  51. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN021010_PKG_scripts_package_solution.js +45 -0
  52. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN021011_PKG_scripts_deploy_azure_storage.js +45 -0
  53. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN021012_PKG_scripts_eject_webpack.js +45 -0
  54. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN021013_PKG_overrides_rushstack_heft.js +45 -0
  55. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN023003_GITIGNORE_libdts.js +36 -0
  56. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN023004_GITIGNORE_libcommonjs.js +36 -0
  57. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN023005_GITIGNORE_libesm.js +36 -0
  58. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN023006_GITIGNORE_jestoutput.js +36 -0
  59. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN026001_CFG_SASS_schema.js +40 -0
  60. package/dist/m365/spfx/commands/project/project-upgrade/rules/FN026002_CFG_SASS_extends.js +40 -0
  61. package/dist/m365/spfx/commands/project/project-upgrade/rules/FileAddRemoveRule.js +7 -0
  62. package/dist/m365/spfx/commands/project/project-upgrade/upgrade-1.22.0-beta.1.js +241 -0
  63. package/dist/m365/spfx/commands/project/project-upgrade.js +16 -13
  64. package/dist/m365/spfx/commands/spfx-doctor.js +15 -0
  65. package/dist/m365/spo/commands/tenant/tenant-site-unarchive.js +1 -1
  66. package/dist/m365/teams/commands/callrecord/callrecord-list.js +100 -0
  67. package/dist/m365/teams/commands/chat/chat-message-send.js +2 -2
  68. package/dist/m365/teams/commands/message/message-remove.js +2 -2
  69. package/dist/m365/teams/commands/message/message-restore.js +2 -2
  70. package/dist/m365/teams/commands.js +1 -0
  71. package/dist/m365/todo/commands/list/list-add.js +2 -2
  72. package/dist/m365/todo/commands/list/list-get.js +2 -2
  73. package/dist/m365/todo/commands/list/list-list.js +2 -2
  74. package/dist/m365/todo/commands/list/list-remove.js +2 -2
  75. package/dist/m365/todo/commands/list/list-set.js +2 -2
  76. package/dist/m365/todo/commands/task/task-add.js +2 -2
  77. package/dist/m365/todo/commands/task/task-get.js +2 -2
  78. package/dist/m365/todo/commands/task/task-list.js +2 -2
  79. package/dist/m365/todo/commands/task/task-remove.js +2 -2
  80. package/dist/m365/todo/commands/task/task-set.js +2 -2
  81. package/dist/utils/accessToken.js +9 -5
  82. package/dist/utils/entraApp.js +15 -0
  83. package/docs/docs/cmd/spe/container/container-recyclebinitem-restore.mdx +53 -0
  84. package/docs/docs/cmd/spo/tenant/tenant-site-unarchive.mdx +1 -1
  85. package/docs/docs/cmd/teams/callrecord/callrecord-list.mdx +173 -0
  86. package/npm-shrinkwrap.json +291 -763
  87. package/package.json +17 -17
@@ -0,0 +1,17 @@
1
+ import auth from '../../Auth.js';
2
+ import { accessToken } from '../../utils/accessToken.js';
3
+ import GraphCommand from './GraphCommand.js';
4
+ /**
5
+ * This command class is for application-only Graph commands.
6
+ */
7
+ export default class GraphApplicationCommand extends GraphCommand {
8
+ async initAction(args, logger) {
9
+ await super.initAction(args, logger);
10
+ if (!auth.connection.active) {
11
+ // we fail no login in the base command command class
12
+ return;
13
+ }
14
+ accessToken.assertAccessTokenType('application');
15
+ }
16
+ }
17
+ //# sourceMappingURL=GraphApplicationCommand.js.map
@@ -2,16 +2,16 @@ import auth from '../../Auth.js';
2
2
  import { accessToken } from '../../utils/accessToken.js';
3
3
  import GraphCommand from './GraphCommand.js';
4
4
  /**
5
- * This command class is for delegated-only Graph commands.
5
+ * This command class is for delegated Graph commands.
6
6
  */
7
- export default class DelegatedGraphCommand extends GraphCommand {
7
+ export default class GraphDelegatedCommand extends GraphCommand {
8
8
  async initAction(args, logger) {
9
9
  await super.initAction(args, logger);
10
10
  if (!auth.connection.active) {
11
11
  // we fail no login in the base command command class
12
12
  return;
13
13
  }
14
- accessToken.assertDelegatedAccessToken();
14
+ accessToken.assertAccessTokenType('delegated');
15
15
  }
16
16
  }
17
- //# sourceMappingURL=DelegatedGraphCommand.js.map
17
+ //# sourceMappingURL=GraphDelegatedCommand.js.map
@@ -14,7 +14,7 @@ export default class PowerAppsCommand extends Command {
14
14
  if (auth.connection.cloudType !== CloudType.Public) {
15
15
  throw new CommandError(`Power Apps commands only support the public cloud at the moment. We'll add support for other clouds in the future. Sorry for the inconvenience.`);
16
16
  }
17
- accessToken.assertDelegatedAccessToken();
17
+ accessToken.assertAccessTokenType('delegated');
18
18
  }
19
19
  }
20
20
  //# sourceMappingURL=PowerAppsCommand.js.map
@@ -14,7 +14,7 @@ export default class PowerAutomateCommand extends Command {
14
14
  if (auth.connection.cloudType !== CloudType.Public) {
15
15
  throw new CommandError(`Power Automate commands only support the public cloud at the moment. We'll add support for other clouds in the future. Sorry for the inconvenience.`);
16
16
  }
17
- accessToken.assertDelegatedAccessToken();
17
+ accessToken.assertAccessTokenType('delegated');
18
18
  }
19
19
  }
20
20
  //# sourceMappingURL=PowerAutomateCommand.js.map
@@ -11,7 +11,7 @@ export default class PowerBICommand extends Command {
11
11
  // we fail no login in the base command command class
12
12
  return;
13
13
  }
14
- accessToken.assertDelegatedAccessToken();
14
+ accessToken.assertAccessTokenType('delegated');
15
15
  }
16
16
  }
17
17
  //# sourceMappingURL=PowerBICommand.js.map
@@ -14,7 +14,7 @@ export default class PowerPlatformCommand extends Command {
14
14
  if (auth.connection.cloudType !== CloudType.Public) {
15
15
  throw new CommandError(`Power Platform commands only support the public cloud at the moment. We'll add support for other clouds in the future. Sorry for the inconvenience.`);
16
16
  }
17
- accessToken.assertDelegatedAccessToken();
17
+ accessToken.assertAccessTokenType('delegated');
18
18
  }
19
19
  }
20
20
  //# sourceMappingURL=PowerPlatformCommand.js.map
@@ -11,7 +11,7 @@ export default class VivaEngageCommand extends Command {
11
11
  // we fail no login in the base command command class
12
12
  return;
13
13
  }
14
- accessToken.assertDelegatedAccessToken();
14
+ accessToken.assertAccessTokenType('delegated');
15
15
  }
16
16
  handleRejectedODataJsonPromise(response) {
17
17
  if (response.statusCode === 404) {
@@ -5,12 +5,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
5
5
  };
6
6
  var _EntraAppGetCommand_instances, _EntraAppGetCommand_initTelemetry, _EntraAppGetCommand_initOptions, _EntraAppGetCommand_initValidators, _EntraAppGetCommand_initOptionSets;
7
7
  import fs from 'fs';
8
- import request from '../../../../request.js';
9
- import { formatting } from '../../../../utils/formatting.js';
10
8
  import { validation } from '../../../../utils/validation.js';
11
9
  import GraphCommand from '../../../base/GraphCommand.js';
12
10
  import commands from '../../commands.js';
13
- import { cli } from '../../../../cli/cli.js';
14
11
  import { entraApp } from '../../../../utils/entraApp.js';
15
12
  class EntraAppGetCommand extends GraphCommand {
16
13
  get name() {
@@ -29,8 +26,7 @@ class EntraAppGetCommand extends GraphCommand {
29
26
  }
30
27
  async commandAction(logger, args) {
31
28
  try {
32
- const appObjectId = await this.getAppObjectId(args, logger);
33
- const appInfo = await this.getAppInfo(appObjectId, args.options.properties);
29
+ const appInfo = await this.getAppInfo(args, logger);
34
30
  const res = await this.saveAppInfo(args, appInfo, logger);
35
31
  await logger.log(res);
36
32
  }
@@ -38,58 +34,21 @@ class EntraAppGetCommand extends GraphCommand {
38
34
  this.handleRejectedODataJsonPromise(err);
39
35
  }
40
36
  }
41
- async getAppObjectId(args, logger) {
42
- if (args.options.objectId) {
43
- return args.options.objectId;
44
- }
45
- const { appId, name } = args.options;
37
+ async getAppInfo(args, logger) {
38
+ const { objectId, appId, name } = args.options;
39
+ const properties = args.options.properties?.split(',');
46
40
  if (this.verbose) {
47
- await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appId ? appId : name}...`);
41
+ await logger.logToStderr(`Retrieving information about Microsoft Entra app ${objectId ? objectId : (appId ? appId : name)}...`);
48
42
  }
49
- if (appId) {
50
- const app = await entraApp.getAppRegistrationByAppId(appId, ["id"]);
51
- return app.id;
43
+ if (objectId) {
44
+ return await entraApp.getAppRegistrationByObjectId(objectId, properties);
52
45
  }
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;
46
+ else if (appId) {
47
+ return await entraApp.getAppRegistrationByAppId(appId, properties);
71
48
  }
72
- }
73
- async getAppInfo(appObjectId, properties) {
74
- const queryParameters = [];
75
- if (properties) {
76
- const allProperties = properties.split(',');
77
- const selectProperties = allProperties.filter(prop => !prop.includes('/'));
78
- if (selectProperties.length > 0) {
79
- queryParameters.push(`$select=${selectProperties}`);
80
- }
49
+ else {
50
+ return await entraApp.getAppRegistrationByAppName(name, properties);
81
51
  }
82
- const queryString = queryParameters.length > 0
83
- ? `?${queryParameters.join('&')}`
84
- : '';
85
- const requestOptions = {
86
- url: `${this.resource}/v1.0/myorganization/applications/${appObjectId}${queryString}`,
87
- headers: {
88
- accept: 'application/json;odata.metadata=none'
89
- },
90
- responseType: 'json'
91
- };
92
- return request.get(requestOptions);
93
52
  }
94
53
  async saveAppInfo(args, appInfo, logger) {
95
54
  if (!args.options.save) {
@@ -9,8 +9,7 @@ import GraphCommand from "../../../base/GraphCommand.js";
9
9
  import commands from "../../commands.js";
10
10
  import request from "../../../../request.js";
11
11
  import { validation } from "../../../../utils/validation.js";
12
- import { formatting } from "../../../../utils/formatting.js";
13
- import { cli } from "../../../../cli/cli.js";
12
+ import { entraApp } from "../../../../utils/entraApp.js";
14
13
  import { entraServicePrincipal } from "../../../../utils/entraServicePrincipal.js";
15
14
  var ScopeType;
16
15
  (function (ScopeType) {
@@ -34,35 +33,35 @@ class EntraAppPermissionAddCommand extends GraphCommand {
34
33
  }
35
34
  async commandAction(logger, args) {
36
35
  try {
37
- const appObject = await this.getAppObject(args.options);
36
+ const entraApp = await this.getEntraApp(args.options, logger);
38
37
  const servicePrincipals = await this.getServicePrincipals();
39
38
  const appPermissions = [];
40
39
  if (args.options.delegatedPermissions) {
41
40
  const delegatedPermissions = await this.getRequiredResourceAccessForApis(servicePrincipals, args.options.delegatedPermissions, ScopeType.Scope, appPermissions, logger);
42
- this.addPermissionsToResourceArray(delegatedPermissions, appObject.requiredResourceAccess);
41
+ this.addPermissionsToResourceArray(delegatedPermissions, entraApp.requiredResourceAccess);
43
42
  }
44
43
  if (args.options.applicationPermissions) {
45
44
  const applicationPermissions = await this.getRequiredResourceAccessForApis(servicePrincipals, args.options.applicationPermissions, ScopeType.Role, appPermissions, logger);
46
- this.addPermissionsToResourceArray(applicationPermissions, appObject.requiredResourceAccess);
45
+ this.addPermissionsToResourceArray(applicationPermissions, entraApp.requiredResourceAccess);
47
46
  }
48
47
  const addPermissionsRequestOptions = {
49
- url: `${this.resource}/v1.0/applications/${appObject.id}`,
48
+ url: `${this.resource}/v1.0/applications/${entraApp.id}`,
50
49
  headers: {
51
50
  accept: 'application/json;odata.metadata=none'
52
51
  },
53
52
  responseType: 'json',
54
53
  data: {
55
- requiredResourceAccess: appObject.requiredResourceAccess
54
+ requiredResourceAccess: entraApp.requiredResourceAccess
56
55
  }
57
56
  };
58
57
  await request.patch(addPermissionsRequestOptions);
59
58
  if (args.options.grantAdminConsent) {
60
- let appServicePrincipal = servicePrincipals.find(sp => sp.appId === appObject.appId);
59
+ let appServicePrincipal = servicePrincipals.find(sp => sp.appId === entraApp.appId);
61
60
  if (!appServicePrincipal) {
62
61
  if (this.verbose) {
63
- await logger.logToStderr(`Creating service principal for app ${appObject.appId}...`);
62
+ await logger.logToStderr(`Creating service principal for app ${entraApp.appId}...`);
64
63
  }
65
- appServicePrincipal = await entraServicePrincipal.createServicePrincipal(appObject.appId);
64
+ appServicePrincipal = await entraServicePrincipal.createServicePrincipal(entraApp.appId);
66
65
  }
67
66
  await this.grantAdminConsent(appServicePrincipal, appPermissions, logger);
68
67
  }
@@ -71,30 +70,20 @@ class EntraAppPermissionAddCommand extends GraphCommand {
71
70
  this.handleRejectedODataJsonPromise(err);
72
71
  }
73
72
  }
74
- async getAppObject(options) {
75
- let appNotFoundMessage = '';
76
- let apps = [];
77
- if (options.appId) {
78
- apps = await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=appId eq '${options.appId}'&$select=id,appId,requiredResourceAccess`);
79
- appNotFoundMessage = `client id ${options.appId}`;
73
+ async getEntraApp(options, logger) {
74
+ const { appObjectId, appId, appName } = options;
75
+ if (this.verbose) {
76
+ await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appObjectId ? appObjectId : (appId ? appId : appName)}...`);
80
77
  }
81
- else if (options.appName) {
82
- apps = await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=displayName eq '${formatting.encodeQueryParameter(options.appName)}'&$select=id,appId,requiredResourceAccess`);
83
- appNotFoundMessage = `name ${options.appName}`;
84
- if (apps.length > 1) {
85
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', apps);
86
- const result = await cli.handleMultipleResultsFound(`Multiple Entra application registrations with name '${options.appName}' found.`, resultAsKeyValuePair);
87
- return result;
88
- }
78
+ if (appObjectId) {
79
+ return await entraApp.getAppRegistrationByObjectId(appObjectId, ['id', 'appId', 'requiredResourceAccess']);
89
80
  }
90
- else if (options.appObjectId) {
91
- apps = await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=id eq '${options.appObjectId}'&$select=id,appId,requiredResourceAccess`);
92
- appNotFoundMessage = `object id ${options.appObjectId}`;
81
+ else if (appId) {
82
+ return await entraApp.getAppRegistrationByAppId(appId, ['id', 'appId', 'requiredResourceAccess']);
93
83
  }
94
- if (apps.length === 0) {
95
- throw `App with ${appNotFoundMessage} not found in Microsoft Entra ID`;
84
+ else {
85
+ return await entraApp.getAppRegistrationByAppName(appName, ['id', 'appId', 'requiredResourceAccess']);
96
86
  }
97
- return apps[0];
98
87
  }
99
88
  async getServicePrincipals() {
100
89
  return await odata.getAllItems(`${this.resource}/v1.0/servicePrincipals?$select=appId,appRoles,id,oauth2PermissionScopes,servicePrincipalNames`);
@@ -8,8 +8,6 @@ import GraphCommand from "../../../base/GraphCommand.js";
8
8
  import commands from "../../commands.js";
9
9
  import request from "../../../../request.js";
10
10
  import { validation } from "../../../../utils/validation.js";
11
- import { formatting } from "../../../../utils/formatting.js";
12
- import { cli } from "../../../../cli/cli.js";
13
11
  import { entraApp } from "../../../../utils/entraApp.js";
14
12
  class EntraAppPermissionListCommand extends GraphCommand {
15
13
  get name() {
@@ -51,23 +49,8 @@ class EntraAppPermissionListCommand extends GraphCommand {
51
49
  return app.id;
52
50
  }
53
51
  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;
52
+ const app = await entraApp.getAppRegistrationByAppName(appName, ["id"]);
53
+ return app.id;
71
54
  }
72
55
  }
73
56
  async getAppRegPermissions(appObjectId, permissionType, logger) {
@@ -10,7 +10,7 @@ import commands from "../../commands.js";
10
10
  import request from "../../../../request.js";
11
11
  import { validation } from "../../../../utils/validation.js";
12
12
  import { cli } from "../../../../cli/cli.js";
13
- import { formatting } from "../../../../utils/formatting.js";
13
+ import { entraApp } from "../../../../utils/entraApp.js";
14
14
  var ScopeType;
15
15
  (function (ScopeType) {
16
16
  ScopeType["Role"] = "Role";
@@ -38,41 +38,41 @@ class EntraAppPermissionRemoveCommand extends GraphCommand {
38
38
  if (this.verbose) {
39
39
  await logger.logToStderr(`Removing permissions from application ${args.options.appId || args.options.appObjectId || args.options.appName}...`);
40
40
  }
41
- const appObject = await this.getAppObject(args.options);
41
+ const entraApp = await this.getEntraApp(args.options, logger);
42
42
  const servicePrincipals = await odata.getAllItems(`${this.resource}/v1.0/servicePrincipals?$select=appId,appRoles,id,oauth2PermissionScopes,servicePrincipalNames`);
43
43
  const appPermissions = [];
44
44
  if (args.options.delegatedPermissions) {
45
45
  const delegatedPermissions = await this.getRequiredResourceAccessForApis(servicePrincipals, args.options.delegatedPermissions, ScopeType.Scope, appPermissions, logger);
46
- this.removePermissionsFromResourceArray(delegatedPermissions, appObject.requiredResourceAccess);
46
+ this.removePermissionsFromResourceArray(delegatedPermissions, entraApp.requiredResourceAccess);
47
47
  }
48
48
  if (args.options.applicationPermissions) {
49
49
  const applicationPermissions = await this.getRequiredResourceAccessForApis(servicePrincipals, args.options.applicationPermissions, ScopeType.Role, appPermissions, logger);
50
- this.removePermissionsFromResourceArray(applicationPermissions, appObject.requiredResourceAccess);
50
+ this.removePermissionsFromResourceArray(applicationPermissions, entraApp.requiredResourceAccess);
51
51
  }
52
- for (let i = 0; i < appObject.requiredResourceAccess.length; i++) {
53
- if (appObject.requiredResourceAccess[i].resourceAccess?.length === 0) {
54
- appObject.requiredResourceAccess.splice(i, 1);
52
+ for (let i = 0; i < entraApp.requiredResourceAccess.length; i++) {
53
+ if (entraApp.requiredResourceAccess[i].resourceAccess?.length === 0) {
54
+ entraApp.requiredResourceAccess.splice(i, 1);
55
55
  }
56
56
  }
57
57
  const removePermissionRequestOptions = {
58
- url: `${this.resource}/v1.0/applications/${appObject.id}`,
58
+ url: `${this.resource}/v1.0/applications/${entraApp.id}`,
59
59
  headers: {
60
60
  accept: 'application/json;odata.metadata=none'
61
61
  },
62
62
  responseType: 'json',
63
63
  data: {
64
- requiredResourceAccess: appObject.requiredResourceAccess
64
+ requiredResourceAccess: entraApp.requiredResourceAccess
65
65
  }
66
66
  };
67
67
  await request.patch(removePermissionRequestOptions);
68
68
  if (args.options.revokeAdminConsent) {
69
- const appServicePrincipal = servicePrincipals.find(sp => sp.appId === appObject.appId);
69
+ const appServicePrincipal = servicePrincipals.find(sp => sp.appId === entraApp.appId);
70
70
  if (appServicePrincipal) {
71
71
  await this.revokeAdminConsent(appServicePrincipal, appPermissions, logger);
72
72
  }
73
73
  else {
74
74
  if (this.debug) {
75
- await logger.logToStderr(`No service principal found for the appId: ${appObject.appId}. Skipping revoking admin consent.`);
75
+ await logger.logToStderr(`No service principal found for the appId: ${entraApp.appId}. Skipping revoking admin consent.`);
76
76
  }
77
77
  }
78
78
  }
@@ -91,29 +91,20 @@ class EntraAppPermissionRemoveCommand extends GraphCommand {
91
91
  }
92
92
  }
93
93
  }
94
- async getAppObject(options) {
95
- const selectProperties = '$select=id,appId,requiredResourceAccess';
96
- if (options.appObjectId) {
97
- const requestOptions = {
98
- url: `${this.resource}/v1.0/applications/${options.appObjectId}?${selectProperties}`,
99
- headers: {
100
- 'content-type': 'application/json;odata.metadata=none'
101
- },
102
- responseType: 'json'
103
- };
104
- return request.get(requestOptions);
94
+ async getEntraApp(options, logger) {
95
+ const { appObjectId, appId, appName } = options;
96
+ if (this.verbose) {
97
+ await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appObjectId ? appObjectId : (appId ? appId : appName)}...`);
98
+ }
99
+ if (appObjectId) {
100
+ return await entraApp.getAppRegistrationByObjectId(appObjectId, ['id', 'appId', 'requiredResourceAccess']);
105
101
  }
106
- const apps = options.appId
107
- ? await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=appId eq '${options.appId}'&${selectProperties}`)
108
- : await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=displayName eq '${options.appName}'&${selectProperties}`);
109
- if (apps.length === 0) {
110
- throw `App with ${options.appId ? 'id' : 'name'} ${options.appId || options.appName} not found in Microsoft Entra ID`;
102
+ else if (appId) {
103
+ return await entraApp.getAppRegistrationByAppId(appId, ['id', 'appId', 'requiredResourceAccess']);
111
104
  }
112
- if (apps.length > 1) {
113
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', apps);
114
- return cli.handleMultipleResultsFound(`Multiple apps with name '${options.appName}' found.`, resultAsKeyValuePair);
105
+ else {
106
+ return await entraApp.getAppRegistrationByAppName(appName, ['id', 'appId', 'requiredResourceAccess']);
115
107
  }
116
- return apps[0];
117
108
  }
118
109
  async revokeAdminConsent(servicePrincipal, appPermissions, logger) {
119
110
  // Check if contains app permissions
@@ -7,7 +7,6 @@ var _EntraAppRemoveCommand_instances, _EntraAppRemoveCommand_initTelemetry, _Ent
7
7
  import { cli } from '../../../../cli/cli.js';
8
8
  import request from '../../../../request.js';
9
9
  import { entraApp } from '../../../../utils/entraApp.js';
10
- import { formatting } from '../../../../utils/formatting.js';
11
10
  import { validation } from '../../../../utils/validation.js';
12
11
  import GraphCommand from '../../../base/GraphCommand.js';
13
12
  import commands from '../../commands.js';
@@ -69,23 +68,8 @@ class EntraAppRemoveCommand extends GraphCommand {
69
68
  return app.id;
70
69
  }
71
70
  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;
71
+ const app = await entraApp.getAppRegistrationByAppName(name, ['id']);
72
+ return app.id;
89
73
  }
90
74
  }
91
75
  }
@@ -6,10 +6,8 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
6
6
  var _EntraAppRoleAddCommand_instances, _a, _EntraAppRoleAddCommand_initTelemetry, _EntraAppRoleAddCommand_initOptions, _EntraAppRoleAddCommand_initValidators, _EntraAppRoleAddCommand_initOptionSets;
7
7
  import { v4 } from 'uuid';
8
8
  import request from '../../../../request.js';
9
- import { formatting } from '../../../../utils/formatting.js';
10
9
  import GraphCommand from '../../../base/GraphCommand.js';
11
10
  import commands from '../../commands.js';
12
- import { cli } from '../../../../cli/cli.js';
13
11
  import { entraApp } from '../../../../utils/entraApp.js';
14
12
  class EntraAppRoleAddCommand extends GraphCommand {
15
13
  get name() {
@@ -28,8 +26,7 @@ class EntraAppRoleAddCommand extends GraphCommand {
28
26
  }
29
27
  async commandAction(logger, args) {
30
28
  try {
31
- const appId = await this.getAppObjectId(args, logger);
32
- const appInfo = await this.getAppInfo(appId, logger);
29
+ const appInfo = await this.getAppInfo(args, logger);
33
30
  if (this.verbose) {
34
31
  await logger.logToStderr(`Adding role ${args.options.name} to Microsoft Entra app ${appInfo.id}...`);
35
32
  }
@@ -55,19 +52,6 @@ class EntraAppRoleAddCommand extends GraphCommand {
55
52
  this.handleRejectedODataJsonPromise(err);
56
53
  }
57
54
  }
58
- async getAppInfo(appId, logger) {
59
- if (this.verbose) {
60
- await logger.logToStderr(`Retrieving information about roles for Microsoft Entra app ${appId}...`);
61
- }
62
- const requestOptions = {
63
- url: `${this.resource}/v1.0/myorganization/applications/${appId}?$select=id,appRoles`,
64
- headers: {
65
- accept: 'application/json;odata.metadata=none'
66
- },
67
- responseType: 'json'
68
- };
69
- return request.get(requestOptions);
70
- }
71
55
  getAllowedMemberTypes(args) {
72
56
  switch (args.options.allowedMembers) {
73
57
  case 'usersGroups':
@@ -80,36 +64,19 @@ class EntraAppRoleAddCommand extends GraphCommand {
80
64
  return [];
81
65
  }
82
66
  }
83
- async getAppObjectId(args, logger) {
84
- if (args.options.appObjectId) {
85
- return args.options.appObjectId;
86
- }
87
- const { appId, appName } = args.options;
67
+ async getAppInfo(args, logger) {
68
+ const { appObjectId, appId, appName } = args.options;
88
69
  if (this.verbose) {
89
- await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appId ? appId : appName}...`);
70
+ await logger.logToStderr(`Retrieving information about Microsoft Entra app ${appObjectId ? appObjectId : (appId ? appId : appName)}...`);
71
+ }
72
+ if (appObjectId) {
73
+ return await entraApp.getAppRegistrationByObjectId(appObjectId, ['id', 'appRoles']);
90
74
  }
91
- if (appId) {
92
- const app = await entraApp.getAppRegistrationByAppId(appId, ['id']);
93
- return app.id;
75
+ else if (appId) {
76
+ return await entraApp.getAppRegistrationByAppId(appId, ['id', 'appRoles']);
94
77
  }
95
78
  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;
79
+ return await entraApp.getAppRegistrationByAppName(appName, ['id', 'appRoles']);
113
80
  }
114
81
  }
115
82
  }
@@ -4,12 +4,9 @@ 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 _EntraAppRoleListCommand_instances, _EntraAppRoleListCommand_initTelemetry, _EntraAppRoleListCommand_initOptions, _EntraAppRoleListCommand_initOptionSets;
7
- import request from '../../../../request.js';
8
- import { formatting } from '../../../../utils/formatting.js';
9
7
  import { odata } from '../../../../utils/odata.js';
10
8
  import GraphCommand from '../../../base/GraphCommand.js';
11
9
  import commands from '../../commands.js';
12
- import { cli } from '../../../../cli/cli.js';
13
10
  import { entraApp } from '../../../../utils/entraApp.js';
14
11
  class EntraAppRoleListCommand extends GraphCommand {
15
12
  get name() {
@@ -51,23 +48,8 @@ class EntraAppRoleListCommand extends GraphCommand {
51
48
  return app.id;
52
49
  }
53
50
  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;
51
+ const app = await entraApp.getAppRegistrationByAppName(appName, ["id"]);
52
+ return app.id;
71
53
  }
72
54
  }
73
55
  }