@pnp/cli-microsoft365 7.8.0-beta.5ca5055 → 7.8.0-beta.a83837a

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 (51) hide show
  1. package/allCommands.json +1 -1
  2. package/allCommandsFull.json +1 -1
  3. package/dist/cli/cli.js +5 -8
  4. package/dist/index.js +13 -12
  5. package/dist/m365/commands/setup.js +3 -3
  6. package/dist/m365/entra/commands/app/app-permission-add.js +25 -6
  7. package/dist/m365/entra/commands/app/app-permission-list.js +17 -5
  8. package/dist/m365/entra/commands/group/group-add.js +12 -14
  9. package/dist/m365/entra/commands/group/group-user-add.js +6 -7
  10. package/dist/m365/entra/commands/m365group/m365group-add.js +4 -2
  11. package/dist/m365/entra/commands/user/user-registrationdetails-list.js +6 -7
  12. package/dist/m365/outlook/commands/message/message-list.js +87 -17
  13. package/dist/m365/planner/commands/bucket/bucket-add.js +4 -7
  14. package/dist/m365/planner/commands/bucket/bucket-get.js +7 -30
  15. package/dist/m365/planner/commands/bucket/bucket-list.js +3 -6
  16. package/dist/m365/planner/commands/bucket/bucket-remove.js +8 -25
  17. package/dist/m365/planner/commands/bucket/bucket-set.js +12 -34
  18. package/dist/m365/planner/commands/plan/plan-add.js +17 -7
  19. package/dist/m365/planner/commands/plan/plan-get.js +12 -22
  20. package/dist/m365/planner/commands/plan/plan-list.js +1 -2
  21. package/dist/m365/planner/commands/plan/plan-remove.js +5 -3
  22. package/dist/m365/planner/commands/plan/plan-set.js +18 -10
  23. package/dist/m365/planner/commands/roster/roster-add.js +1 -2
  24. package/dist/m365/planner/commands/task/task-add.js +15 -21
  25. package/dist/m365/planner/commands/task/task-checklistitem-add.js +1 -1
  26. package/dist/m365/planner/commands/task/task-checklistitem-remove.js +1 -1
  27. package/dist/m365/planner/commands/task/task-get.js +5 -26
  28. package/dist/m365/planner/commands/task/task-list.js +11 -37
  29. package/dist/m365/planner/commands/task/task-reference-remove.js +1 -1
  30. package/dist/m365/planner/commands/task/task-remove.js +12 -29
  31. package/dist/m365/planner/commands/task/task-set.js +15 -21
  32. package/dist/m365/spo/commands/listitem/listitem-batch-remove.js +222 -0
  33. package/dist/m365/spo/commands/navigation/navigation-node-add.js +3 -2
  34. package/dist/m365/spo/commands/navigation/navigation-node-set.js +3 -2
  35. package/dist/m365/spo/commands/site/site-recyclebinitem-move.js +5 -2
  36. package/dist/m365/spo/commands/site/site-recyclebinitem-remove.js +3 -2
  37. package/dist/m365/spo/commands/site/site-remove.js +128 -149
  38. package/dist/m365/spo/commands/spo-set.js +6 -2
  39. package/dist/m365/spo/commands.js +1 -0
  40. package/dist/m365/teams/commands/meeting/meeting-add.js +3 -3
  41. package/dist/m365/teams/commands/team/team-add.js +22 -16
  42. package/dist/utils/planner.js +87 -8
  43. package/dist/utils/urlUtil.js +8 -0
  44. package/dist/utils/validation.js +8 -5
  45. package/docs/docs/cmd/entra/app/app-permission-add.mdx +7 -4
  46. package/docs/docs/cmd/entra/app/app-permission-list.mdx +14 -5
  47. package/docs/docs/cmd/entra/m365group/m365group-add.mdx +24 -24
  48. package/docs/docs/cmd/outlook/message/message-list.mdx +18 -6
  49. package/docs/docs/cmd/spo/listitem/listitem-batch-remove.mdx +70 -0
  50. package/docs/docs/cmd/spo/site/site-remove.mdx +9 -19
  51. package/package.json +1 -1
package/dist/cli/cli.js CHANGED
@@ -18,7 +18,6 @@ import { validation } from '../utils/validation.js';
18
18
  import { prompt } from '../utils/prompt.js';
19
19
  import { timings } from './timings.js';
20
20
  import { browserUtil } from '../utils/browserUtil.js';
21
- import chalk from 'chalk';
22
21
  const require = createRequire(import.meta.url);
23
22
  const __dirname = fileURLToPath(new URL('.', import.meta.url));
24
23
  let _config;
@@ -564,6 +563,7 @@ async function printHelp(helpMode, exitCode = 0) {
564
563
  }
