@pnp/cli-microsoft365 11.6.0 → 11.7.0-beta.293104a

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 (32) hide show
  1. package/allCommands.json +1 -1
  2. package/allCommandsFull.json +1 -1
  3. package/dist/config.js +1 -0
  4. package/dist/m365/entra/commands/user/user-license-add.js +2 -1
  5. package/dist/m365/entra/commands/user/user-license-list.js +4 -9
  6. package/dist/m365/entra/commands/user/user-license-remove.js +2 -1
  7. package/dist/m365/outlook/commands/calendar/calendar-add.js +85 -0
  8. package/dist/m365/outlook/commands/calendar/calendar-get.js +71 -0
  9. package/dist/m365/outlook/commands/calendar/calendar-remove.js +100 -0
  10. package/dist/m365/outlook/commands/event/event-cancel.js +103 -0
  11. package/dist/m365/outlook/commands/event/event-list.js +115 -0
  12. package/dist/m365/outlook/commands/event/event-remove.js +104 -0
  13. package/dist/m365/outlook/commands.js +6 -0
  14. package/dist/m365/teams/commands/chat/chat-message-list.js +43 -4
  15. package/dist/utils/calendar.js +37 -0
  16. package/dist/utils/calendarGroup.js +22 -0
  17. package/dist/utils/entraApp.js +9 -2
  18. package/docs/docs/cmd/entra/license/license-list.mdx +19 -0
  19. package/docs/docs/cmd/entra/m365group/m365group-conversation-list.mdx +19 -0
  20. package/docs/docs/cmd/entra/m365group/m365group-conversation-post-list.mdx +19 -0
  21. package/docs/docs/cmd/entra/user/user-license-add.mdx +19 -0
  22. package/docs/docs/cmd/entra/user/user-license-list.mdx +18 -1
  23. package/docs/docs/cmd/entra/user/user-license-remove.mdx +21 -0
  24. package/docs/docs/cmd/outlook/calendar/calendar-add.mdx +165 -0
  25. package/docs/docs/cmd/outlook/calendar/calendar-get.mdx +165 -0
  26. package/docs/docs/cmd/outlook/calendar/calendar-remove.mdx +86 -0
  27. package/docs/docs/cmd/outlook/event/event-cancel.mdx +85 -0
  28. package/docs/docs/cmd/outlook/event/event-list.mdx +245 -0
  29. package/docs/docs/cmd/outlook/event/event-remove.mdx +85 -0
  30. package/docs/docs/cmd/teams/chat/chat-message-list.mdx +23 -2
  31. package/npm-shrinkwrap.json +322 -306
  32. package/package.json +33 -21
package/dist/config.js CHANGED
@@ -7,6 +7,7 @@ export default {
7
7
  'https://graph.microsoft.com/AuditLog.Read.All',
8
8
  'https://graph.microsoft.com/Bookings.Read.All',
9
9
  'https://graph.microsoft.com/Calendars.Read',
10
+ 'https://graph.microsoft.com/Calendars.ReadWrite',
10
11
  'https://graph.microsoft.com/ChannelMember.ReadWrite.All',
11
12
  'https://graph.microsoft.com/ChannelMessage.Read.All',
12
13
  'https://graph.microsoft.com/ChannelMessage.ReadWrite',
@@ -5,6 +5,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
5
5
  };
6
6
  var _EntraUserLicenseAddCommand_instances, _EntraUserLicenseAddCommand_initTelemetry, _EntraUserLicenseAddCommand_initOptions, _EntraUserLicenseAddCommand_initValidators, _EntraUserLicenseAddCommand_initOptionSets;
7
7
  import request from '../../../../request.js';
8
+ import { formatting } from '../../../../utils/formatting.js';
8
9
  import { validation } from '../../../../utils/validation.js';
9
10
  import GraphCommand from '../../../base/GraphCommand.js';
10
11
  import commands from '../../commands.js';
