@pnp/cli-microsoft365 4.4.0-beta.23194d7 → 4.4.0-beta.3913c30

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.
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AppliedCategories.js.map
@@ -0,0 +1,357 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const request_1 = require("../../../../request");
4
+ const Utils_1 = require("../../../../Utils");
5
+ const GraphCommand_1 = require("../../../base/GraphCommand");
6
+ const commands_1 = require("../../commands");
7
+ class PlannerTaskSetCommand extends GraphCommand_1.default {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.allowedAppliedCategories = ['category1', 'category2', 'category3', 'category4', 'category5', 'category6'];
11
+ }
12
+ get name() {
13
+ return commands_1.default.TASK_SET;
14
+ }
15
+ get description() {
16
+ return 'Updates a Microsoft Planner Task';
17
+ }
18
+ getTelemetryProperties(args) {
19
+ const telemetryProps = super.getTelemetryProperties(args);
20
+ telemetryProps.title = typeof args.options.title !== 'undefined';
21
+ telemetryProps.planId = typeof args.options.planId !== 'undefined';
22
+ telemetryProps.planName = typeof args.options.planName !== 'undefined';
23
+ telemetryProps.ownerGroupId = typeof args.options.ownerGroupId !== 'undefined';
24
+ telemetryProps.ownerGroupName = typeof args.options.ownerGroupName !== 'undefined';
25
+ telemetryProps.bucketId = typeof args.options.bucketId !== 'undefined';
26
+ telemetryProps.bucketName = typeof args.options.bucketName !== 'undefined';
27
+ telemetryProps.startDateTime = typeof args.options.startDateTime !== 'undefined';
28
+ telemetryProps.dueDateTime = typeof args.options.dueDateTime !== 'undefined';
29
+ telemetryProps.percentComplete = typeof args.options.percentComplete !== 'undefined';
30
+ telemetryProps.assignedToUserIds = typeof args.options.assignedToUserIds !== 'undefined';
31
+ telemetryProps.assignedToUserNames = typeof args.options.assignedToUserNames !== 'undefined';
32
+ telemetryProps.assigneePriority = typeof args.options.assigneePriority !== 'undefined';
33
+ telemetryProps.description = typeof args.options.description !== 'undefined';
34
+ telemetryProps.appliedCategories = typeof args.options.appliedCategories !== 'undefined';
35
+ telemetryProps.orderHint = typeof args.options.orderHint !== 'undefined';
36
+ return telemetryProps;
37
+ }
38
+ commandAction(logger, args, cb) {
39
+ this
40
+ .getBucketId(args.options)
41
+ .then(bucketId => {
42
+ this.bucketId = bucketId;
43
+ return this.generateUserAssignments(args.options);
44
+ })
45
+ .then(resultAssignments => {
46
+ this.assignments = resultAssignments;
47
+ return this.getTaskEtag(args.options.id);
48
+ })
49
+ .then(etag => {
50
+ const appliedCategories = this.generateAppliedCategories(args.options);
51
+ const data = this.mapRequestBody(args.options, appliedCategories);
52
+ const requestOptions = {
53
+ url: `${this.resource}/v1.0/planner/tasks/${args.options.id}`,
54
+ headers: {
55
+ 'accept': 'application/json;odata.metadata=none',
56
+ 'If-Match': etag,
57
+ 'Prefer': 'return=representation'
58
+ },
59
+ responseType: 'json',
60
+ data: data
61
+ };
62
+ return request_1.default.patch(requestOptions);
63
+ })
64
+ .then(newTask => this.updateTaskDetails(args.options, newTask))
65
+ .then((res) => {
66
+ logger.log(res);
67
+ cb();
68
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
69
+ }
70
+ updateTaskDetails(options, newTask) {
71
+ if (!options.description) {
72
+ return Promise.resolve(newTask);
73
+ }
74
+ const taskId = newTask.id;
75
+ return this
76
+ .getTaskDetailsEtag(taskId)
77
+ .then(etag => {
78
+ const requestOptionsTaskDetails = {
79
+ url: `${this.resource}/v1.0/planner/tasks/${taskId}/details`,
80
+ headers: {
81
+ 'accept': 'application/json;odata.metadata=none',
82
+ 'If-Match': etag,
83
+ 'Prefer': 'return=representation'
84
+ },
85
+ responseType: 'json',
86
+ data: {
87
+ description: options.description
88
+ }
89
+ };
90
+ return request_1.default.patch(requestOptionsTaskDetails);
91
+ })
92
+ .then(taskDetails => {
93
+ return Object.assign(Object.assign({}, newTask), taskDetails);
94
+ });
95
+ }
96
+ getTaskDetailsEtag(taskId) {
97
+ const requestOptions = {
98
+ url: `${this.resource}/v1.0/planner/tasks/${encodeURIComponent(taskId)}/details`,
99
+ headers: {
100
+ accept: 'application/json'
101
+ },
102
+ responseType: 'json'
103
+ };
104
+ return request_1.default
105
+ .get(requestOptions)
106
+ .then((response) => {
107
+ const etag = response ? response['@odata.etag'] : undefined;
108
+ if (!etag) {
109
+ return Promise.reject(`Error fetching task details`);
110
+ }
111
+ return Promise.resolve(etag);
112
+ });
113
+ }
114
+ getTaskEtag(taskId) {
115
+ const requestOptions = {
116
+ url: `${this.resource}/v1.0/planner/tasks/${encodeURIComponent(taskId)}`,
117
+ headers: {
118
+ accept: 'application/json'
119
+ },
120
+ responseType: 'json'
121
+ };
122
+ return request_1.default
123
+ .get(requestOptions)
124
+ .then((response) => {
125
+ const etag = response ? response['@odata.etag'] : undefined;
126
+ if (!etag) {
127
+ return Promise.reject(`Error fetching task`);
128
+ }
129
+ return Promise.resolve(etag);
130
+ });
131
+ }
132
+ generateAppliedCategories(options) {
133
+ if (!options.appliedCategories) {
134
+ return {};
135
+ }
136
+ const categories = {};
137
+ options.appliedCategories.toLocaleLowerCase().split(',').forEach(x => categories[x] = true);
138
+ return categories;
139
+ }
140
+ generateUserAssignments(options) {
141
+ const assignments = {};
142
+ if (!options.assignedToUserIds && !options.assignedToUserNames) {
143
+ return Promise.resolve(assignments);
144
+ }
145
+ return this
146
+ .getUserIds(options)
147
+ .then((userIds) => {
148
+ userIds.forEach(x => assignments[x] = {
149
+ '@odata.type': '#microsoft.graph.plannerAssignment',
150
+ orderHint: ' !'
151
+ });
152
+ return Promise.resolve(assignments);
153
+ });
154
+ }
155
+ getUserIds(options) {
156
+ if (options.assignedToUserIds) {
157
+ return Promise.resolve(options.assignedToUserIds.split(',').map(o => o.trim()));
158
+ }
159
+ // Hitting this section means assignedToUserNames won't be undefined
160
+ const userNames = options.assignedToUserNames;
161
+ const userArr = userNames.split(',').map(o => o.trim());
162
+ let userIds = [];
163
+ const promises = userArr.map(user => {
164
+ const requestOptions = {
165
+ url: `${this.resource}/v1.0/users?$filter=userPrincipalName eq '${Utils_1.default.encodeQueryParameter(user)}'&$select=id,userPrincipalName`,
166
+ headers: {
167
+ 'accept ': 'application/json;odata.metadata=none'
168
+ },
169
+ responseType: 'json'
170
+ };
171
+ return request_1.default.get(requestOptions);
172
+ });
173
+ return Promise
174
+ .all(promises)
175
+ .then((usersRes) => {
176
+ let userUpns = [];
177
+ userUpns = usersRes.map(res => { var _a; return (_a = res.value[0]) === null || _a === void 0 ? void 0 : _a.userPrincipalName; });
178
+ userIds = usersRes.map(res => { var _a; return (_a = res.value[0]) === null || _a === void 0 ? void 0 : _a.id; });
179
+ // Find the members where no graph response was found
180
+ const invalidUsers = userArr.filter(user => !userUpns.some((upn) => (upn === null || upn === void 0 ? void 0 : upn.toLowerCase()) === user.toLowerCase()));
181
+ if (invalidUsers && invalidUsers.length > 0) {
182
+ return Promise.reject(`Cannot proceed with planner task update. The following users provided are invalid : ${invalidUsers.join(',')}`);
183
+ }
184
+ return Promise.resolve(userIds);
185
+ });
186
+ }
187
+ getBucketId(options) {
188
+ if (options.bucketId) {
189
+ return Promise.resolve(options.bucketId);
190
+ }
191
+ if (!options.bucketName) {
192
+ return Promise.resolve(undefined);
193
+ }
194
+ return this
195
+ .getPlanId(options)
196
+ .then(planId => {
197
+ const requestOptions = {
198
+ url: `${this.resource}/v1.0/planner/plans/${planId}/buckets?$select=id,name`,
199
+ headers: {
200
+ accept: 'application/json;odata.metadata=none'
201
+ },
202
+ responseType: 'json'
203
+ };
204
+ return request_1.default.get(requestOptions);
205
+ })
206
+ .then((response) => {
207
+ const bucket = response.value.find(val => val.name === options.bucketName);
208
+ if (!bucket) {
209
+ return Promise.reject(`The specified bucket does not exist`);
210
+ }
211
+ return Promise.resolve(bucket.id);
212
+ });
213
+ }
214
+ getPlanId(options) {
215
+ if (options.planId) {
216
+ return Promise.resolve(options.planId);
217
+ }
218
+ return this
219
+ .getGroupId(options)
220
+ .then((groupId) => {
221
+ const requestOptions = {
222
+ url: `${this.resource}/v1.0/planner/plans?$filter=(owner eq '${groupId}')&$select=id,title`,
223
+ headers: {
224
+ accept: 'application/json;odata.metadata=none'
225
+ },
226
+ responseType: 'json'
227
+ };
228
+ return request_1.default.get(requestOptions);
229
+ })
230
+ .then((response) => {
231
+ const plan = response.value.find(val => val.title === options.planName);
232
+ if (!plan) {
233
+ return Promise.reject(`The specified plan does not exist`);
234
+ }
235
+ return Promise.resolve(plan.id);
236
+ });
237
+ }
238
+ getGroupId(options) {
239
+ if (options.ownerGroupId) {
240
+ return Promise.resolve(options.ownerGroupId);
241
+ }
242
+ const requestOptions = {
243
+ url: `${this.resource}/v1.0/groups?$filter=displayName eq '${encodeURIComponent(options.ownerGroupName)}'&$select=id`,
244
+ headers: {
245
+ accept: 'application/json;odata.metadata=none'
246
+ },
247
+ responseType: 'json'
248
+ };
249
+ return request_1.default
250
+ .get(requestOptions)
251
+ .then(response => {
252
+ const group = response.value[0];
253
+ if (!group) {
254
+ return Promise.reject(`The specified owner group does not exist`);
255
+ }
256
+ return Promise.resolve(group.id);
257
+ });
258
+ }
259
+ mapRequestBody(options, appliedCategories) {
260
+ const requestBody = {};
261
+ if (options.title) {
262
+ requestBody.title = options.title;
263
+ }
264
+ if (this.bucketId) {
265
+ requestBody.bucketId = this.bucketId;
266
+ }
267
+ if (options.startDateTime) {
268
+ requestBody.startDateTime = options.startDateTime;
269
+ }
270
+ if (options.dueDateTime) {
271
+ requestBody.dueDateTime = options.dueDateTime;
272
+ }
273
+ if (options.percentComplete) {
274
+ requestBody.percentComplete = options.percentComplete;
275
+ }
276
+ if (this.assignments && Object.keys(this.assignments).length > 0) {
277
+ requestBody.assignments = this.assignments;
278
+ }
279
+ if (options.assigneePriority) {
280
+ requestBody.assigneePriority = options.assigneePriority;
281
+ }
282
+ if (appliedCategories && Object.keys(appliedCategories).length > 0) {
283
+ requestBody.appliedCategories = appliedCategories;
284
+ }
285
+ if (options.orderHint) {
286
+ requestBody.orderHint = options.orderHint;
287
+ }
288
+ return requestBody;
289
+ }
290
+ options() {
291
+ const options = [
292
+ { option: '-i, --id <id>' },
293
+ { option: '-t, --title [title]' },
294
+ { option: '--planId [planId]' },
295
+ { option: '--planName [planName]' },
296
+ { option: '--ownerGroupId [ownerGroupId]' },
297
+ { option: '--ownerGroupName [ownerGroupName]' },
298
+ { option: '--bucketId [bucketId]' },
299
+ { option: '--bucketName [bucketName]' },
300
+ { option: '--startDateTime [startDateTime]' },
301
+ { option: '--dueDateTime [dueDateTime]' },
302
+ { option: '--percentComplete [percentComplete]' },
303
+ { option: '--assignedToUserIds [assignedToUserIds]' },
304
+ { option: '--assignedToUserNames [assignedToUserNames]' },
305
+ { option: '--assigneePriority [assigneePriority]' },
306
+ { option: '--description [description]' },
307
+ { option: '--appliedCategories [appliedCategories]' },
308
+ { option: '--orderHint [orderHint]' }
309
+ ];
310
+ const parentOptions = super.options();
311
+ return options.concat(parentOptions);
312
+ }
313
+ validate(args) {
314
+ if (args.options.bucketId && args.options.bucketName) {
315
+ return 'Specify either bucketId or bucketName but not both';
316
+ }
317
+ if (args.options.bucketName && !args.options.planId && !args.options.planName) {
318
+ return 'Specify either planId or planName when using bucketName';
319
+ }
320
+ if (args.options.bucketName && args.options.planId && args.options.planName) {
321
+ return 'Specify either planId or planName when using bucketName but not both';
322
+ }
323
+ if (args.options.planName && !args.options.ownerGroupId && !args.options.ownerGroupName) {
324
+ return 'Specify either ownerGroupId or ownerGroupName when using planName';
325
+ }
326
+ if (args.options.planName && args.options.ownerGroupId && args.options.ownerGroupName) {
327
+ return 'Specify either ownerGroupId or ownerGroupName when using planName but not both';
328
+ }
329
+ if (args.options.ownerGroupId && !Utils_1.default.isValidGuid(args.options.ownerGroupId)) {
330
+ return `${args.options.ownerGroupId} is not a valid GUID`;
331
+ }
332
+ if (args.options.startDateTime && !Utils_1.default.isValidISODateTime(args.options.startDateTime)) {
333
+ return 'The startDateTime is not a valid ISO date string';
334
+ }
335
+ if (args.options.dueDateTime && !Utils_1.default.isValidISODateTime(args.options.dueDateTime)) {
336
+ return 'The dueDateTime is not a valid ISO date string';
337
+ }
338
+ if (args.options.percentComplete && isNaN(args.options.percentComplete)) {
339
+ return `percentComplete is not a number`;
340
+ }
341
+ if (args.options.percentComplete && (args.options.percentComplete < 0 || args.options.percentComplete > 100)) {
342
+ return `percentComplete should be between 0 and 100`;
343
+ }
344
+ if (args.options.assignedToUserIds && !Utils_1.default.isValidGuidArray(args.options.assignedToUserIds.split(','))) {
345
+ return 'assignedToUserIds contains invalid GUID';
346
+ }
347
+ if (args.options.assignedToUserIds && args.options.assignedToUserNames) {
348
+ return 'Specify either assignedToUserIds or assignedToUserNames but not both';
349
+ }
350
+ if (args.options.appliedCategories && args.options.appliedCategories.split(',').filter(category => this.allowedAppliedCategories.indexOf(category.toLocaleLowerCase()) < 0).length !== 0) {
351
+ return 'The appliedCategories contains invalid value. Specify either category1, category2, category3, category4, category5 and/or category6 as properties';
352
+ }
353
+ return true;
354
+ }
355
+ }
356
+ module.exports = new PlannerTaskSetCommand();
357
+ //# sourceMappingURL=task-set.js.map
@@ -8,6 +8,7 @@ exports.default = {
8
8
  PLAN_GET: `${prefix} plan get`,
9
9
  PLAN_LIST: `${prefix} plan list`,
10
10
  TASK_ADD: `${prefix} task add`,
11
- TASK_LIST: `${prefix} task list`
11
+ TASK_LIST: `${prefix} task list`,
12
+ TASK_SET: `${prefix} task set`
12
13
  };
13
14
  //# sourceMappingURL=commands.js.map
@@ -0,0 +1,99 @@
1
+ # planner task set
2
+
3
+ Updates a Microsoft Planner task
4
+
5
+ ## Usage
6
+
7
+ ```sh
8
+ m365 planner task set [options]
9
+ ```
10
+
11
+ ## Options
12
+
13
+ `-i, --id <id>`
14
+ : ID of the task.
15
+
16
+ `-t, --title [title]`
17
+ : New title of the task.
18
+
19
+ `--bucketId [bucketId]`
20
+ : ID of the bucket to move the task to. Specify either `bucketId` or `bucketName` but not both.
21
+
22
+ `--bucketName [bucketName]`
23
+ : Name of the bucket to move the task to. The bucket needs to exist in the selected plan. Specify either `bucketId` or `bucketName` but not both.
24
+
25
+ `--planId [planId]`
26
+ : ID of the plan to move the task to. Specify either `planId` or `planName` but not both.
27
+
28
+ `--planName [planName]`
29
+ : Name of the plan to move the task to. Specify either `planId` or `planName` but not both.
30
+
31
+ `--ownerGroupId [ownerGroupId]`
32
+ : ID of the group to which the plan belongs. Specify `ownerGroupId` or `ownerGroupName` when using `planName`.
33
+
34
+ `--ownerGroupName [ownerGroupName]`
35
+ : Name of the group to which the plan belongs. Specify `ownerGroupId` or `ownerGroupName` when using `planName`.
36
+
37
+ `--startDateTime [startDateTime]`
38
+ : The date and time when the task started. This should be defined as a valid ISO 8601 string. `2021-12-16T18:28:48.6964197Z`
39
+
40
+ `--dueDateTime [dueDateTime]`
41
+ : The date and time when the task is due. This should be defined as a valid ISO 8601 string. `2021-12-16T18:28:48.6964197Z`
42
+
43
+ `--percentComplete [percentComplete]`
44
+ : Percentage of task completion. Number between 0 and 100.
45
+
46
+ `--assignedToUserIds [assignedToUserIds]`
47
+ : Comma-separated IDs of the assignees that should be added to the task assignment. Specify either `assignedToUserIds` or `assignedToUserNames` but not both.
48
+
49
+ `--assignedToUserNames [assignedToUserNames]`
50
+ : Comma-separated UPNs of the assignees that should be added to the task assignment. Specify either `assignedToUserIds` or `assignedToUserNames` but not both.
51
+
52
+ `--description [description]`
53
+ : Description of the task
54
+
55
+ `--orderHint [orderHint]`
56
+ : Hint used to order items of this type in a list view
57
+
58
+ `--assigneePriority [assigneePriority]`
59
+ : Hint used to order items of this type in a list view
60
+
61
+ `--appliedCategories [appliedCategories]`
62
+ : Comma-separated categories that should be added to the task
63
+
64
+ --8<-- "docs/cmd/_global.md"
65
+
66
+ ## Remarks
67
+
68
+ When you specify the value for `percentageComplete`, consider the following:
69
+
70
+ - when set to 0, the task is considered _Not started_
71
+ - when set between 1 and 99, the task is considered _In progress_
72
+ - when set to 100, the task is considered _Completed_
73
+
74
+ You can add up to 6 categories to the task. An example to add _category1_ and _category3_ would be `category1,category3`.
75
+
76
+ ## Examples
77
+
78
+ Updates a Microsoft Planner task name to _My Planner Task_ for the task with the ID _Z-RLQGfppU6H3663DBzfs5gAMD3o_
79
+
80
+ ```sh
81
+ m365 planner task set --id "Z-RLQGfppU6H3663DBzfs5gAMD3o" --title "My Planner Task"
82
+ ```
83
+
84
+ Moves a Microsoft Planner task with the ID _Z-RLQGfppU6H3663DBzfs5gAMD3o_ to the bucket named _My Planner Bucket_. Based on the plan with the name _My Planner Plan_ owned by the group _My Planner Group_
85
+
86
+ ```sh
87
+ m365 planner task set --id "2Vf8JHgsBUiIf-nuvBtv-ZgAAYw2" --bucketName "My Planner Bucket" --planName "My Planner Plan" --ownerGroupName "My Planner Group"
88
+ ```
89
+
90
+ Marks a Microsoft Planner task with the ID _Z-RLQGfppU6H3663DBzfs5gAMD3o_ as 50% complete and assigned to categories 1 and 3.
91
+
92
+ ```sh
93
+ m365 planner task set --id "2Vf8JHgsBUiIf-nuvBtv-ZgAAYw2" --percentComplete 50 --appliedCategories "category1,category3"
94
+ ```
95
+
96
+ ## Additional information
97
+
98
+ - Using order hints in Planner: [https://docs.microsoft.com/graph/api/resources/planner-order-hint-format?view=graph-rest-1.0](https://docs.microsoft.com/graph/api/resources/planner-order-hint-format?view=graph-rest-1.0)
99
+ - Applied categories in Planner: [https://docs.microsoft.com/graph/api/resources/plannerappliedcategories?view=graph-rest-1.0](https://docs.microsoft.com/en-us/graph/api/resources/plannerappliedcategories?view=graph-rest-1.0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "4.4.0-beta.23194d7",
3
+ "version": "4.4.0-beta.3913c30",
4
4
  "description": "Manage Microsoft 365 and SharePoint Framework projects on any platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",