565
564
  else {
566
565
  if (cli.currentCommandName && !cli.commands.some(command => command.name.startsWith(cli.currentCommandName))) {
566
+ const chalk = (await import('chalk')).default;
567
567
  await cli.error(chalk.red(`Command '${cli.currentCommandName}' was not found. Below you can find the commands and command groups you can use. For detailed information on a command group, use 'm365 [command group] --help'.`));
568
568
  }
569
569
  cli.log();
@@ -735,26 +735,23 @@ async function closeWithError(error, args, showHelpIfEnabled = false) {
735
735
  if (args.options.output === 'none') {
736
736
  return process.exit(exitCode);
737
737
  }
738
- const chalk = (await import('chalk')).default;
739
738
  let errorMessage = error instanceof CommandError ? error.message : error;
740
739
  if ((!args.options.output || args.options.output === 'json') &&
741
740
  !cli.getSettingWithDefaultValue(settingsNames.printErrorsAsPlainText, true)) {
742
741
  errorMessage = JSON.stringify({ error: errorMessage });
743
742
  }
744
743
  else {
744
+ const chalk = (await import('chalk')).default;
745
745
  errorMessage = chalk.red(`Error: ${errorMessage}`);
746
746
  }
747
747
  if (error instanceof CommandError && error.code) {
748
748
  exitCode = error.code;
749
749
  }
750
750
  await cli.error(errorMessage);
751
- if (showHelpIfEnabled &&
752
- await cli.getSettingWithDefaultValue(settingsNames.showHelpOnFailure, showHelpIfEnabled)) {
753
- await printHelp(await getHelpMode(args.options), exitCode);
754
- }
755
- else {
756
- process.exit(exitCode);
751
+ if (showHelpIfEnabled && cli.getSettingWithDefaultValue(settingsNames.showHelpOnFailure, showHelpIfEnabled)) {
752
+ await cli.error(`Run 'm365 ${cli.commandToExecute.name} -h' for help.`);
757
753
  }
754
+ process.exit(exitCode);
758
755
  // will never be run. Required for testing where we're stubbing process.exit
759
756
  /* c8 ignore next */
760
757
  throw new Error(errorMessage);
package/dist/index.js CHANGED
@@ -1,17 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import { cli } from './cli/cli.js';
3
3
  import { app } from './utils/app.js';
4
- // required to make console.log() in combination with piped output synchronous
5
- // on Windows/in PowerShell so that the output is not trimmed by calling
6
- // process.exit() after executing the command, while the output is still
7
- // being processed; https://github.com/pnp/cli-microsoft365/issues/1266
8
- if (process.stdout._handle) {
9
- process.stdout._handle.setBlocking(true);
10
- }
11
- if (!process.env.CLIMICROSOFT365_NOUPDATE) {
12
- import('update-notifier').then(updateNotifier => {
4
+ (async () => {
5
+ // required to make console.log() in combination with piped output synchronous
6
+ // on Windows/in PowerShell so that the output is not trimmed by calling
7
+ // process.exit() after executing the command, while the output is still
8
+ // being processed; https://github.com/pnp/cli-microsoft365/issues/1266
9
+ if (process.stdout._handle) {
10
+ process.stdout._handle.setBlocking(true);
11
+ }
12
+ if (!process.env.CLIMICROSOFT365_NOUPDATE) {
13
+ const updateNotifier = await import('update-notifier');
13
14
  updateNotifier.default({ pkg: app.packageJson() }).notify({ defer: false });
14
- });
15
- }
16
- cli.execute(process.argv.slice(2));
15
+ }
16
+ await cli.execute(process.argv.slice(2));
17
+ })();
17
18
  //# sourceMappingURL=index.js.map
@@ -35,9 +35,9 @@ class SetupCommand extends AnonymousCommand {
35
35
  }
36
36
  else if (args.options.scripting) {
37
37
  Object.assign(settings, scriptingPreset);
38
- }
39
- if (pid.isPowerShell()) {
40
- Object.assign(settings, powerShellPreset);
38
+ if (pid.isPowerShell()) {
39
+ Object.assign(settings, powerShellPreset);
40
+ }
41
41
  }
42
42
  await this.configureSettings(settings, true, logger);
43
43
  return;
@@ -10,6 +10,8 @@ import commands from "../../commands.js";
10
10
  import request from "../../../../request.js";
11
11
  import { validation } from "../../../../utils/validation.js";
12
12
  import aadCommands from "../../aadCommands.js";
13
+ import { formatting } from "../../../../utils/formatting.js";
14
+ import { cli } from "../../../../cli/cli.js";
13
15
  var ScopeType;
14
16
  (function (ScopeType) {
15
17
  ScopeType["Role"] = "Role";
@@ -68,11 +70,27 @@ class EntraAppPermissionAddCommand extends GraphCommand {
68
70
  }
69
71
  }
70
72
  async getAppObject(options) {
71
- const apps = options.appObjectId
72
- ? await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=id eq '${options.appObjectId}'&$select=id,appId,requiredResourceAccess`)
73
- : await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=appId eq '${options.appId}'&$select=id,appId,requiredResourceAccess`);
73
+ let appNotFoundMessage = '';
74
+ let apps = [];
75
+ if (options.appId) {
76
+ apps = await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=appId eq '${options.appId}'&$select=id,appId,requiredResourceAccess`);
77
+ appNotFoundMessage = `client id ${options.appId}`;
78
+ }
79
+ else if (options.appName) {
80
+ apps = await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=displayName eq '${formatting.encodeQueryParameter(options.appName)}'&$select=id,appId,requiredResourceAccess`);
81
+ appNotFoundMessage = `name ${options.appName}`;
82
+ if (apps.length > 1) {
83
+ const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', apps);
84
+ const result = await cli.handleMultipleResultsFound(`Multiple Entra application registrations with name '${options.appName}' found.`, resultAsKeyValuePair);
85
+ return result;
86
+ }
87
+ }
88
+ else if (options.appObjectId) {
89
+ apps = await odata.getAllItems(`${this.resource}/v1.0/applications?$filter=id eq '${options.appObjectId}'&$select=id,appId,requiredResourceAccess`);
90
+ appNotFoundMessage = `object id ${options.appObjectId}`;
91
+ }
74
92
  if (apps.length === 0) {
75
- throw `App with ${options.appObjectId ? 'object id' : 'client id'} ${options.appObjectId ? options.appObjectId : options.appId} not found in Microsoft Entra ID`;
93
+ throw `App with ${appNotFoundMessage} not found in Microsoft Entra ID`;
76
94
  }
77
95
  return apps[0];
78
96
  }
@@ -209,6 +227,7 @@ _EntraAppPermissionAddCommand_instances = new WeakSet(), _EntraAppPermissionAddC
209
227
  this.telemetry.push((args) => {
210
228
  Object.assign(this.telemetryProperties, {
211
229
  appId: typeof args.options.appId !== 'undefined',
230
+ appName: typeof args.options.appName !== 'undefined',
212
231
  appObjectId: typeof args.options.appObjectId !== 'undefined',
213
232
  applicationPermissions: typeof args.options.applicationPermissions !== 'undefined',
214
233
  delegatedPermissions: typeof args.options.delegatedPermissions !== 'undefined',
@@ -216,7 +235,7 @@ _EntraAppPermissionAddCommand_instances = new WeakSet(), _EntraAppPermissionAddC
216
235
  });
217
236
  });
218
237
  }, _EntraAppPermissionAddCommand_initOptions = function _EntraAppPermissionAddCommand_initOptions() {
219
- this.options.unshift({ option: '-i, --appId [appId]' }, { option: '--appObjectId [appObjectId]' }, { option: '-a, --applicationPermissions [applicationPermissions]' }, { option: '-d, --delegatedPermissions [delegatedPermissions]' }, { option: '--grantAdminConsent' });
238
+ this.options.unshift({ option: '-i, --appId [appId]' }, { option: '-n, --appName [appName]' }, { option: '--appObjectId [appObjectId]' }, { option: '-a, --applicationPermissions [applicationPermissions]' }, { option: '-d, --delegatedPermissions [delegatedPermissions]' }, { option: '--grantAdminConsent' });
220
239
  }, _EntraAppPermissionAddCommand_initValidators = function _EntraAppPermissionAddCommand_initValidators() {
221
240
  this.validators.push(async (args) => {
222
241
  if (args.options.appId && !validation.isValidGuid(args.options.appId)) {
@@ -228,7 +247,7 @@ _EntraAppPermissionAddCommand_instances = new WeakSet(), _EntraAppPermissionAddC
228
247
  return true;
229
248
  });
230
249
  }, _EntraAppPermissionAddCommand_initOptionSets = function _EntraAppPermissionAddCommand_initOptionSets() {
231
- this.optionSets.push({ options: ['appId', 'appObjectId'] });
250
+ this.optionSets.push({ options: ['appId', 'appName', 'appObjectId'] });
232
251
  this.optionSets.push({
233
252
  options: ['applicationPermissions', 'delegatedPermissions'],
234
253
  runsWhen: (args) => args.options.delegatedPermissions === undefined && args.options.applicationPermissions === undefined
@@ -9,6 +9,7 @@ import commands from "../../commands.js";
9
9
  import request from "../../../../request.js";
10
10
  import { validation } from "../../../../utils/validation.js";
11
11
  import { formatting } from "../../../../utils/formatting.js";
12
+ import { cli } from "../../../../cli/cli.js";
12
13
  class EntraAppPermissionListCommand extends GraphCommand {
13
14
  get name() {
14
15
  return commands.APP_PERMISSION_LIST;
@@ -40,18 +41,28 @@ class EntraAppPermissionListCommand extends GraphCommand {
40
41
  if (options.appObjectId) {
41
42
  return options.appObjectId;
42
43
  }
44
+ const { appId, appName } = options;
45
+ const filter = appId ?
46
+ `appId eq '${formatting.encodeQueryParameter(appId)}'` :
47
+ `displayName eq '${formatting.encodeQueryParameter(appName)}'`;
43
48
  const requestOptions = {
44
- url: `${this.resource}/v1.0/myorganization/applications?$filter=appId eq '${formatting.encodeQueryParameter(options.appId)}'&$select=id`,
49
+ url: `${this.resource}/v1.0/myorganization/applications?$filter=${filter}&$select=id`,
45
50
  headers: {
46
51
  accept: 'application/json;odata.metadata=none'
47
52
  },
48
53
  responseType: 'json'
49
54
  };
50
55
  const res = await request.get(requestOptions);
56
+ if (res.value.length === 1) {
57
+ return res.value[0].id;
58
+ }
51
59
  if (res.value.length === 0) {
52
- throw `No Microsoft Entra application registration with ID ${options.appId} found`;
60
+ const applicationIdentifier = appId ? `ID ${appId}` : `name ${appName}`;
61
+ throw `No Microsoft Entra application registration with ${applicationIdentifier} found`;
53
62
  }
54
- return res.value[0].id;
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;
55
66
  }
56
67
  async getAppRegPermissions(appObjectId, permissionType, logger) {
57
68
  const requestOptions = {
@@ -156,12 +167,13 @@ _EntraAppPermissionListCommand_instances = new WeakSet(), _EntraAppPermissionLis
156
167
  this.telemetry.push((args) => {
157
168
  Object.assign(this.telemetryProperties, {
158
169
  appId: typeof args.options.appId !== 'undefined',
170
+ appName: typeof args.options.appName !== 'undefined',
159
171
  appObjectId: typeof args.options.appObjectId !== 'undefined',
160
172
  type: typeof args.options.type !== 'undefined'
161
173
  });
162
174
  });
163
175
  }, _EntraAppPermissionListCommand_initOptions = function _EntraAppPermissionListCommand_initOptions() {
164
- this.options.unshift({ option: '-i, --appId [appId]' }, { option: '--appObjectId [appObjectId]' }, { option: '--type [type]', autocomplete: this.allowedTypes });
176
+ this.options.unshift({ option: '-i, --appId [appId]' }, { option: '-n, --appName [appName]' }, { option: '--appObjectId [appObjectId]' }, { option: '--type [type]', autocomplete: this.allowedTypes });
165
177
  }, _EntraAppPermissionListCommand_initValidators = function _EntraAppPermissionListCommand_initValidators() {
166
178
  this.validators.push(async (args) => {
167
179
  if (args.options.appId && !validation.isValidGuid(args.options.appId)) {
@@ -176,7 +188,7 @@ _EntraAppPermissionListCommand_instances = new WeakSet(), _EntraAppPermissionLis
176
188
  return true;
177
189
  });
178
190
  }, _EntraAppPermissionListCommand_initOptionSets = function _EntraAppPermissionListCommand_initOptionSets() {
179
- this.optionSets.push({ options: ['appId', 'appObjectId'] });
191
+ this.optionSets.push({ options: ['appId', 'appName', 'appObjectId'] });
180
192
  };
181
193
  export default new EntraAppPermissionListCommand();
182
194
  //# sourceMappingURL=app-permission-list.js.map
@@ -169,29 +169,27 @@ _EntraGroupAddCommand_instances = new WeakSet(), _EntraGroupAddCommand_initOptio
169
169
  }
170
170
  }
171
171
  if (args.options.ownerIds) {
172
- const ids = args.options.ownerIds.split(',').map(i => i.trim());
173
- if (!validation.isValidGuidArray(ids)) {
174
- const invalidGuid = ids.find(id => !validation.isValidGuid(id));
175
- return `'${invalidGuid}' is not a valid GUID for option 'ownerIds'.`;
172
+ const isValidGUIDArrayResult = validation.isValidGuidArray(args.options.ownerIds);
173
+ if (isValidGUIDArrayResult !== true) {
174
+ return `The following GUIDs are invalid for the option 'ownerIds': ${isValidGUIDArrayResult}.`;
176
175
  }
177
176
  }
178
177
  if (args.options.ownerUserNames) {
179
- const isValidUserPrincipalNameArray = validation.isValidUserPrincipalNameArray(args.options.ownerUserNames.split(',').map(u => u.trim()));
180
- if (isValidUserPrincipalNameArray !== true) {
181
- return `User principal name '${isValidUserPrincipalNameArray}' is invalid for option 'ownerUserNames'.`;
178
+ const isValidUPNArrayResult = validation.isValidUserPrincipalNameArray(args.options.ownerUserNames);
179
+ if (isValidUPNArrayResult !== true) {
180
+ return `The following user principal names are invalid for the option 'ownerUserNames': ${isValidUPNArrayResult}.`;
182
181
  }
183
182
  }
184
183
  if (args.options.memberIds) {
185
- const ids = args.options.memberIds.split(',').map(i => i.trim());
186
- if (!validation.isValidGuidArray(ids)) {
187
- const invalidGuid = ids.find(id => !validation.isValidGuid(id));
188
- return `'${invalidGuid}' is not a valid GUID for option 'memberIds'.`;
184
+ const isValidGUIDArrayResult = validation.isValidGuidArray(args.options.memberIds);
185
+ if (isValidGUIDArrayResult !== true) {
186
+ return `The following GUIDs are invalid for the option 'memberIds': ${isValidGUIDArrayResult}.`;
189
187
  }
190
188
  }
191
189
  if (args.options.memberUserNames) {
192
- const isValidUserPrincipalNameArray = validation.isValidUserPrincipalNameArray(args.options.memberUserNames.split(',').map(u => u.trim()));
193
- if (isValidUserPrincipalNameArray !== true) {
194
- return `User principal name '${isValidUserPrincipalNameArray}' is invalid for option 'memberUserNames'.`;
190
+ const isValidUPNArrayResult = validation.isValidUserPrincipalNameArray(args.options.memberUserNames);
191
+ if (isValidUPNArrayResult !== true) {
192
+ return `The following user principal names are invalid for the option 'memberUserNames': ${isValidUPNArrayResult}.`;
195
193
  }
196
194
  }
197
195
  if (['microsoft365', 'security'].indexOf(args.options.type) === -1) {
@@ -119,16 +119,15 @@ _EntraGroupUserAddCommand_instances = new WeakSet(), _EntraGroupUserAddCommand_i
119
119
  return `${args.options.groupId} is not a valid GUID for option groupId.`;
120
120
  }
121
121
  if (args.options.ids) {
122
- const ids = args.options.ids.split(',').map(i => i.trim());
123
- if (!validation.isValidGuidArray(ids)) {
124
- const invalidGuid = ids.find(id => !validation.isValidGuid(id));
125
- return `'${invalidGuid}' is not a valid GUID for option 'ids'.`;
122
+ const isValidGUIDArrayResult = validation.isValidGuidArray(args.options.ids);
123
+ if (isValidGUIDArrayResult !== true) {
124
+ return `The following GUIDs are invalid for the option 'ids': ${isValidGUIDArrayResult}.`;
126
125
  }
127
126
  }
128
127
  if (args.options.userNames) {
129
- const isValidUserPrincipalNameArray = validation.isValidUserPrincipalNameArray(args.options.userNames.split(',').map(u => u.trim()));
130
- if (isValidUserPrincipalNameArray !== true) {
131
- return `User principal name '${isValidUserPrincipalNameArray}' is invalid for option 'userNames'.`;
128
+ const isValidUPNArrayResult = validation.isValidUserPrincipalNameArray(args.options.userNames);
129
+ if (isValidUPNArrayResult !== true) {
130
+ return `The following user principal names are invalid for the option 'userNames': ${isValidUPNArrayResult}.`;
132
131
  }
133
132
  }
134
133
  if (this.roleValues.indexOf(args.options.role) === -1) {
@@ -189,6 +189,7 @@ class EntraM365GroupAddCommand extends GraphCommand {
189
189
  _EntraM365GroupAddCommand_instances = new WeakSet(), _EntraM365GroupAddCommand_initTelemetry = function _EntraM365GroupAddCommand_initTelemetry() {
190
190
  this.telemetry.push((args) => {
191
191
  Object.assign(this.telemetryProperties, {
192
+ description: typeof args.options.description !== 'undefined',
192
193
  owners: typeof args.options.owners !== 'undefined',
193
194
  members: typeof args.options.members !== 'undefined',
194
195
  logoPath: typeof args.options.logoPath !== 'undefined',
@@ -202,10 +203,10 @@ _EntraM365GroupAddCommand_instances = new WeakSet(), _EntraM365GroupAddCommand_i
202
203
  }, _EntraM365GroupAddCommand_initOptions = function _EntraM365GroupAddCommand_initOptions() {
203
204
  this.options.unshift({
204
205
  option: '-n, --displayName <displayName>'
205
- }, {
206
- option: '-d, --description <description>'
207
206
  }, {
208
207
  option: '-m, --mailNickname <mailNickname>'
208
+ }, {
209
+ option: '-d, --description [description]'
209
210
  }, {
210
211
  option: '--owners [owners]'
211
212
  }, {
@@ -229,6 +230,7 @@ _EntraM365GroupAddCommand_instances = new WeakSet(), _EntraM365GroupAddCommand_i
229
230
  option: '-l, --logoPath [logoPath]'
230
231
  });
231
232
  }, _EntraM365GroupAddCommand_initTypes = function _EntraM365GroupAddCommand_initTypes() {
233
+ this.types.string.push('displayName', 'mailNickname', 'description', 'owners', 'members', 'visibility', 'logoPath');
232
234
  this.types.boolean.push('allowMembersToPost', 'hideGroupInOutlook', 'subscribeNewGroupMembers', 'welcomeEmailDisabled');
233
235
  }, _EntraM365GroupAddCommand_initValidators = function _EntraM365GroupAddCommand_initValidators() {
234
236
  this.validators.push(async (args) => {
@@ -205,16 +205,15 @@ _EntraUserRegistrationDetailsListCommand_instances = new WeakSet(), _EntraUserRe
205
205
  }
206
206
  }
207
207
  if (args.options.userIds) {
208
- const ids = args.options.userIds.split(',').map(i => i.trim());
209
- if (!validation.isValidGuidArray(ids)) {
210
- const invalidGuid = ids.find(id => !validation.isValidGuid(id));
211
- return `'${invalidGuid}' is not a valid GUID for option 'userIds'.`;
208
+ const isValidGUIDArrayResult = validation.isValidGuidArray(args.options.userIds);
209
+ if (isValidGUIDArrayResult !== true) {
210
+ return `The following GUIDs are invalid for the option 'userIds': ${isValidGUIDArrayResult}.`;
212
211
  }
213
212
  }
214
213
  if (args.options.userPrincipalNames) {
215
- const isValidUserPrincipalNameArray = validation.isValidUserPrincipalNameArray(args.options.userPrincipalNames.split(',').map(u => u.trim()));
216
- if (isValidUserPrincipalNameArray !== true) {
217
- return `User principal name '${isValidUserPrincipalNameArray}' is invalid for option 'userPrincipalNames'.`;
214
+ const isValidUPNArrayResult = validation.isValidUserPrincipalNameArray(args.options.userPrincipalNames);
215
+ if (isValidUPNArrayResult !== true) {
216
+ return `The following user principal names are invalid for the option 'userPrincipalNames': ${isValidUPNArrayResult}.`;
218
217
  }
219
218
  }
220
219
  return true;
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
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
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _OutlookMessageListCommand_instances, _OutlookMessageListCommand_initTelemetry, _OutlookMessageListCommand_initOptions, _OutlookMessageListCommand_initOptionSets;
6
+ var _OutlookMessageListCommand_instances, _OutlookMessageListCommand_initTelemetry, _OutlookMessageListCommand_initOptions, _OutlookMessageListCommand_initValidators, _OutlookMessageListCommand_initTypes, _OutlookMessageListCommand_initOptionSets;
7
7
  import request from '../../../../request.js';
8
8
  import { formatting } from '../../../../utils/formatting.js';
9
9
  import { odata } from '../../../../utils/odata.js';
@@ -11,6 +11,9 @@ import GraphCommand from '../../../base/GraphCommand.js';
11
11
  import commands from '../../commands.js';
12
12
  import { Outlook } from '../../Outlook.js';
13
13
  import { cli } from '../../../../cli/cli.js';
14
+ import { validation } from '../../../../utils/validation.js';
15
+ import { accessToken } from '../../../../utils/accessToken.js';
16
+ import auth from '../../../../Auth.js';
14
17
  class OutlookMessageListCommand extends GraphCommand {
15
18
  get name() {
16
19
  return commands.MESSAGE_LIST;
@@ -23,6 +26,8 @@ class OutlookMessageListCommand extends GraphCommand {
23
26
  _OutlookMessageListCommand_instances.add(this);
24
27
  __classPrivateFieldGet(this, _OutlookMessageListCommand_instances, "m", _OutlookMessageListCommand_initTelemetry).call(this);
25
28
  __classPrivateFieldGet(this, _OutlookMessageListCommand_instances, "m", _OutlookMessageListCommand_initOptions).call(this);
29
+ __classPrivateFieldGet(this, _OutlookMessageListCommand_instances, "m", _OutlookMessageListCommand_initValidators).call(this);
30
+ __classPrivateFieldGet(this, _OutlookMessageListCommand_instances, "m", _OutlookMessageListCommand_initTypes).call(this);
26
31
  __classPrivateFieldGet(this, _OutlookMessageListCommand_instances, "m", _OutlookMessageListCommand_initOptionSets).call(this);
27
32
  }
28
33
  defaultProperties() {
@@ -30,27 +35,44 @@ class OutlookMessageListCommand extends GraphCommand {
30
35
  }
31
36
  async commandAction(logger, args) {
32
37
  try {
33
- const folderId = await this.getFolderId(args);
34
- const url = folderId ? `me/mailFolders/${folderId}/messages` : 'me/messages';
35
- const messages = await odata.getAllItems(`${this.resource}/v1.0/${url}?$top=50`);
38
+ if (!args.options.userId && !args.options.userName && accessToken.isAppOnlyAccessToken(auth.connection.accessTokens[auth.defaultResource].accessToken)) {
39
+ throw 'You must specify either the userId or userName option when using app-only permissions.';
40
+ }
41
+ const userUrl = args.options.userId || args.options.userName ? `users/${args.options.userId || formatting.encodeQueryParameter(args.options.userName)}` : 'me';
42
+ const folderId = await this.getFolderId(userUrl, args.options);
43
+ const folderUrl = folderId ? `/mailFolders/${folderId}` : '';
44
+ let requestUrl = `${this.resource}/v1.0/${userUrl}${folderUrl}/messages?$top=100`;
45
+ if (args.options.startTime || args.options.endTime) {
46
+ const filters = [];
47
+ if (args.options.startTime) {
48
+ filters.push(`receivedDateTime ge ${args.options.startTime}`);
49
+ }
50
+ if (args.options.endTime) {
51
+ filters.push(`receivedDateTime lt ${args.options.endTime}`);
52
+ }
53
+ if (filters.length > 0) {
54
+ requestUrl += `&$filter=${filters.join(' and ')}`;
55
+ }
56
+ }
57
+ const messages = await odata.getAllItems(requestUrl);
36
58
  await logger.log(messages);
37
59
  }
38
60
  catch (err) {
39
61
  this.handleRejectedODataJsonPromise(err);
40
62
  }
41
63
  }
42
- async getFolderId(args) {
43
- if (!args.options.folderId && !args.options.folderName) {
64
+ async getFolderId(userUrl, options) {
65
+ if (!options.folderId && !options.folderName) {
44
66
  return '';
45
67
  }
46
- if (args.options.folderId) {
47
- return args.options.folderId;
68
+ if (options.folderId) {
69
+ return options.folderId;
48
70
  }
49
- if (Outlook.wellKnownFolderNames.indexOf(args.options.folderName) > -1) {
50
- return args.options.folderName;
71
+ if (Outlook.wellKnownFolderNames.includes(options.folderName.toLowerCase())) {
72
+ return options.folderName;
51
73
  }
52
74
  const requestOptions = {
53
- url: `${this.resource}/v1.0/me/mailFolders?$filter=displayName eq '${formatting.encodeQueryParameter(args.options.folderName)}'&$select=id`,
75
+ url: `${this.resource}/v1.0/${userUrl}/mailFolders?$filter=displayName eq '${formatting.encodeQueryParameter(options.folderName)}'&$select=id`,
54
76
  headers: {
55
77
  accept: 'application/json;odata.metadata=none'
56
78
  },
@@ -58,11 +80,11 @@ class OutlookMessageListCommand extends GraphCommand {
58
80
  };
59
81
  const response = await request.get(requestOptions);
60
82
  if (response.value.length === 0) {
61
- throw `Folder with name '${args.options.folderName}' not found`;
83
+ throw `Folder with name '${options.folderName}' not found`;
62
84
  }
63
85
  if (response.value.length > 1) {
64
86
  const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', response.value);
65
- const result = await cli.handleMultipleResultsFound(`Multiple folders with name '${args.options.folderName}' found.`, resultAsKeyValuePair);
87
+ const result = await cli.handleMultipleResultsFound(`Multiple folders with name '${options.folderName}' found.`, resultAsKeyValuePair);
66
88
  return result.id;
67
89
  }
68
90
  return response.value[0].id;
@@ -72,7 +94,11 @@ _OutlookMessageListCommand_instances = new WeakSet(), _OutlookMessageListCommand
72
94
  this.telemetry.push((args) => {
73
95
  Object.assign(this.telemetryProperties, {
74
96
  folderId: typeof args.options.folderId !== 'undefined',
75
- folderName: typeof args.options.folderName !== 'undefined'
97
+ folderName: typeof args.options.folderName !== 'undefined',
98
+ startTime: typeof args.options.startTime !== 'undefined',
99
+ endTime: typeof args.options.endTime !== 'undefined',
100
+ userId: typeof args.options.userId !== 'undefined',
101
+ userName: typeof args.options.userName !== 'undefined'
76
102
  });
77
103
  });
78
104
  }, _OutlookMessageListCommand_initOptions = function _OutlookMessageListCommand_initOptions() {
@@ -80,11 +106,55 @@ _OutlookMessageListCommand_instances = new WeakSet(), _OutlookMessageListCommand
80
106
  option: '--folderName [folderName]',
81
107
  autocomplete: Outlook.wellKnownFolderNames
82
108
  }, {
83
- option: '--folderId [folderId]',
84
- autocomplete: Outlook.wellKnownFolderNames
109
+ option: '--folderId [folderId]'
110
+ }, {
111
+ option: '--startTime [startTime]'
112
+ }, {
113
+ option: '--endTime [endTime]'
114
+ }, {
115
+ option: '--userId [userId]'
116
+ }, {
117
+ option: '--userName [userName]'
85
118
  });
119
+ }, _OutlookMessageListCommand_initValidators = function _OutlookMessageListCommand_initValidators() {
120
+ this.validators.push(async (args) => {
121
+ if (args.options.startTime) {
122
+ if (!validation.isValidISODateTime(args.options.startTime)) {
123
+ return `'${args.options.startTime}' is not a valid ISO date string for option startTime.`;
124
+ }
125
+ if (new Date(args.options.startTime) > new Date()) {
126
+ return 'startTime value cannot be in the future.';
127
+ }
128
+ }
129
+ if (args.options.endTime) {
130
+ if (!validation.isValidISODateTime(args.options.endTime)) {
131
+ return `'${args.options.endTime}' is not a valid ISO date string for option endTime.`;
132
+ }
133
+ if (new Date(args.options.endTime) > new Date()) {
134
+ return 'endTime value cannot be in the future.';
135
+ }
136
+ }
137
+ if (args.options.startTime && args.options.endTime && new Date(args.options.startTime) >= new Date(args.options.endTime)) {
138
+ return 'startTime must be before endTime.';
139
+ }
140
+ if (args.options.userId && !validation.isValidGuid(args.options.userId)) {
141
+ return `${args.options.userId} is not a valid GUID for option userId.`;
142
+ }
143
+ if (args.options.userName && !validation.isValidUserPrincipalName(args.options.userName)) {
144
+ return `${args.options.userName} is not a valid UPN for option userName.`;
145
+ }
146
+ return true;
147
+ });
148
+ }, _OutlookMessageListCommand_initTypes = function _OutlookMessageListCommand_initTypes() {
149
+ this.types.string.push('folderName', 'folderId', 'startTime', 'endTime', 'userId', 'userName');
86
150
  }, _OutlookMessageListCommand_initOptionSets = function _OutlookMessageListCommand_initOptionSets() {
87
- this.optionSets.push({ options: ['folderId', 'folderName'] });
151
+ this.optionSets.push({
152
+ options: ['folderId', 'folderName'],
153
+ runsWhen: (args) => args.options.folderId || args.options.folderName
154
+ }, {
155
+ options: ['userId', 'userName'],
156
+ runsWhen: (args) => args.options.userId || args.options.userName
157
+ });
88
158
  };
89
159
  export default new OutlookMessageListCommand();
90
160
  //# sourceMappingURL=message-list.js.map
@@ -35,7 +35,7 @@ class PlannerBucketAddCommand extends GraphCommand {
35
35
  const requestOptions = {
36
36
  url: `${this.resource}/v1.0/planner/buckets`,
37
37
  headers: {
38
- 'accept': 'application/json;odata.metadata=none'
38
+ accept: 'application/json;odata.metadata=none'
39
39
  },
40
40
  responseType: 'json',
41
41
  data: {
@@ -57,18 +57,15 @@ class PlannerBucketAddCommand extends GraphCommand {
57
57
  }
58
58
  if (args.options.planTitle) {
59
59
  const groupId = await this.getGroupId(args);
60
- const plan = await planner.getPlanByTitle(args.options.planTitle, groupId);
61
- return plan.id;
60
+ return planner.getPlanIdByTitle(args.options.planTitle, groupId);
62
61
  }
63
- const plan = await planner.getPlanByRosterId(args.options.rosterId);
64
- return plan.id;
62
+ return planner.getPlanIdByRosterId(args.options.rosterId);
65
63
  }
66
64
  async getGroupId(args) {
67
65
  if (args.options.ownerGroupId) {
68
66
  return args.options.ownerGroupId;
69
67
  }
70
- const group = await entraGroup.getGroupByDisplayName(args.options.ownerGroupName);
71
- return group.id;
68
+ return entraGroup.getGroupIdByDisplayName(args.options.ownerGroupName);
72
69
  }
73
70
  }
74
71
  _PlannerBucketAddCommand_instances = new WeakSet(), _PlannerBucketAddCommand_initTelemetry = function _PlannerBucketAddCommand_initTelemetry() {
@@ -10,8 +10,6 @@ import { planner } from '../../../../utils/planner.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 { cli } from '../../../../cli/cli.js';
14
- import { formatting } from '../../../../utils/formatting.js';
15
13
  class PlannerBucketGetCommand extends GraphCommand {
16
14
  get name() {
17
15
  return commands.BUCKET_GET;
@@ -30,38 +28,20 @@ class PlannerBucketGetCommand extends GraphCommand {
30
28
  }
31
29
  async commandAction(logger, args) {
32
30
  try {
33
- const bucketId = await this.getBucketId(args);
34
- const bucket = await this.getBucketById(bucketId);
31
+ const bucket = await this.getBucket(args);
35
32
  await logger.log(bucket);
36
33
  }
37
34
  catch (err) {
38
35
  this.handleRejectedODataJsonPromise(err);
39
36
  }
40
37
  }
41
- async getBucketId(args) {
38
+ async getBucket(args) {
42
39
  const { id, name } = args.options;
43
40
  if (id) {
44
- return id;
41
+ return this.getBucketById(id);
45
42
  }
46
43
  const planId = await this.getPlanId(args);
47
- const requestOptions = {
48
- url: `${this.resource}/v1.0/planner/plans/${planId}/buckets`,
49
- headers: {
50
- accept: 'application/json;odata.metadata=none'
51
- },
52
- responseType: 'json'
53
- };
54
- const buckets = await request.get(requestOptions);
55
- const filteredBuckets = buckets.value.filter(b => name.toLowerCase() === b.name.toLowerCase());
56
- if (!filteredBuckets.length) {
57
- throw `The specified bucket ${name} does not exist`;
58
- }
59
- if (filteredBuckets.length > 1) {
60
- const resultAsKeyValuePair = formatting.convertArrayToHashTable('id', filteredBuckets);
61
- const result = await cli.handleMultipleResultsFound(`Multiple buckets with name '${name}' found.`, resultAsKeyValuePair);
62
- return result.id.toString();
63
- }
64
- return filteredBuckets[0].id.toString();
44
+ return planner.getBucketByTitle(name, planId);
65
45
  }
66
46
  async getPlanId(args) {
67
47
  const { planId, planTitle, rosterId } = args.options;
@@ -70,11 +50,9 @@ class PlannerBucketGetCommand extends GraphCommand {
70
50
  }
71
51
  if (planTitle) {
72
52
  const groupId = await this.getGroupId(args);
73
- const plan = await planner.getPlanByTitle(planTitle, groupId);
74
- return plan.id;
53
+ return planner.getPlanIdByTitle(planTitle, groupId);
75
54
  }
76
- const plan = await planner.getPlanByRosterId(rosterId);
77
- return plan.id;
55
+ return planner.getPlanIdByRosterId(rosterId);
78
56
  }
79
57
  async getBucketById(id) {
80
58
  const requestOptions = {
@@ -91,8 +69,7 @@ class PlannerBucketGetCommand extends GraphCommand {
91
69
  if (ownerGroupId) {
92
70
  return ownerGroupId;
93
71
  }
94
- const group = await entraGroup.getGroupByDisplayName(ownerGroupName);
95
- return group.id;
72
+ return entraGroup.getGroupIdByDisplayName(ownerGroupName);
96
73
  }
97
74
  }
98
75
  _PlannerBucketGetCommand_instances = new WeakSet(), _PlannerBucketGetCommand_initTelemetry = function _PlannerBucketGetCommand_initTelemetry() {