@pnp/cli-microsoft365 7.1.0-beta.d53f0d9 → 7.2.0-beta.194fd07

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 (33) hide show
  1. package/.eslintrc.cjs +2 -0
  2. package/dist/Auth.js +1 -1
  3. package/dist/Command.js +18 -28
  4. package/dist/cli/Cli.js +6 -4
  5. package/dist/m365/aad/commands/administrativeunit/administrativeunit-add.js +61 -0
  6. package/dist/m365/aad/commands/administrativeunit/administrativeunit-get.js +93 -0
  7. package/dist/m365/aad/commands/administrativeunit/administrativeunit-list.js +25 -0
  8. package/dist/m365/aad/commands/administrativeunit/administrativeunit-remove.js +108 -0
  9. package/dist/m365/aad/commands/group/group-user-list.js +146 -0
  10. package/dist/m365/aad/commands/m365group/m365group-remove.js +109 -15
  11. package/dist/m365/aad/commands.js +5 -0
  12. package/dist/m365/base/AppCommand.js +3 -12
  13. package/dist/m365/cli/commands/cli-doctor.js +11 -6
  14. package/dist/m365/commands/setup.js +6 -1
  15. package/dist/m365/spo/commands/sitedesign/sitedesign-get.js +15 -14
  16. package/dist/m365/spo/commands/sitedesign/sitedesign-remove.js +22 -22
  17. package/dist/m365/teams/commands/app/app-update.js +9 -6
  18. package/dist/m365/todo/commands/task/task-list.js +8 -10
  19. package/dist/m365/todo/commands/task/task-remove.js +36 -36
  20. package/dist/m365/todo/commands/task/task-set.js +11 -13
  21. package/dist/m365/yammer/commands/group/group-user-remove.js +22 -23
  22. package/dist/utils/aadGroup.js +3 -1
  23. package/dist/utils/odata.js +20 -19
  24. package/dist/utils/prompt.js +16 -0
  25. package/docs/docs/cmd/aad/administrativeunit/administrativeunit-add.mdx +115 -0
  26. package/docs/docs/cmd/aad/administrativeunit/administrativeunit-get.mdx +98 -0
  27. package/docs/docs/cmd/aad/administrativeunit/administrativeunit-list.mdx +83 -0
  28. package/docs/docs/cmd/aad/administrativeunit/administrativeunit-remove.mdx +52 -0
  29. package/docs/docs/cmd/aad/group/group-user-list.mdx +135 -0
  30. package/docs/docs/cmd/aad/m365group/m365group-remove.mdx +11 -1
  31. package/docs/docs/cmd/spo/field/field-get.mdx +1 -1
  32. package/npm-shrinkwrap.json +2 -2
  33. package/package.json +33 -13