@@ -27,7 +28,7 @@ class EntraUserLicenseAddCommand extends GraphCommand {
27
28
  const addLicenses = args.options.ids.split(',').map(x => { return { "disabledPlans": [], "skuId": x }; });
28
29
  const requestBody = { "addLicenses": addLicenses, "removeLicenses": [] };
29
30
  const requestOptions = {
30
- url: `${this.resource}/v1.0/users/${args.options.userId || args.options.userName}/assignLicense`,
31
+ url: `${this.resource}/v1.0/users/${formatting.encodeQueryParameter(args.options.userId || args.options.userName)}/assignLicense`,
31
32
  headers: {
32
33
  accept: 'application/json;odata.metadata=none'
33
34
  },
@@ -4,13 +4,12 @@ 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 _EntraUserLicenseListCommand_instances, _EntraUserLicenseListCommand_initTelemetry, _EntraUserLicenseListCommand_initOptions, _EntraUserLicenseListCommand_initValidators, _EntraUserLicenseListCommand_initOptionSets;
7
- import { accessToken } from '../../../../utils/accessToken.js';
8
7
  import { odata } from '../../../../utils/odata.js';
8
+ import { formatting } from '../../../../utils/formatting.js';
9
9
  import { validation } from '../../../../utils/validation.js';
10
- import GraphCommand from '../../../base/GraphCommand.js';
11
10
  import commands from '../../commands.js';
12
- import auth from '../../../../Auth.js';
13
- class EntraUserLicenseListCommand extends GraphCommand {
11
+ import GraphDelegatedCommand from '../../../base/GraphDelegatedCommand.js';
12
+ class EntraUserLicenseListCommand extends GraphDelegatedCommand {
14
13
  get name() {
15
14
  return commands.USER_LICENSE_LIST;
16
15
  }
@@ -29,16 +28,12 @@ class EntraUserLicenseListCommand extends GraphCommand {
29
28
  __classPrivateFieldGet(this, _EntraUserLicenseListCommand_instances, "m", _EntraUserLicenseListCommand_initOptionSets).call(this);
30
29
  }
31
30
  async commandAction(logger, args) {
32
- const isAppOnlyAccessToken = accessToken.isAppOnlyAccessToken(auth.connection.accessTokens[this.resource].accessToken);
33
- if (isAppOnlyAccessToken && !args.options.userId && !args.options.userName) {
34
- this.handleError(`Specify at least 'userId' or 'userName' when using application permissions.`);
35
- }
36
31
  if (this.verbose) {
37
32
  await logger.logToStderr(`Retrieving licenses from user: ${args.options.userId || args.options.userName || 'current user'}.`);
38
33
  }
39
34
  let requestUrl = `${this.resource}/v1.0/`;
40
35
  if (args.options.userId || args.options.userName) {
41
- requestUrl += `users/${args.options.userId || args.options.userName}`;
36
+ requestUrl += `users/${formatting.encodeQueryParameter(args.options.userId || args.options.userName)}`;
42
37
  }
43
38
  else {
44
39
  requestUrl += 'me';
@@ -7,6 +7,7 @@ var _EntraUserLicenseRemoveCommand_instances, _EntraUserLicenseRemoveCommand_ini
7
7
  import commands from '../../commands.js';
8
8
  import request from '../../../../request.js';
9
9
  import { validation } from '../../../../utils/validation.js';
10
+ import { formatting } from '../../../../utils/formatting.js';
10
11
  import { cli } from '../../../../cli/cli.js';
11
12
  import GraphCommand from '../../../base/GraphCommand.js';
12
13
  class EntraUserLicenseRemoveCommand extends GraphCommand {
@@ -42,7 +43,7 @@ class EntraUserLicenseRemoveCommand extends GraphCommand {
42
43
  const removeLicenses = args.options.ids.split(',');
43
44
  const requestBody = { "addLicenses": [], "removeLicenses": removeLicenses };
44
45
  const requestOptions = {
45
- url: `${this.resource}/v1.0/users/${args.options.userId || args.options.userName}/assignLicense`,
46
+ url: `${this.resource}/v1.0/users/${formatting.encodeQueryParameter(args.options.userId || args.options.userName)}/assignLicense`,
46
47
  headers: {
47
48
  accept: 'application/json;odata.metadata=none'
48
49
  },
@@ -0,0 +1,85 @@
1
+ import request from '../../../../request.js';
2
+ import GraphCommand from '../../../base/GraphCommand.js';
3
+ import commands from '../../commands.js';
4
+ import { z } from 'zod';
5
+ import { globalOptionsZod } from '../../../../Command.js';
6
+ import { validation } from '../../../../utils/validation.js';
7
+ import { calendarGroup } from '../../../../utils/calendarGroup.js';
8
+ export const options = z.strictObject({
9
+ ...globalOptionsZod.shape,
10
+ userId: z.string()
11
+ .refine(userId => validation.isValidGuid(userId), {
12
+ error: e => `'${e.input}' is not a valid GUID.`
13
+ }).optional(),
14
+ userName: z.string()
15
+ .refine(userName => validation.isValidUserPrincipalName(userName), {
16
+ error: e => `'${e.input}' is not a valid UPN.`
17
+ }).optional(),
18
+ name: z.string(),
19
+ calendarGroupId: z.string().optional(),
20
+ calendarGroupName: z.string().optional(),
21
+ color: z.enum(['auto', 'lightBlue', 'lightGreen', 'lightOrange', 'lightGray', 'lightYellow', 'lightTeal', 'lightPink', 'lightBrown', 'lightRed', 'maxColor']).optional().default('auto'),
22
+ defaultOnlineMeetingProvider: z.enum(['none', 'teamsForBusiness']).optional().default('teamsForBusiness'),
23
+ default: z.boolean().optional()
24
+ });
25
+ class OutlookCalendarAddCommand extends GraphCommand {
26
+ get name() {
27
+ return commands.CALENDAR_ADD;
28
+ }
29
+ get description() {
30
+ return 'Creates a new calendar for a user';
31
+ }
32
+ get schema() {
33
+ return options;
34
+ }
35
+ getRefinedSchema(schema) {
36
+ return schema
37
+ .refine(options => !(options.userId && options.userName), {
38
+ error: 'Specify either userId or userName, but not both'
39
+ })
40
+ .refine(options => !(options.calendarGroupId && options.calendarGroupName), {
41
+ error: 'Specify either calendarGroupId or calendarGroupName, but not both'
42
+ });
43
+ }
44
+ async commandAction(logger, args) {
45
+ try {
46
+ const userIdentifier = args.options.userId ?? args.options.userName;
47
+ let requestUrl = `${this.resource}/v1.0/users('${userIdentifier}')/`;
48
+ if (args.options.calendarGroupId || args.options.calendarGroupName) {
49
+ let calendarGroupId = args.options.calendarGroupId;
50
+ if (args.options.calendarGroupName) {
51
+ const group = await calendarGroup.getUserCalendarGroupByName(userIdentifier, args.options.calendarGroupName, 'id');
52
+ calendarGroupId = group.id;
53
+ }
54
+ requestUrl += `calendarGroups/${calendarGroupId}/calendars`;
55
+ }
56
+ else {
57
+ requestUrl += 'calendars';
58
+ }
59
+ if (args.options.verbose) {
60
+ await logger.logToStderr(`Creating a calendar for the user ${userIdentifier}...`);
61
+ }
62
+ const requestOptions = {
63
+ url: requestUrl,
64
+ headers: {
65
+ accept: 'application/json;odata.metadata=none',
66
+ 'content-type': 'application/json'
67
+ },
68
+ responseType: 'json',
69
+ data: {
70
+ name: args.options.name,
71
+ color: args.options.color,
72
+ defaultOnlineMeetingProvider: args.options.defaultOnlineMeetingProvider,
73
+ isDefaultCalendar: args.options.default
74
+ }
75
+ };
76
+ const result = await request.post(requestOptions);
77
+ await logger.log(result);
78
+ }
79
+ catch (err) {
80
+ this.handleRejectedODataJsonPromise(err);
81
+ }
82
+ }
83
+ }
84
+ export default new OutlookCalendarAddCommand();
85
+ //# sourceMappingURL=calendar-add.js.map
@@ -0,0 +1,71 @@
1
+ import GraphCommand from '../../../base/GraphCommand.js';
2
+ import commands from '../../commands.js';
3
+ import { z } from 'zod';
4
+ import { globalOptionsZod } from '../../../../Command.js';
5
+ import { validation } from '../../../../utils/validation.js';
6
+ import { calendarGroup } from '../../../../utils/calendarGroup.js';
7
+ import { calendar } from '../../../../utils/calendar.js';
8
+ export const options = z.strictObject({
9
+ ...globalOptionsZod.shape,
10
+ id: z.string().alias('i').optional(),
11
+ name: z.string().alias('n').optional(),
12
+ userId: z.string()
13
+ .refine(userId => validation.isValidGuid(userId), {
14
+ error: e => `'${e.input}' is not a valid GUID.`
15
+ }).optional(),
16
+ userName: z.string()
17
+ .refine(userName => validation.isValidUserPrincipalName(userName), {
18
+ error: e => `'${e.input}' is not a valid UPN.`
19
+ }).optional(),
20
+ calendarGroupId: z.string().optional(),
21
+ calendarGroupName: z.string().optional()
22
+ });
23
+ class OutlookCalendarGetCommand extends GraphCommand {
24
+ get name() {
25
+ return commands.CALENDAR_GET;
26
+ }
27
+ get description() {
28
+ return 'Retrieves the calendar of a user or a group';
29
+ }
30
+ get schema() {
31
+ return options;
32
+ }
33
+ getRefinedSchema(schema) {
34
+ return schema
35
+ .refine(options => [options.id, options.name].filter(x => x !== undefined).length === 1, {
36
+ error: 'Specify either id or name, but not both'
37
+ })
38
+ .refine(options => !(options.userId && options.userName), {
39
+ error: 'Specify either userId or userName, but not both'
40
+ })
41
+ .refine(options => !(options.calendarGroupId && options.calendarGroupName), {
42
+ error: 'Specify either calendarGroupId or calendarGroupName, but not both'
43
+ });
44
+ }
45
+ async commandAction(logger, args) {
46
+ if (this.verbose) {
47
+ await logger.logToStderr('Getting calendar...');
48
+ }
49
+ try {
50
+ const userIdentifier = args.options.userId ?? args.options.userName;
51
+ let calendarGroupId = args.options.calendarGroupId;
52
+ if (args.options.calendarGroupName) {
53
+ const group = await calendarGroup.getUserCalendarGroupByName(userIdentifier, args.options.calendarGroupName, 'id');
54
+ calendarGroupId = group.id;
55
+ }
56
+ let result;
57
+ if (args.options.id) {
58
+ result = await calendar.getUserCalendarById(userIdentifier, args.options.id, calendarGroupId);
59
+ }
60
+ else {
61
+ result = await calendar.getUserCalendarByName(userIdentifier, args.options.name, calendarGroupId);
62
+ }
63
+ await logger.log(result);
64
+ }
65
+ catch (err) {
66
+ this.handleRejectedODataJsonPromise(err);
67
+ }
68
+ }
69
+ }
70
+ export default new OutlookCalendarGetCommand();
71
+ //# sourceMappingURL=calendar-get.js.map
@@ -0,0 +1,100 @@
1
+ import GraphCommand from '../../../base/GraphCommand.js';
2
+ import commands from '../../commands.js';
3
+ import { z } from 'zod';
4
+ import { globalOptionsZod } from '../../../../Command.js';
5
+ import { validation } from '../../../../utils/validation.js';
6
+ import { calendarGroup } from '../../../../utils/calendarGroup.js';
7
+ import { calendar } from '../../../../utils/calendar.js';
8
+ import { cli } from '../../../../cli/cli.js';
9
+ import request from '../../../../request.js';
10
+ export const options = z.strictObject({
11
+ ...globalOptionsZod.shape,
12
+ id: z.string().alias('i').optional(),
13
+ name: z.string().alias('n').optional(),
14
+ userId: z.string()
15
+ .refine(userId => validation.isValidGuid(userId), {
16
+ error: e => `'${e.input}' is not a valid GUID.`
17
+ }).optional(),
18
+ userName: z.string()
19
+ .refine(userName => validation.isValidUserPrincipalName(userName), {
20
+ error: e => `'${e.input}' is not a valid UPN.`
21
+ }).optional(),
22
+ calendarGroupId: z.string().optional(),
23
+ calendarGroupName: z.string().optional(),
24
+ permanent: z.boolean().optional(),
25
+ force: z.boolean().optional().alias('f')
26
+ });
27
+ class OutlookCalendarRemoveCommand extends GraphCommand {
28
+ get name() {
29
+ return commands.CALENDAR_REMOVE;
30
+ }
31
+ get description() {
32
+ return 'Removes the calendar of a user';
33
+ }
34
+ get schema() {
35
+ return options;
36
+ }
37
+ getRefinedSchema(schema) {
38
+ return schema
39
+ .refine(options => [options.id, options.name].filter(x => x !== undefined).length === 1, {
40
+ error: 'Specify either id or name, but not both'
41
+ })
42
+ .refine(options => [options.userId, options.userName].filter(x => x !== undefined).length === 1, {
43
+ error: 'Specify either userId or userName, but not both'
44
+ })
45
+ .refine(options => [options.calendarGroupId, options.calendarGroupName].filter(x => x !== undefined).length !== 2, {
46
+ error: 'Do not specify both calendarGroupId and calendarGroupName'
47
+ });
48
+ }
49
+ async commandAction(logger, args) {
50
+ const removeCalendar = async () => {
51
+ try {
52
+ const userIdentifier = args.options.userId ?? args.options.userName;
53
+ let calendarGroupId = args.options.calendarGroupId;
54
+ if (args.options.calendarGroupName) {
55
+ const group = await calendarGroup.getUserCalendarGroupByName(userIdentifier, args.options.calendarGroupName, 'id');
56
+ calendarGroupId = group.id;
57
+ }
58
+ let calendarId = args.options.id;
59
+ if (args.options.name) {
60
+ const result = await calendar.getUserCalendarByName(userIdentifier, args.options.name, calendarGroupId, 'id');
61
+ calendarId = result.id;
62
+ }
63
+ if (args.options.verbose) {
64
+ await logger.logToStderr(`Removing calendar with ID ${calendarId}...`);
65
+ }
66
+ let url = `${this.resource}/v1.0/users('${userIdentifier}')/${calendarGroupId ? `calendarGroups/${calendarGroupId}/` : ''}calendars/${calendarId}`;
67
+ if (args.options.permanent) {
68
+ url += '/permanentDelete';
69
+ }
70
+ const requestOptions = {
71
+ url: url,
72
+ headers: {
73
+ accept: 'application/json;odata.metadata=none'
74
+ }
75
+ };
76
+ if (args.options.permanent) {
77
+ await request.post(requestOptions);
78
+ }
79
+ else {
80
+ await request.delete(requestOptions);
81
+ }
82
+ }
83
+ catch (err) {
84
+ this.handleRejectedODataJsonPromise(err);
85
+ }
86
+ };
87
+ if (args.options.force) {
88
+ await removeCalendar();
89
+ }
90
+ else {
91
+ const calendarIdentifier = args.options.id ?? args.options.name;
92
+ const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove calendar '${calendarIdentifier}'?` });
93
+ if (result) {
94
+ await removeCalendar();
95
+ }
96
+ }
97
+ }
98
+ }
99
+ export default new OutlookCalendarRemoveCommand();
100
+ //# sourceMappingURL=calendar-remove.js.map
@@ -0,0 +1,103 @@
1
+ import auth from '../../../../Auth.js';
2
+ import request from '../../../../request.js';
3
+ import { accessToken } from '../../../../utils/accessToken.js';
4
+ import { validation } from '../../../../utils/validation.js';
5
+ import GraphCommand from '../../../base/GraphCommand.js';
6
+ import commands from '../../commands.js';
7
+ import { cli } from '../../../../cli/cli.js';
8
+ import { globalOptionsZod } from '../../../../Command.js';
9
+ import { z } from 'zod';
10
+ export const options = z.strictObject({
11
+ ...globalOptionsZod.shape,
12
+ id: z.string().alias('i'),
13
+ userId: z.string().refine(id => validation.isValidGuid(id), {
14
+ error: e => `'${e.input}' is not a valid GUID.`
15
+ }).optional(),
16
+ userName: z.string()
17
+ .refine(upn => validation.isValidUserPrincipalName(upn) === true, {
18
+ error: e => `'${e.input}' is not a valid user principal name for option 'userName'.`
19
+ })
20
+ .optional(),
21
+ comment: z.string().optional(),
22
+ force: z.boolean().optional().alias('f')
23
+ });
24
+ class OutlookEventCancelCommand extends GraphCommand {
25
+ get name() {
26
+ return commands.EVENT_CANCEL;
27
+ }
28
+ get description() {
29
+ return 'Cancels a calendar event';
30
+ }
31
+ get schema() {
32
+ return options;
33
+ }
34
+ getRefinedSchema(schema) {
35
+ return schema
36
+ .refine(options => !(options.userId && options.userName), {
37
+ error: `Specify either 'userId' or 'userName', but not both.`
38
+ });
39
+ }
40
+ async commandAction(logger, args) {
41
+ const isAppOnlyAccessToken = accessToken.isAppOnlyAccessToken(auth.connection.accessTokens[auth.defaultResource].accessToken);
42
+ let principalUrl = '';
43
+ const token = auth.connection.accessTokens[auth.defaultResource].accessToken;
44
+ if (isAppOnlyAccessToken) {
45
+ if (!args.options.userId && !args.options.userName) {
46
+ throw `The option 'userId' or 'userName' is required when cancelling an event using application permissions.`;
47
+ }
48
+ }
49
+ else {
50
+ if (args.options.userId) {
51
+ const currentUserId = accessToken.getUserIdFromAccessToken(token);
52
+ if (args.options.userId !== currentUserId) {
53
+ throw `You can only cancel your own events when using delegated permissions. The specified userId '${args.options.userId}' does not match the current user '${currentUserId}'.`;
54
+ }
55
+ }
56
+ if (args.options.userName) {
57
+ const currentUserName = accessToken.getUserNameFromAccessToken(token);
58
+ if (args.options.userName.toLowerCase() !== currentUserName.toLowerCase()) {
59
+ throw `You can only cancel your own events when using delegated permissions. The specified userName '${args.options.userName}' does not match the current user '${currentUserName}'.`;
60
+ }
61
+ }
62
+ }
63
+ if (args.options.userId || args.options.userName) {
64
+ const userIdentifier = args.options.userId ?? args.options.userName;
65
+ principalUrl += `users('${userIdentifier}')`;
66
+ }
67
+ else {
68
+ principalUrl += 'me';
69
+ }
70
+ const cancelEvent = async () => {
71
+ try {
72
+ if (this.verbose) {
73
+ await logger.logToStderr(`Cancelling event with id '${args.options.id}'...`);
74
+ }
75
+ const requestOptions = {
76
+ url: `${this.resource}/v1.0/${principalUrl}/events/${args.options.id}/cancel`,
77
+ headers: {
78
+ accept: 'application/json;odata.metadata=none',
79
+ 'content-type': 'application/json'
80
+ },
81
+ data: {
82
+ comment: args.options.comment
83
+ }
84
+ };
85
+ await request.post(requestOptions);
86
+ }
87
+ catch (err) {
88
+ this.handleRejectedODataJsonPromise(err);
89
+ }
90
+ };
91
+ if (args.options.force) {
92
+ await cancelEvent();
93
+ }
94
+ else {
95
+ const result = await cli.promptForConfirmation({ message: `Are you sure you want to cancel event with id '${args.options.id}'?` });
96
+ if (result) {
97
+ await cancelEvent();
98
+ }
99
+ }
100
+ }
101
+ }
102
+ export default new OutlookEventCancelCommand();
103
+ //# sourceMappingURL=event-cancel.js.map
@@ -0,0 +1,115 @@
1
+ import { z } from 'zod';
2
+ import { globalOptionsZod } from '../../../../Command.js';
3
+ import GraphCommand from '../../../base/GraphCommand.js';
4
+ import commands from '../../commands.js';
5
+ import { validation } from '../../../../utils/validation.js';
6
+ import { odata } from '../../../../utils/odata.js';
7
+ import { calendar } from '../../../../utils/calendar.js';
8
+ export const options = z.strictObject({
9
+ ...globalOptionsZod.shape,
10
+ userId: z.string().refine(id => validation.isValidGuid(id), {
11
+ error: e => `'${e.input}' is not a valid GUID.`
12
+ }).optional(),
13
+ userName: z.string().refine(name => validation.isValidUserPrincipalName(name), {
14
+ error: e => `'${e.input}' is not a valid UPN.`
15
+ }).optional(),
16
+ calendarId: z.string().optional(),
17
+ calendarName: z.string().optional(),
18
+ startDateTime: z.string().refine(date => validation.isValidISODateTime(date), {
19
+ error: e => `'${e.input}' is not a valid ISO date-time.`
20
+ }).optional(),
21
+ endDateTime: z.string().refine(date => validation.isValidISODateTime(date), {
22
+ error: e => `'${e.input}' is not a valid ISO date-time.`
23
+ }).optional(),
24
+ timeZone: z.string().optional(),
25
+ properties: z.string().optional(),
26
+ filter: z.string().optional()
27
+ });
28
+ class OutlookEventListCommand extends GraphCommand {
29
+ get name() {
30
+ return commands.EVENT_LIST;
31
+ }
32
+ get description() {
33
+ return 'Retrieves a list of events from a specific calendar of a user.';
34
+ }
35
+ get schema() {
36
+ return options;
37
+ }
38
+ getRefinedSchema(schema) {
39
+ return schema
40
+ .refine(options => [options.userId, options.userName].filter(x => x !== undefined).length === 1, {
41
+ error: 'Specify either userId or userName, but not both'
42
+ })
43
+ .refine(options => !(options.calendarId && options.calendarName), {
44
+ error: 'Specify either calendarId or calendarName, but not both.'
45
+ });
46
+ }
47
+ defaultProperties() {
48
+ return ['id', 'subject'];
49
+ }
50
+ async commandAction(logger, args) {
51
+ try {
52
+ if (this.verbose) {
53
+ await logger.logToStderr('Getting a list of the events...');
54
+ }
55
+ let events;
56
+ const endpoint = await this.getRequestUrl(args.options);
57
+ if (args.options.timeZone) {
58
+ const requestOptions = {
59
+ url: endpoint,
60
+ headers: {
61
+ accept: 'application/json;odata.metadata=none',
62
+ Prefer: `outlook.timezone="${args.options.timeZone}"`
63
+ },
64
+ responseType: 'json'
65
+ };
66
+ events = await odata.getAllItems(requestOptions);
67
+ }
68
+ else {
69
+ events = await odata.getAllItems(endpoint);
70
+ }
71
+ await logger.log(events);
72
+ }
73
+ catch (err) {
74
+ this.handleRejectedODataJsonPromise(err);
75
+ }
76
+ }
77
+ async getRequestUrl(options) {
78
+ const queryParameters = [];
79
+ if (options.properties) {
80
+ const allProperties = options.properties.split(',');
81
+ const selectProperties = allProperties.filter(prop => !prop.includes('/'));
82
+ const expandProperties = allProperties.filter(prop => prop.includes('/'));
83
+ if (selectProperties.length > 0) {
84
+ queryParameters.push(`$select=${selectProperties}`);
85
+ }
86
+ if (expandProperties.length > 0) {
87
+ const fieldExpands = expandProperties.map(p => `${p.split('/')[0]}($select=${p.split('/')[1]})`);
88
+ queryParameters.push(`$expand=${fieldExpands.join(',')}`);
89
+ }
90
+ }
91
+ if (options.filter || options.startDateTime || options.endDateTime) {
92
+ let filter = options.filter || '';
93
+ if (options.startDateTime) {
94
+ filter += `${filter ? ' and ' : ''}start/dateTime ge '${options.startDateTime}'`;
95
+ }
96
+ if (options.endDateTime) {
97
+ filter += `${filter ? ' and ' : ''}start/dateTime lt '${options.endDateTime}'`;
98
+ }
99
+ queryParameters.push(`$filter=${filter}`);
100
+ }
101
+ const queryString = queryParameters.length > 0
102
+ ? `?${queryParameters.join('&')}`
103
+ : '';
104
+ const userIdentifier = options.userId ?? options.userName;
105
+ let calendarId = options.calendarId;
106
+ if (options.calendarName) {
107
+ calendarId = (await calendar.getUserCalendarByName(userIdentifier, options.calendarName)).id;
108
+ }
109
+ return calendarId
110
+ ? `${this.resource}/v1.0/users('${userIdentifier}')/calendars/${calendarId}/events${queryString}`
111
+ : `${this.resource}/v1.0/users('${userIdentifier}')/events${queryString}`;
112
+ }
113
+ }
114
+ export default new OutlookEventListCommand();
115
+ //# sourceMappingURL=event-list.js.map
@@ -0,0 +1,104 @@
1
+ import auth from '../../../../Auth.js';
2
+ import request from '../../../../request.js';
3
+ import { accessToken } from '../../../../utils/accessToken.js';
4
+ import { validation } from '../../../../utils/validation.js';
5
+ import GraphCommand from '../../../base/GraphCommand.js';
6
+ import commands from '../../commands.js';
7
+ import { cli } from '../../../../cli/cli.js';
8
+ import { globalOptionsZod } from '../../../../Command.js';
9
+ import { z } from 'zod';
10
+ export const options = z.strictObject({
11
+ ...globalOptionsZod.shape,
12
+ id: z.string().alias('i'),
13
+ userId: z.string().refine(id => validation.isValidGuid(id), {
14
+ error: e => `'${e.input}' is not a valid GUID.`
15
+ }).optional(),
16
+ userName: z.string()
17
+ .refine(upn => validation.isValidUserPrincipalName(upn) === true, {
18
+ error: e => `'${e.input}' is not a valid user principal name for option 'userName'.`
19
+ })
20
+ .optional(),
21
+ permanent: z.boolean().optional(),
22
+ force: z.boolean().optional().alias('f')
23
+ });
24
+ class OutlookEventRemoveCommand extends GraphCommand {
25
+ get name() {
26
+ return commands.EVENT_REMOVE;
27
+ }
28
+ get description() {
29
+ return 'Removes an event from a calendar';
30
+ }
31
+ get schema() {
32
+ return options;
33
+ }
34
+ getRefinedSchema(schema) {
35
+ return schema.refine(options => !options.userId || !options.userName, {
36
+ error: 'Specify either userId or userName, but not both.'
37
+ });
38
+ }
39
+ async commandAction(logger, args) {
40
+ const isAppOnlyAccessToken = accessToken.isAppOnlyAccessToken(auth.connection.accessTokens[auth.defaultResource].accessToken);
41
+ const token = auth.connection.accessTokens[auth.defaultResource].accessToken;
42
+ if (isAppOnlyAccessToken) {
43
+ if (!args.options.userId && !args.options.userName) {
44
+ throw `The option 'userId' or 'userName' is required when removing an event using application permissions.`;
45
+ }
46
+ }
47
+ else {
48
+ if (args.options.userId) {
49
+ const currentUserId = accessToken.getUserIdFromAccessToken(token);
50
+ if (args.options.userId !== currentUserId) {
51
+ throw `You can only remove your own events when using delegated permissions. The specified userId '${args.options.userId}' does not match the current user '${currentUserId}'.`;
52
+ }
53
+ }
54
+ if (args.options.userName) {
55
+ const currentUserName = accessToken.getUserNameFromAccessToken(token);
56
+ if (args.options.userName.toLowerCase() !== currentUserName.toLowerCase()) {
57
+ throw `You can only remove your own events when using delegated permissions. The specified userName '${args.options.userName}' does not match the current user '${currentUserName}'.`;
58
+ }
59
+ }
60
+ }
61
+ let principalUrl = '';
62
+ const userIdentifier = args.options.userId ?? args.options.userName;
63
+ if (userIdentifier) {
64
+ principalUrl += `users('${userIdentifier}')`;
65
+ }
66
+ else {
67
+ principalUrl += 'me';
68
+ }
69
+ const removeEvent = async () => {
70
+ try {
71
+ if (this.verbose) {
72
+ await logger.logToStderr(`Removing event with id '${args.options.id}'...`);
73
+ }
74
+ const requestOptions = {
75
+ url: `${this.resource}/v1.0/${principalUrl}/events/${args.options.id}`,
76
+ headers: {
77
+ accept: 'application/json;odata.metadata=none'
78
+ }
79
+ };
80
+ if (args.options.permanent) {
81
+ requestOptions.url += '/permanentDelete';
82
+ await request.post(requestOptions);
83
+ }
84
+ else {
85
+ await request.delete(requestOptions);
86
+ }
87
+ }
88
+ catch (err) {
89
+ this.handleRejectedODataJsonPromise(err);
90
+ }
91
+ };
92
+ if (args.options.force) {
93
+ await removeEvent();
94
+ }
95
+ else {
96
+ const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove event with id '${args.options.id}'?` });
97
+ if (result) {
98
+ await removeEvent();
99
+ }
100
+ }
101
+ }
102
+ }
103
+ export default new OutlookEventRemoveCommand();
104
+ //# sourceMappingURL=event-remove.js.map