package/.eslintrc.cjs CHANGED
@@ -5,6 +5,7 @@ const dictionary = [
5
5
  'activation',
6
6
  'activations',
7
7
  'adaptive',
8
+ 'administrative',
8
9
  'ai',
9
10
  'app',
10
11
  'application',
@@ -90,6 +91,7 @@ const dictionary = [
90
91
  'threat',
91
92
  'token',
92
93
  'type',
94
+ 'unit',
93
95
  'user',
94
96
  'web',
95
97
  'webhook'
package/dist/Auth.js CHANGED
@@ -289,7 +289,7 @@ export class Auth {
289
289
  // but also stub it for testing
290
290
  /* c8 ignore next 3 */
291
291
  if (!this._authServer) {
292
- this._authServer = (await import('./AuthServer')).default;
292
+ this._authServer = (await import('./AuthServer.js')).default;
293
293
  }
294
294
  this._authServer.initializeServer(this.service, resource, resolve, reject, logger, debug);
295
295
  });
package/dist/Command.js CHANGED
@@ -12,6 +12,7 @@ import { settingsNames } from './settingsNames.js';
12
12
  import { telemetry } from './telemetry.js';
13
13
  import { accessToken } from './utils/accessToken.js';
14
14
  import { md } from './utils/md.js';
15
+ import { prompt } from './utils/prompt.js';
15
16
  export class CommandError {
16
17
  constructor(message, code) {
17
18
  this.message = message;
@@ -75,7 +76,6 @@ class Command {
75
76
  }
76
77
  async validateRequiredOptions(args, command) {
77
78
  const shouldPrompt = Cli.getInstance().getSettingWithDefaultValue(settingsNames.prompt, true);
78
- let inquirer;
79
79
  let prompted = false;
80
80
  for (let i = 0; i < command.options.length; i++) {
81
81
  if (!command.options[i].required ||
@@ -87,19 +87,17 @@ class Command {
87
87
  }
88
88
  if (!prompted) {
89
89
  prompted = true;
90
- Cli.log('Provide values for the following parameters:');
90
+ Cli.error('🌶️ Provide values for the following parameters:');
91
91
  }
92
- if (!inquirer) {
93
- inquirer = await import('inquirer');
94
- }
95
- const missingRequireOptionValue = await inquirer.default
96
- .prompt({
92
+ const missingRequireOptionValue = await prompt.forInput({
97
93
  name: 'missingRequireOptionValue',
98
94
  message: `${command.options[i].name}: `
99
- })
100
- .then(result => result.missingRequireOptionValue);
95
+ }).then(result => result.missingRequireOptionValue);
101
96
  args.options[command.options[i].name] = missingRequireOptionValue;
102
97
  }
98
+ if (prompted) {
99
+ Cli.error('');
100
+ }
103
101
  this.processOptions(args.options);
104
102
  return true;
105
103
  }
@@ -108,7 +106,6 @@ class Command {
108
106
  if (!optionsSets || optionsSets.length === 0) {
109
107
  return true;
110
108
  }
111
- let inquirer;
112
109
  const shouldPrompt = Cli.getInstance().getSettingWithDefaultValue(settingsNames.prompt, true);
113
110
  const argsOptions = Object.keys(args.options);
114
111
  for (const optionSet of optionsSets.sort(opt => opt.runsWhen ? 0 : 1)) {
@@ -120,50 +117,43 @@ class Command {
120
117
  if (!shouldPrompt) {
121
118
  return `Specify one of the following options: ${optionSet.options.join(', ')}.`;
122
119
  }
123
- await this.promptForOptionSetNameAndValue(args, optionSet, inquirer);
120
+ await this.promptForOptionSetNameAndValue(args, optionSet);
124
121
  }
125
122
  if (commonOptions.length > 1) {
126
123
  if (!shouldPrompt) {
127
124
  return `Specify one of the following options: ${optionSet.options.join(', ')}, but not multiple.`;
128
125
  }
129
- await this.promptForSpecificOption(args, commonOptions, inquirer);
126
+ await this.promptForSpecificOption(args, commonOptions);
130
127
  }
131
128
  }
132
129
  return true;
133
130
  }
134
- async promptForOptionSetNameAndValue(args, optionSet, inquirer) {
135
- if (!inquirer) {
136
- inquirer = await import('inquirer');
137
- }
138
- Cli.log(`Please specify one of the following options:`);
139
- const resultOptionName = await inquirer.default.prompt({
131
+ async promptForOptionSetNameAndValue(args, optionSet) {
132
+ Cli.error(`🌶️ Please specify one of the following options:`);
133
+ const resultOptionName = await prompt.forInput({
140
134
  type: 'list',
141
135
  name: 'missingRequiredOptionName',
142
136
  message: `Option to use:`,
143
137
  choices: optionSet.options
144
138
  });
145
139
  const missingRequiredOptionName = resultOptionName.missingRequiredOptionName;
146
- const resultOptionValue = await inquirer.default
147
- .prompt({
140
+ const resultOptionValue = await prompt.forInput({
148
141
  name: 'missingRequiredOptionValue',
149
142
  message: `${missingRequiredOptionName}:`
150
143
  });
151
144
  args.options[missingRequiredOptionName] = resultOptionValue.missingRequiredOptionValue;
152
- Cli.log();
145
+ Cli.error('');
153
146
  }
154
- async promptForSpecificOption(args, commonOptions, inquirer) {
155
- if (!inquirer) {
156
- inquirer = await import('inquirer');
157
- }
158
- Cli.log(`Multiple options for an option set specified. Please specify the correct option that you wish to use.`);
159
- const requiredOptionNameResult = await inquirer.default.prompt({
147
+ async promptForSpecificOption(args, commonOptions) {
148
+ Cli.error(`🌶️ Multiple options for an option set specified. Please specify the correct option that you wish to use.`);
149
+ const requiredOptionNameResult = await prompt.forInput({
160
150
  type: 'list',
161
151
  name: 'missingRequiredOptionName',
162
152
  message: `Option to use:`,
163
153
  choices: commonOptions
164
154
  });
165
155
  commonOptions.filter(y => y !== requiredOptionNameResult.missingRequiredOptionName).map(optionName => args.options[optionName] = undefined);
166
- Cli.log();
156
+ Cli.error('');
167
157
  }
168
158
  async validateOutput(args) {
169
159
  if (args.options.output &&
package/dist/cli/Cli.js CHANGED
@@ -15,6 +15,7 @@ import { formatting } from '../utils/formatting.js';
15
15
  import { fsUtil } from '../utils/fsUtil.js';
16
16
  import { md } from '../utils/md.js';
17
17
  import { validation } from '../utils/validation.js';
18
+ import { prompt } from '../utils/prompt.js';
18
19
  export class Cli {
19
20
  get config() {
20
21
  if (!this._config) {
@@ -706,9 +707,10 @@ export class Cli {
706
707
  const maxLength = Math.max(...namesOfCommandsToPrint.map(s => s.length)) + 10;
707
708
  Cli.log(`Commands:`);
708
709
  Cli.log();
709
- for (const commandName in commandsToPrint) {
710
+ const sortedCommandNamesToPrint = Object.getOwnPropertyNames(commandsToPrint).sort();
711
+ sortedCommandNamesToPrint.forEach(commandName => {
710
712
  Cli.log(` ${`${commandName} [options]`.padEnd(maxLength, ' ')} ${commandsToPrint[commandName].command.description}`);
711
- }
713
+ });
712
714
  }
713
715
  const namesOfCommandGroupsToPrint = Object.keys(commandGroupsToPrint);
714
716
  if (namesOfCommandGroupsToPrint.length > 0) {
@@ -803,14 +805,13 @@ export class Cli {
803
805
  }
804
806
  }
805
807
  static async prompt(options, answers) {
806
- const inquirer = await import('inquirer');
807
808
  const cli = Cli.getInstance();
808
809
  const spinnerSpinning = cli.spinner.isSpinning;
809
810
  /* c8 ignore next 3 */
810
811
  if (spinnerSpinning) {
811
812
  cli.spinner.stop();
812
813
  }
813
- const response = await inquirer.default.prompt(options, answers);
814
+ const response = await prompt.forInput(options, answers);
814
815
  // Restart the spinner if it was running before the prompt
815
816
  /* c8 ignore next 3 */
816
817
  if (spinnerSpinning) {
@@ -827,6 +828,7 @@ export class Cli {
827
828
  type: 'list',
828
829
  name: 'select',
829
830
  default: 0,
831
+ prefix: '🌶️ ',
830
832
  message: `${message} Please choose one:`,
831
833
  choices: Object.keys(values)
832
834
  });
@@ -0,0 +1,61 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _AadAdministrativeUnitAddCommand_instances, _AadAdministrativeUnitAddCommand_initTelemetry, _AadAdministrativeUnitAddCommand_initOptions;
7
+ import request from "../../../../request.js";
8
+ import GraphCommand from "../../../base/GraphCommand.js";
9
+ import commands from "../../commands.js";
10
+ class AadAdministrativeUnitAddCommand extends GraphCommand {
11
+ get name() {
12
+ return commands.ADMINISTRATIVEUNIT_ADD;
13
+ }
14
+ get description() {
15
+ return 'Creates an administrative unit';
16
+ }
17
+ constructor() {
18
+ super();
19
+ _AadAdministrativeUnitAddCommand_instances.add(this);
20
+ __classPrivateFieldGet(this, _AadAdministrativeUnitAddCommand_instances, "m", _AadAdministrativeUnitAddCommand_initTelemetry).call(this);
21
+ __classPrivateFieldGet(this, _AadAdministrativeUnitAddCommand_instances, "m", _AadAdministrativeUnitAddCommand_initOptions).call(this);
22
+ }
23
+ async commandAction(logger, args) {
24
+ const requestOptions = {
25
+ url: `${this.resource}/v1.0/directory/administrativeUnits`,
26
+ headers: {
27
+ 'accept': 'application/json;odata.metadata=none'
28
+ },
29
+ responseType: 'json',
30
+ data: {
31
+ description: args.options.description,
32
+ displayName: args.options.displayName,
33
+ visibility: args.options.hiddenMembership ? 'HiddenMembership' : null
34
+ }
35
+ };
36
+ try {
37
+ const administrativeUnit = await request.post(requestOptions);
38
+ await logger.log(administrativeUnit);
39
+ }
40
+ catch (err) {
41
+ this.handleRejectedODataJsonPromise(err);
42
+ }
43
+ }
44
+ }
45
+ _AadAdministrativeUnitAddCommand_instances = new WeakSet(), _AadAdministrativeUnitAddCommand_initTelemetry = function _AadAdministrativeUnitAddCommand_initTelemetry() {
46
+ this.telemetry.push((args) => {
47
+ Object.assign(this.telemetryProperties, {
48
+ hiddenMembership: args.options.hiddenMembership
49
+ });
50
+ });
51
+ }, _AadAdministrativeUnitAddCommand_initOptions = function _AadAdministrativeUnitAddCommand_initOptions() {
52
+ this.options.unshift({
53
+ option: '-n, --displayName <displayName>'
54
+ }, {
55
+ option: '-d, --description [description]'
56
+ }, {
57
+ option: '--hiddenMembership [hiddenMembership]'
58
+ });
59
+ };
60
+ export default new AadAdministrativeUnitAddCommand();
61
+ //# sourceMappingURL=administrativeunit-add.js.map
@@ -0,0 +1,93 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _AadAdministrativeUnitGetCommand_instances, _AadAdministrativeUnitGetCommand_initTelemetry, _AadAdministrativeUnitGetCommand_initOptions, _AadAdministrativeUnitGetCommand_initValidators, _AadAdministrativeUnitGetCommand_initOptionSets, _AadAdministrativeUnitGetCommand_initTypes;
7
+ import { validation } from "../../../../utils/validation.js";
8
+ import request from "../../../../request.js";
9
+ import GraphCommand from "../../../base/GraphCommand.js";
10
+ import commands from "../../commands.js";
11
+ import { odata } from "../../../../utils/odata.js";
12
+ import { formatting } from "../../../../utils/formatting.js";
13
+ import { Cli } from "../../../../cli/Cli.js";
14
+ class AadAdministrativeUnitGetCommand extends GraphCommand {
15
+ get name() {
16
+ return commands.ADMINISTRATIVEUNIT_GET;
17
+ }
18
+ get description() {
19
+ return 'Gets information about a specific administrative unit';
20
+ }
21
+ constructor() {
22
+ super();
23
+ _AadAdministrativeUnitGetCommand_instances.add(this);
24
+ __classPrivateFieldGet(this, _AadAdministrativeUnitGetCommand_instances, "m", _AadAdministrativeUnitGetCommand_initTelemetry).call(this);
25
+ __classPrivateFieldGet(this, _AadAdministrativeUnitGetCommand_instances, "m", _AadAdministrativeUnitGetCommand_initOptions).call(this);
26
+ __classPrivateFieldGet(this, _AadAdministrativeUnitGetCommand_instances, "m", _AadAdministrativeUnitGetCommand_initValidators).call(this);
27
+ __classPrivateFieldGet(this, _AadAdministrativeUnitGetCommand_instances, "m", _AadAdministrativeUnitGetCommand_initOptionSets).call(this);
28
+ __classPrivateFieldGet(this, _AadAdministrativeUnitGetCommand_instances, "m", _AadAdministrativeUnitGetCommand_initTypes).call(this);
29
+ }
30
+ async commandAction(logger, args) {
31
+ let administrativeUnit;
32
+ try {
33
+ if (args.options.id) {
34
+ administrativeUnit = await this.getAdministrativeUnitById(args.options.id);
35
+ }
36
+ else {
37
+ administrativeUnit = await this.getAdministrativeUnitByDisplayName(args.options.displayName);
38
+ }
39
+ await logger.log(administrativeUnit);
40
+ }
41
+ catch (err) {
42
+ this.handleRejectedODataJsonPromise(err);
43
+ }
44
+ }
45
+ async getAdministrativeUnitById(id) {
46
+ const requestOptions = {
47
+ url: `${this.resource}/v1.0/directory/administrativeUnits/${id}`,
48
+ headers: {
49
+ accept: 'application/json;odata.metadata=none'
50
+ },
51
+ responseType: 'json'
52
+ };
53
+ return await request.get(requestOptions);
54
+ }
55
+ async getAdministrativeUnitByDisplayName(displayName) {
56
+ const administrativeUnits = await odata.getAllItems(`${this.resource}/v1.0/directory/administrativeUnits?$filter=displayName eq '${formatting.encodeQueryParameter(displayName)}'`);
57
+ if (administrativeUnits.length === 0) {
58
+ throw `The specified administrative unit '${displayName}' does not exist.`;
59
+ }
60
+ if (administrativeUnits.length > 1) {
61
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', administrativeUnits);
62
+ return await Cli.handleMultipleResultsFound(`Multiple administrative units with name '${displayName}' found.`, resultAsKeyValuePair);
63
+ }
64
+ return administrativeUnits[0];
65
+ }
66
+ }
67
+ _AadAdministrativeUnitGetCommand_instances = new WeakSet(), _AadAdministrativeUnitGetCommand_initTelemetry = function _AadAdministrativeUnitGetCommand_initTelemetry() {
68
+ this.telemetry.push((args) => {
69
+ Object.assign(this.telemetryProperties, {
70
+ id: typeof args.options.id !== 'undefined',
71
+ displayName: typeof args.options.displayName !== 'undefined'
72
+ });
73
+ });
74
+ }, _AadAdministrativeUnitGetCommand_initOptions = function _AadAdministrativeUnitGetCommand_initOptions() {
75
+ this.options.unshift({
76
+ option: '-i, --id [id]'
77
+ }, {
78
+ option: '-n, --displayName [displayName]'
79
+ });
80
+ }, _AadAdministrativeUnitGetCommand_initValidators = function _AadAdministrativeUnitGetCommand_initValidators() {
81
+ this.validators.push(async (args) => {
82
+ if (args.options.id && !validation.isValidGuid(args.options.id)) {
83
+ return `${args.options.id} is not a valid GUID`;
84
+ }
85
+ return true;
86
+ });
87
+ }, _AadAdministrativeUnitGetCommand_initOptionSets = function _AadAdministrativeUnitGetCommand_initOptionSets() {
88
+ this.optionSets.push({ options: ['id', 'displayName'] });
89
+ }, _AadAdministrativeUnitGetCommand_initTypes = function _AadAdministrativeUnitGetCommand_initTypes() {
90
+ this.types.string.push('displayName');
91
+ };
92
+ export default new AadAdministrativeUnitGetCommand();
93
+ //# sourceMappingURL=administrativeunit-get.js.map
@@ -0,0 +1,25 @@
1
+ import { odata } from '../../../../utils/odata.js';
2
+ import GraphCommand from '../../../base/GraphCommand.js';
3
+ import commands from '../../commands.js';
4
+ class AadAdministrativeUnitListCommand extends GraphCommand {
5
+ get name() {
6
+ return commands.ADMINISTRATIVEUNIT_LIST;
7
+ }
8
+ get description() {
9
+ return 'Retrieves a list of administrative units';
10
+ }
11
+ defaultProperties() {
12
+ return ['id', 'displayName', 'visibility'];
13
+ }
14
+ async commandAction(logger) {
15
+ try {
16
+ const results = await odata.getAllItems(`${this.resource}/v1.0/directory/administrativeUnits`);
17
+ await logger.log(results);
18
+ }
19
+ catch (err) {
20
+ this.handleRejectedODataJsonPromise(err);
21
+ }
22
+ }
23
+ }
24
+ export default new AadAdministrativeUnitListCommand();
25
+ //# sourceMappingURL=administrativeunit-list.js.map
@@ -0,0 +1,108 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _AadAdministrativeUnitRemoveCommand_instances, _AadAdministrativeUnitRemoveCommand_initTelemetry, _AadAdministrativeUnitRemoveCommand_initOptions, _AadAdministrativeUnitRemoveCommand_initOptionSets, _AadAdministrativeUnitRemoveCommand_initValidators, _AadAdministrativeUnitRemoveCommand_initTypes;
7
+ import { validation } from "../../../../utils/validation.js";
8
+ import request from "../../../../request.js";
9
+ import GraphCommand from "../../../base/GraphCommand.js";
10
+ import commands from "../../commands.js";
11
+ import { odata } from "../../../../utils/odata.js";
12
+ import { formatting } from "../../../../utils/formatting.js";
13
+ import { Cli } from "../../../../cli/Cli.js";
14
+ class AadAdministrativeUnitRemoveCommand extends GraphCommand {
15
+ get name() {
16
+ return commands.ADMINISTRATIVEUNIT_REMOVE;
17
+ }
18
+ get description() {
19
+ return 'Removes an administrative unit';
20
+ }
21
+ constructor() {
22
+ super();
23
+ _AadAdministrativeUnitRemoveCommand_instances.add(this);
24
+ __classPrivateFieldGet(this, _AadAdministrativeUnitRemoveCommand_instances, "m", _AadAdministrativeUnitRemoveCommand_initOptions).call(this);
25
+ __classPrivateFieldGet(this, _AadAdministrativeUnitRemoveCommand_instances, "m", _AadAdministrativeUnitRemoveCommand_initValidators).call(this);
26
+ __classPrivateFieldGet(this, _AadAdministrativeUnitRemoveCommand_instances, "m", _AadAdministrativeUnitRemoveCommand_initOptionSets).call(this);
27
+ __classPrivateFieldGet(this, _AadAdministrativeUnitRemoveCommand_instances, "m", _AadAdministrativeUnitRemoveCommand_initTelemetry).call(this);
28
+ __classPrivateFieldGet(this, _AadAdministrativeUnitRemoveCommand_instances, "m", _AadAdministrativeUnitRemoveCommand_initTypes).call(this);
29
+ }
30
+ async commandAction(logger, args) {
31
+ const removeAdministrativeUnit = async () => {
32
+ try {
33
+ let administrativeUnitId = args.options.id;
34
+ if (args.options.displayName) {
35
+ administrativeUnitId = await this.getAdministrativeUnitIdByDisplayName(args.options.displayName);
36
+ }
37
+ const requestOptions = {
38
+ url: `${this.resource}/v1.0/directory/administrativeUnits/${administrativeUnitId}`,
39
+ headers: {
40
+ accept: 'application/json;odata.metadata=none'
41
+ }
42
+ };
43
+ await request.delete(requestOptions);
44
+ }
45
+ catch (err) {
46
+ this.handleRejectedODataJsonPromise(err);
47
+ }
48
+ };
49
+ if (args.options.force) {
50
+ await removeAdministrativeUnit();
51
+ }
52
+ else {
53
+ const result = await Cli.prompt({
54
+ type: 'confirm',
55
+ name: 'continue',
56
+ default: false,
57
+ message: `Are you sure you want to remove administrative unit '${args.options.id || args.options.displayName}'?`
58
+ });
59
+ if (result.continue) {
60
+ await removeAdministrativeUnit();
61
+ }
62
+ }
63
+ }
64
+ async getAdministrativeUnitIdByDisplayName(displayName) {
65
+ const administrativeUnits = await odata.getAllItems(`${this.resource}/v1.0/directory/administrativeUnits?$filter=displayName eq '${formatting.encodeQueryParameter(displayName)}'&$select=id`);
66
+ if (administrativeUnits.length === 0) {
67
+ throw `The specified administrative unit '${displayName}' does not exist.`;
68
+ }
69
+ if (administrativeUnits.length > 1) {
70
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', administrativeUnits);
71
+ const selectedAdministrativeUnit = await Cli.handleMultipleResultsFound(`Multiple administrative units with name '${displayName}' found.`, resultAsKeyValuePair);
72
+ return selectedAdministrativeUnit.id;
73
+ }
74
+ return administrativeUnits[0].id;
75
+ }
76
+ }
77
+ _AadAdministrativeUnitRemoveCommand_instances = new WeakSet(), _AadAdministrativeUnitRemoveCommand_initTelemetry = function _AadAdministrativeUnitRemoveCommand_initTelemetry() {
78
+ this.telemetry.push((args) => {
79
+ Object.assign(this.telemetryProperties, {
80
+ id: args.options.id !== 'undefined',
81
+ displayName: args.options.displayName !== 'undefined',
82
+ force: !!args.options.force
83
+ });
84
+ });
85
+ }, _AadAdministrativeUnitRemoveCommand_initOptions = function _AadAdministrativeUnitRemoveCommand_initOptions() {
86
+ this.options.unshift({
87
+ option: '-i, --id [id]'
88
+ }, {
89
+ option: '-n, --displayName [displayName]'
90
+ }, {
91
+ option: '-f, --force'
92
+ });
93
+ }, _AadAdministrativeUnitRemoveCommand_initOptionSets = function _AadAdministrativeUnitRemoveCommand_initOptionSets() {
94
+ this.optionSets.push({
95
+ options: ['id', 'displayName']
96
+ });
97
+ }, _AadAdministrativeUnitRemoveCommand_initValidators = function _AadAdministrativeUnitRemoveCommand_initValidators() {
98
+ this.validators.push(async (args) => {
99
+ if (args.options.id && !validation.isValidGuid(args.options.id)) {
100
+ return `${args.options.id} is not a valid GUID for option id.`;
101
+ }
102
+ return true;
103
+ });
104
+ }, _AadAdministrativeUnitRemoveCommand_initTypes = function _AadAdministrativeUnitRemoveCommand_initTypes() {
105
+ this.types.string.push('id', 'displayName');
106
+ };
107
+ export default new AadAdministrativeUnitRemoveCommand();
108
+ //# sourceMappingURL=administrativeunit-remove.js.map
@@ -0,0 +1,146 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _AadGroupUserListCommand_instances, _AadGroupUserListCommand_initTelemetry, _AadGroupUserListCommand_initOptions, _AadGroupUserListCommand_initOptionSets, _AadGroupUserListCommand_initValidators;
7
+ import { aadGroup } from '../../../../utils/aadGroup.js';
8
+ import { odata } from '../../../../utils/odata.js';
9
+ import { validation } from '../../../../utils/validation.js';
10
+ import GraphCommand from '../../../base/GraphCommand.js';
11
+ import commands from '../../commands.js';
12
+ class AadGroupUserListCommand extends GraphCommand {
13
+ get name() {
14
+ return commands.GROUP_USER_LIST;
15
+ }
16
+ get description() {
17
+ return 'Lists users of a specific Azure AD group';
18
+ }
19
+ defaultProperties() {
20
+ return ['id', 'displayName', 'userPrincipalName', 'roles'];
21
+ }
22
+ constructor() {
23
+ super();
24
+ _AadGroupUserListCommand_instances.add(this);
25
+ __classPrivateFieldGet(this, _AadGroupUserListCommand_instances, "m", _AadGroupUserListCommand_initTelemetry).call(this);
26
+ __classPrivateFieldGet(this, _AadGroupUserListCommand_instances, "m", _AadGroupUserListCommand_initOptions).call(this);
27
+ __classPrivateFieldGet(this, _AadGroupUserListCommand_instances, "m", _AadGroupUserListCommand_initOptionSets).call(this);
28
+ __classPrivateFieldGet(this, _AadGroupUserListCommand_instances, "m", _AadGroupUserListCommand_initValidators).call(this);
29
+ }
30
+ async commandAction(logger, args) {
31
+ try {
32
+ const groupId = await this.getGroupId(args.options, logger);
33
+ const users = [];
34
+ if (!args.options.role || args.options.role === 'Owner') {
35
+ const owners = await this.getUsers(args.options, 'Owners', groupId, logger);
36
+ owners.forEach(owner => users.push({ ...owner, roles: ['Owner'] }));
37
+ }
38
+ if (!args.options.role || args.options.role === 'Member') {
39
+ const members = await this.getUsers(args.options, 'Members', groupId, logger);
40
+ members.forEach((member) => {
41
+ const user = users.find((u) => u.id === member.id);
42
+ if (user !== undefined) {
43
+ user.roles.push('Member');
44
+ }
45
+ else {
46
+ users.push({ ...member, roles: ['Member'] });
47
+ }
48
+ });
49
+ }
50
+ await logger.log(users);
51
+ }
52
+ catch (err) {
53
+ this.handleRejectedODataJsonPromise(err);
54
+ }
55
+ }
56
+ async getGroupId(options, logger) {
57
+ if (options.groupId) {
58
+ return options.groupId;
59
+ }
60
+ if (this.verbose) {
61
+ await logger.logToStderr('Retrieving Group Id...');
62
+ }
63
+ return await aadGroup.getGroupIdByDisplayName(options.groupDisplayName);
64
+ }
65
+ async getUsers(options, role, groupId, logger) {
66
+ const { properties, filter } = options;
67
+ if (this.verbose) {
68
+ await logger.logToStderr(`Retrieving ${role} of the group with id ${groupId}`);
69
+ }
70
+ const selectProperties = properties ?
71
+ `${properties.split(',').filter(f => f.toLowerCase() !== 'id').concat('id').map(p => p.trim()).join(',')}` :
72
+ 'id,displayName,userPrincipalName,givenName,surname';
73
+ const allSelectProperties = selectProperties.split(',');
74
+ const propertiesWithSlash = allSelectProperties.filter(item => item.includes('/'));
75
+ let fieldExpand = '';
76
+ propertiesWithSlash.forEach(p => {
77
+ if (fieldExpand.length > 0) {
78
+ fieldExpand += ',';
79
+ }
80
+ fieldExpand += `${p.split('/')[0]}($select=${p.split('/')[1]})`;
81
+ });
82
+ const expandParam = fieldExpand.length > 0 ? `&$expand=${fieldExpand}` : '';
83
+ const selectParam = allSelectProperties.filter(item => !item.includes('/'));
84
+ const endpoint = `${this.resource}/v1.0/groups/${groupId}/${role}/microsoft.graph.user?$select=${selectParam}${expandParam}`;
85
+ let users = [];
86
+ if (filter) {
87
+ // While using the filter, we need to specify the ConsistencyLevel header.
88
+ // Can be refactored when the header is no longer necessary.
89
+ const requestOptions = {
90
+ url: `${endpoint}&$filter=${encodeURIComponent(filter)}&$count=true`,
91
+ headers: {
92
+ accept: 'application/json;odata.metadata=none',
93
+ ConsistencyLevel: 'eventual'
94
+ },
95
+ responseType: 'json'
96
+ };
97
+ users = await odata.getAllItems(requestOptions);
98
+ }
99
+ else {
100
+ users = await odata.getAllItems(endpoint);
101
+ }
102
+ return users;
103
+ }
104
+ }
105
+ _AadGroupUserListCommand_instances = new WeakSet(), _AadGroupUserListCommand_initTelemetry = function _AadGroupUserListCommand_initTelemetry() {
106
+ this.telemetry.push((args) => {
107
+ Object.assign(this.telemetryProperties, {
108
+ groupId: typeof args.options.groupId !== 'undefined',
109
+ groupDisplayName: typeof args.options.groupDisplayName !== 'undefined',
110
+ role: typeof args.options.role !== 'undefined',
111
+ properties: typeof args.options.properties !== 'undefined',
112
+ filter: typeof args.options.filter !== 'undefined'
113
+ });
114
+ });
115
+ }, _AadGroupUserListCommand_initOptions = function _AadGroupUserListCommand_initOptions() {
116
+ this.options.unshift({
117
+ option: "-i, --groupId [groupId]"
118
+ }, {
119
+ option: "-n, --groupDisplayName [groupDisplayName]"
120
+ }, {
121
+ option: "-r, --role [role]",
122
+ autocomplete: ["Owner", "Member"]
123
+ }, {
124
+ option: "-p, --properties [properties]"
125
+ }, {
126
+ option: "-f, --filter [filter]"
127
+ });
128
+ }, _AadGroupUserListCommand_initOptionSets = function _AadGroupUserListCommand_initOptionSets() {
129
+ this.optionSets.push({
130
+ options: ['groupId', 'groupDisplayName']
131
+ });
132
+ }, _AadGroupUserListCommand_initValidators = function _AadGroupUserListCommand_initValidators() {
133
+ this.validators.push(async (args) => {
134
+ if (args.options.groupId && !validation.isValidGuid(args.options.groupId)) {
135
+ return `${args.options.groupId} is not a valid GUID`;
136
+ }
137
+ if (args.options.role) {
138
+ if (['Owner', 'Member'].indexOf(args.options.role) === -1) {
139
+ return `${args.options.role} is not a valid role value. Allowed values Owner|Member`;
140
+ }
141
+ }
142
+ return true;
143
+ });
144
+ };
145
+ export default new AadGroupUserListCommand();
146
+ //# sourceMappingURL=group-user-list.js.map