@pnp/cli-microsoft365 5.2.0-beta.dc50ce6 → 5.3.0-beta.95db8d3

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 (41) hide show
  1. package/.eslintrc.js +1 -0
  2. package/dist/m365/aad/commands/approleassignment/approleassignment-list.js +55 -22
  3. package/dist/m365/aad/commands.js +1 -1
  4. package/dist/m365/app/commands/app-open.js +64 -0
  5. package/dist/m365/app/commands.js +1 -0
  6. package/dist/m365/planner/commands/bucket/bucket-get.js +198 -0
  7. package/dist/m365/planner/commands/bucket/bucket-remove.js +214 -0
  8. package/dist/m365/planner/commands/bucket/bucket-set.js +208 -0
  9. package/dist/m365/planner/commands/task/task-get.js +150 -7
  10. package/dist/m365/planner/commands.js +3 -0
  11. package/dist/m365/spfx/commands/project/project-upgrade/{upgrade-1.15.0-beta.1.js → upgrade-1.15.0-beta.6.js} +27 -27
  12. package/dist/m365/spfx/commands/project/project-upgrade.js +1 -1
  13. package/dist/m365/spfx/commands/spfx-doctor.js +1 -105
  14. package/dist/m365/spo/commands/field/field-list.js +84 -0
  15. package/dist/m365/spo/commands/list/list-roleinheritance-break.js +84 -0
  16. package/dist/m365/spo/commands/list/list-roleinheritance-reset.js +76 -0
  17. package/dist/m365/spo/commands/roledefinition/roledefinition-list.js +49 -0
  18. package/dist/m365/spo/commands.js +4 -0
  19. package/dist/m365/teams/commands/channel/channel-member-remove.js +214 -0
  20. package/dist/m365/teams/commands.js +2 -0
  21. package/dist/m365/tenant/commands/security/security-alerts-list.js +71 -0
  22. package/dist/m365/tenant/commands.js +1 -0
  23. package/docs/docs/cmd/app/app-open.md +45 -0
  24. package/docs/docs/cmd/planner/bucket/bucket-get.md +57 -0
  25. package/docs/docs/cmd/planner/bucket/bucket-remove.md +60 -0
  26. package/docs/docs/cmd/planner/bucket/bucket-set.md +57 -0
  27. package/docs/docs/cmd/planner/task/task-get.md +30 -3
  28. package/docs/docs/cmd/planner/task/task-set.md +2 -2
  29. package/docs/docs/cmd/spfx/project/project-upgrade.md +1 -1
  30. package/docs/docs/cmd/spfx/spfx-doctor.md +1 -1
  31. package/docs/docs/cmd/spo/field/field-list.md +51 -0
  32. package/docs/docs/cmd/spo/list/list-roleinheritance-break.md +55 -0
  33. package/docs/docs/cmd/spo/list/list-roleinheritance-reset.md +36 -0
  34. package/docs/docs/cmd/spo/listitem/listitem-list.md +2 -2
  35. package/docs/docs/cmd/spo/roledefinition/roledefinition-list.md +24 -0
  36. package/docs/docs/cmd/teams/channel/channel-member-list.md +4 -4
  37. package/docs/docs/cmd/teams/channel/channel-member-remove.md +57 -0
  38. package/docs/docs/cmd/teams/channel/channel-member-set.md +2 -2
  39. package/docs/docs/cmd/tenant/security/security-alerts-list.md +30 -0
  40. package/npm-shrinkwrap.json +1517 -1284
  41. package/package.json +26 -24
package/.eslintrc.js CHANGED
@@ -29,6 +29,7 @@ const dictionary = [
29
29
  'home',
30
30
  'hub',
31
31
  'in',
32
+ 'inheritance',
32
33
  'init',
33
34
  'install',
34
35
  'installed',
@@ -22,29 +22,14 @@ class AadAppRoleAssignmentListCommand extends GraphCommand_1.default {
22
22
  return ['resourceDisplayName', 'roleName'];
23
23
  }
24
24
  commandAction(logger, args, cb) {
25
- let sp;
26
- // get the service principal associated with the appId
27
- let spMatchQuery = '';
28
- if (args.options.appId) {
29
- spMatchQuery = `appId eq '${encodeURIComponent(args.options.appId)}'`;
30
- }
31
- else if (args.options.objectId) {
32
- spMatchQuery = `id eq '${encodeURIComponent(args.options.objectId)}'`;
33
- }
34
- else {
35
- spMatchQuery = `displayName eq '${encodeURIComponent(args.options.displayName)}'`;
36
- }
37
- this
38
- .getServicePrincipalForApp(spMatchQuery)
39
- .then((resp) => {
40
- if (!resp.value.length) {
41
- return Promise.reject('app registration not found');
42
- }
43
- sp = resp.value[0];
25
+ let spAppRoleAssignments;
26
+ this.getAppRoleAssignments(args.options)
27
+ .then((appRoleAssignments) => {
28
+ spAppRoleAssignments = appRoleAssignments;
44
29
  // the role assignment has an appRoleId but no name. To get the name,
45
30
  // we need to get all the roles from the resource. the resource is
46
31
  // a service principal. Multiple roles may have same resource id.
47
- const resourceIds = sp.appRoleAssignments.map((item) => item.resourceId);
32
+ const resourceIds = appRoleAssignments.map((item) => item.resourceId);
48
33
  const tasks = [];
49
34
  for (let i = 0; i < resourceIds.length; i++) {
50
35
  tasks.push(this.getServicePrincipal(resourceIds[i]));
@@ -55,7 +40,7 @@ class AadAppRoleAssignmentListCommand extends GraphCommand_1.default {
55
40
  // loop through all appRoleAssignments for the servicePrincipal
56
41
  // and lookup the appRole.Id in the resources[resourceId].appRoles array...
57
42
  const results = [];
58
- sp.appRoleAssignments.map((appRoleAssignment) => {
43
+ spAppRoleAssignments.map((appRoleAssignment) => {
59
44
  const resource = resources.find((r) => r.id === appRoleAssignment.resourceId);
60
45
  if (resource) {
61
46
  const appRole = resource.appRoles.find((r) => r.id === appRoleAssignment.appRoleId);
@@ -65,7 +50,9 @@ class AadAppRoleAssignmentListCommand extends GraphCommand_1.default {
65
50
  resourceDisplayName: appRoleAssignment.resourceDisplayName,
66
51
  resourceId: appRoleAssignment.resourceId,
67
52
  roleId: appRole.id,
68
- roleName: appRole.value
53
+ roleName: appRole.value,
54
+ created: appRoleAssignment.createdDateTime,
55
+ deleted: appRoleAssignment.deletedDateTime
69
56
  });
70
57
  }
71
58
  }
@@ -74,6 +61,52 @@ class AadAppRoleAssignmentListCommand extends GraphCommand_1.default {
74
61
  cb();
75
62
  }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
76
63
  }
64
+ getAppRoleAssignments(argOptions) {
65
+ return new Promise((resolve, reject) => {
66
+ if (argOptions.objectId) {
67
+ this.getSPAppRoleAssignments(argOptions.objectId)
68
+ .then((spAppRoleAssignments) => {
69
+ if (!spAppRoleAssignments.value.length) {
70
+ reject('no app role assignments found');
71
+ }
72
+ resolve(spAppRoleAssignments.value);
73
+ })
74
+ .catch((err) => {
75
+ reject(err);
76
+ });
77
+ }
78
+ else {
79
+ // Use existing way to get service principal object
80
+ let spMatchQuery = '';
81
+ if (argOptions.appId) {
82
+ spMatchQuery = `appId eq '${encodeURIComponent(argOptions.appId)}'`;
83
+ }
84
+ else {
85
+ spMatchQuery = `displayName eq '${encodeURIComponent(argOptions.displayName)}'`;
86
+ }
87
+ this.getServicePrincipalForApp(spMatchQuery)
88
+ .then((resp) => {
89
+ if (!resp.value.length) {
90
+ reject('app registration not found');
91
+ }
92
+ resolve(resp.value[0].appRoleAssignments);
93
+ })
94
+ .catch((err) => {
95
+ reject(err);
96
+ });
97
+ }
98
+ });
99
+ }
100
+ getSPAppRoleAssignments(spId) {
101
+ const spRequestOptions = {
102
+ url: `${this.resource}/v1.0/servicePrincipals/${spId}/appRoleAssignments`,
103
+ headers: {
104
+ accept: 'application/json'
105
+ },
106
+ responseType: 'json'
107
+ };
108
+ return request_1.default.get(spRequestOptions);
109
+ }
77
110
  getServicePrincipalForApp(filterParam) {
78
111
  const spRequestOptions = {
79
112
  url: `${this.resource}/v1.0/servicePrincipals?$expand=appRoleAssignments&$filter=${filterParam}`,
@@ -6,11 +6,11 @@ exports.default = {
6
6
  APP_DELETE: `${prefix} app delete`,
7
7
  APP_GET: `${prefix} app get`,
8
8
  APP_REMOVE: `${prefix} app remove`,
9
- APP_SET: `${prefix} app set`,
10
9
  APP_ROLE_ADD: `${prefix} app role add`,
11
10
  APP_ROLE_DELETE: `${prefix} app role delete`,
12
11
  APP_ROLE_LIST: `${prefix} app role list`,
13
12
  APP_ROLE_REMOVE: `${prefix} app role remove`,
13
+ APP_SET: `${prefix} app set`,
14
14
  APPROLEASSIGNMENT_ADD: `${prefix} approleassignment add`,
15
15
  APPROLEASSIGNMENT_LIST: `${prefix} approleassignment list`,
16
16
  APPROLEASSIGNMENT_REMOVE: `${prefix} approleassignment remove`,
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_1 = require("../../../cli");
4
+ const validation_1 = require("../../../utils/validation");
5
+ const settingsNames_1 = require("../../../settingsNames");
6
+ const AppCommand_1 = require("../../base/AppCommand");
7
+ const commands_1 = require("../commands");
8
+ class AppOpenCommand extends AppCommand_1.default {
9
+ get name() {
10
+ return commands_1.default.OPEN;
11
+ }
12
+ get description() {
13
+ return 'Opens Azure AD app in the Azure AD portal';
14
+ }
15
+ getTelemetryProperties(args) {
16
+ const telemetryProps = super.getTelemetryProperties(args);
17
+ telemetryProps.appId = typeof args.options.appId !== 'undefined';
18
+ telemetryProps.preview = typeof args.options.preview !== 'undefined';
19
+ return telemetryProps;
20
+ }
21
+ commandAction(logger, args, cb) {
22
+ this.logOrOpenUrl(args, logger)
23
+ .then(_ => cb(), (rawRes) => this.handleRejectedODataJsonPromise(rawRes, logger, cb));
24
+ }
25
+ logOrOpenUrl(args, logger) {
26
+ return new Promise((resolve, reject) => {
27
+ const previewPrefix = args.options.preview === true ? "preview." : "";
28
+ const url = `https://${previewPrefix}portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationMenuBlade/Overview/appId/${this.appId}/isMSAApp/`;
29
+ if (cli_1.Cli.getInstance().getSettingWithDefaultValue(settingsNames_1.settingsNames.autoOpenLinksInBrowser, false) === false) {
30
+ logger.log(`Use a web browser to open the page ${url}`);
31
+ return resolve();
32
+ }
33
+ logger.log(`Opening the following page in your browser: ${url}`);
34
+ // 'open' is required here so we can lazy load the dependency.
35
+ // _open is never set before hitting this line, but this check
36
+ // is implemented so that we can stub it when testing.
37
+ /* c8 ignore next 3 */
38
+ if (!this._open) {
39
+ this._open = require('open');
40
+ }
41
+ this._open(url).then(() => {
42
+ resolve();
43
+ }, (error) => {
44
+ reject(error);
45
+ });
46
+ });
47
+ }
48
+ options() {
49
+ const options = [
50
+ { option: '--appId [appId]' },
51
+ { option: '--preview' }
52
+ ];
53
+ const parentOptions = super.options();
54
+ return options.concat(parentOptions);
55
+ }
56
+ validate(args) {
57
+ if (args.options.appId && !validation_1.validation.isValidGuid(args.options.appId)) {
58
+ return `${args.options.appId} is not a valid GUID`;
59
+ }
60
+ return true;
61
+ }
62
+ }
63
+ module.exports = new AppOpenCommand();
64
+ //# sourceMappingURL=app-open.js.map
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const prefix = 'app';
4
4
  exports.default = {
5
5
  GET: `${prefix} get`,
6
+ OPEN: `${prefix} open`,
6
7
  PERMISSION_LIST: `${prefix} permission list`
7
8
  };
8
9
  //# sourceMappingURL=commands.js.map
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const request_1 = require("../../../../request");
13
+ const utils_1 = require("../../../../utils");
14
+ const GraphCommand_1 = require("../../../base/GraphCommand");
15
+ const commands_1 = require("../../commands");
16
+ class PlannerBucketGetCommand extends GraphCommand_1.default {
17
+ get name() {
18
+ return commands_1.default.BUCKET_GET;
19
+ }
20
+ get description() {
21
+ return 'Gets the Microsoft Planner bucket in a plan';
22
+ }
23
+ getTelemetryProperties(args) {
24
+ const telemetryProps = super.getTelemetryProperties(args);
25
+ telemetryProps.id = typeof args.options.id !== 'undefined';
26
+ telemetryProps.name = typeof args.options.name !== 'undefined';
27
+ telemetryProps.planId = typeof args.options.planId !== 'undefined';
28
+ telemetryProps.planName = typeof args.options.planName !== 'undefined';
29
+ telemetryProps.ownerGroupId = typeof args.options.ownerGroupId !== 'undefined';
30
+ telemetryProps.ownerGroupName = typeof args.options.ownerGroupName !== 'undefined';
31
+ return telemetryProps;
32
+ }
33
+ commandAction(logger, args, cb) {
34
+ this
35
+ .getBucketId(args)
36
+ .then((bucketId) => this.getBucketById(bucketId))
37
+ .then((bucket) => {
38
+ logger.log(bucket);
39
+ cb();
40
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
41
+ }
42
+ getBucketId(args) {
43
+ const { id, name } = args.options;
44
+ if (id) {
45
+ return Promise.resolve(id);
46
+ }
47
+ return this
48
+ .getPlanId(args)
49
+ .then((planId) => {
50
+ const requestOptions = {
51
+ url: `${this.resource}/v1.0/planner/plans/${planId}/buckets`,
52
+ headers: {
53
+ accept: 'application/json;odata.metadata=none'
54
+ },
55
+ responseType: 'json'
56
+ };
57
+ return request_1.default.get(requestOptions);
58
+ })
59
+ .then(buckets => {
60
+ const filteredBuckets = buckets.value.filter(b => name.toLowerCase() === b.name.toLowerCase());
61
+ if (!filteredBuckets.length) {
62
+ return Promise.reject(`The specified bucket ${name} does not exist`);
63
+ }
64
+ if (filteredBuckets.length > 1) {
65
+ return Promise.reject(`Multiple buckets with name ${name} found: ${filteredBuckets.map(x => x.id)}`);
66
+ }
67
+ return Promise.resolve(filteredBuckets[0].id.toString());
68
+ });
69
+ }
70
+ getPlanId(args) {
71
+ const { planId, planName } = args.options;
72
+ if (planId) {
73
+ return Promise.resolve(planId);
74
+ }
75
+ return this
76
+ .getGroupId(args)
77
+ .then(groupId => {
78
+ const requestOptions = {
79
+ url: `${this.resource}/v1.0/planner/plans?$filter=owner eq '${groupId}'`,
80
+ headers: {
81
+ accept: 'application/json;odata.metadata=none'
82
+ },
83
+ responseType: 'json'
84
+ };
85
+ return request_1.default.get(requestOptions);
86
+ })
87
+ .then(plans => {
88
+ const filteredPlans = plans.value.filter(p => p.title.toLowerCase() === planName.toLowerCase());
89
+ if (filteredPlans.length === 0) {
90
+ return Promise.reject(`The specified plan ${planName} does not exist`);
91
+ }
92
+ if (filteredPlans.length > 1) {
93
+ return Promise.reject(`Multiple plans with name ${planName} found: ${filteredPlans.map(x => x.id)}`);
94
+ }
95
+ return Promise.resolve(filteredPlans[0].id);
96
+ });
97
+ }
98
+ getBucketById(id) {
99
+ return __awaiter(this, void 0, void 0, function* () {
100
+ const requestOptions = {
101
+ url: `${this.resource}/v1.0/planner/buckets/${id}`,
102
+ headers: {
103
+ accept: 'application/json'
104
+ },
105
+ responseType: 'json'
106
+ };
107
+ return request_1.default.get(requestOptions);
108
+ });
109
+ }
110
+ getGroupId(args) {
111
+ const { ownerGroupId, ownerGroupName } = args.options;
112
+ if (ownerGroupId) {
113
+ return Promise.resolve(ownerGroupId);
114
+ }
115
+ const requestOptions = {
116
+ url: `${this.resource}/v1.0/groups?$filter=displayName eq '${encodeURIComponent(ownerGroupName)}'`,
117
+ headers: {
118
+ accept: 'application/json;odata.metadata=none'
119
+ },
120
+ responseType: 'json'
121
+ };
122
+ return request_1.default
123
+ .get(requestOptions)
124
+ .then(response => {
125
+ if (!response.value.length) {
126
+ return Promise.reject(`The specified owner group ${ownerGroupName} does not exist`);
127
+ }
128
+ if (response.value.length > 1) {
129
+ return Promise.reject(`Multiple owner groups with name ${ownerGroupName} found: ${response.value.map(x => x.id)}`);
130
+ }
131
+ return Promise.resolve(response.value[0].id);
132
+ });
133
+ }
134
+ options() {
135
+ const options = [
136
+ {
137
+ option: '-i, --id [id]'
138
+ },
139
+ {
140
+ option: '--name [name]'
141
+ },
142
+ {
143
+ option: '--planId [planId]'
144
+ },
145
+ {
146
+ option: '--planName [planName]'
147
+ },
148
+ {
149
+ option: '--ownerGroupId [ownerGroupId]'
150
+ },
151
+ {
152
+ option: '--ownerGroupName [ownerGroupName]'
153
+ }
154
+ ];
155
+ const parentOptions = super.options();
156
+ return options.concat(parentOptions);
157
+ }
158
+ validate(args) {
159
+ if (args.options.id) {
160
+ if (args.options.planId || args.options.planName || args.options.ownerGroupId || args.options.ownerGroupName) {
161
+ return 'Don\'t specify planId, planName, ownerGroupId or ownerGroupName when using id';
162
+ }
163
+ if (args.options.name) {
164
+ return 'Specify either id or name';
165
+ }
166
+ }
167
+ if (args.options.name) {
168
+ if (!args.options.planId && !args.options.planName) {
169
+ return 'Specify either planId or planName when using name';
170
+ }
171
+ if (args.options.planId && args.options.planName) {
172
+ return 'Specify either planId or planName when using name but not both';
173
+ }
174
+ if (args.options.planName) {
175
+ if (!args.options.ownerGroupId && !args.options.ownerGroupName) {
176
+ return 'Specify either ownerGroupId or ownerGroupName when using planName';
177
+ }
178
+ if (args.options.ownerGroupId && args.options.ownerGroupName) {
179
+ return 'Specify either ownerGroupId or ownerGroupName when using planName but not both';
180
+ }
181
+ if (args.options.ownerGroupId && !utils_1.validation.isValidGuid(args.options.ownerGroupId)) {
182
+ return `${args.options.ownerGroupId} is not a valid GUID`;
183
+ }
184
+ }
185
+ if (args.options.planId) {
186
+ if (args.options.ownerGroupId || args.options.ownerGroupName) {
187
+ return 'Don\'t specify ownerGroupId or ownerGroupName when using planId';
188
+ }
189
+ }
190
+ }
191
+ if (!args.options.id && !args.options.name) {
192
+ return 'Please specify id or name';
193
+ }
194
+ return true;
195
+ }
196
+ }
197
+ module.exports = new PlannerBucketGetCommand();
198
+ //# sourceMappingURL=bucket-get.js.map
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_1 = require("../../../../cli");
4
+ const utils_1 = require("../../../../utils");
5
+ const request_1 = require("../../../../request");
6
+ const GraphCommand_1 = require("../../../base/GraphCommand");
7
+ const commands_1 = require("../../commands");
8
+ class PlannerBucketRemoveCommand extends GraphCommand_1.default {
9
+ get name() {
10
+ return commands_1.default.BUCKET_REMOVE;
11
+ }
12
+ get description() {
13
+ return 'Removes the Microsoft Planner bucket from a plan';
14
+ }
15
+ getTelemetryProperties(args) {
16
+ const telemetryProps = super.getTelemetryProperties(args);
17
+ telemetryProps.id = typeof args.options.id !== 'undefined';
18
+ telemetryProps.name = typeof args.options.name !== 'undefined';
19
+ telemetryProps.planId = typeof args.options.planId !== 'undefined';
20
+ telemetryProps.planName = typeof args.options.planName !== 'undefined';
21
+ telemetryProps.ownerGroupId = typeof args.options.ownerGroupId !== 'undefined';
22
+ telemetryProps.ownerGroupName = typeof args.options.ownerGroupName !== 'undefined';
23
+ telemetryProps.confirm = args.options.confirm || false;
24
+ return telemetryProps;
25
+ }
26
+ commandAction(logger, args, cb) {
27
+ const removeBucket = () => {
28
+ this
29
+ .getBucket(args)
30
+ .then(bucket => {
31
+ const requestOptions = {
32
+ url: `${this.resource}/v1.0/planner/buckets/${bucket.id}`,
33
+ headers: {
34
+ accept: 'application/json;odata.metadata=none',
35
+ 'if-match': bucket['@odata.etag']
36
+ },
37
+ responseType: 'json'
38
+ };
39
+ return request_1.default.delete(requestOptions);
40
+ })
41
+ .then(_ => cb(), (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
42
+ };
43
+ if (args.options.confirm) {
44
+ removeBucket();
45
+ }
46
+ else {
47
+ cli_1.Cli.prompt({
48
+ type: 'confirm',
49
+ name: 'continue',
50
+ default: false,
51
+ message: `Are you sure you want to remove the bucket ${args.options.id || args.options.name}?`
52
+ }, (result) => {
53
+ if (!result.continue) {
54
+ cb();
55
+ }
56
+ else {
57
+ removeBucket();
58
+ }
59
+ });
60
+ }
61
+ }
62
+ getBucket(args) {
63
+ if (args.options.id) {
64
+ const requestOptions = {
65
+ url: `${this.resource}/v1.0/planner/buckets/${args.options.id}`,
66
+ headers: {
67
+ accept: 'application/json'
68
+ },
69
+ responseType: 'json'
70
+ };
71
+ return request_1.default.get(requestOptions);
72
+ }
73
+ return this
74
+ .getPlanId(args)
75
+ .then(planId => {
76
+ const requestOptions = {
77
+ url: `${this.resource}/v1.0/planner/plans/${planId}/buckets`,
78
+ headers: {
79
+ accept: 'application/json'
80
+ },
81
+ responseType: 'json'
82
+ };
83
+ return request_1.default.get(requestOptions);
84
+ })
85
+ .then(buckets => {
86
+ const filteredBuckets = buckets.value.filter(b => args.options.name.toLowerCase() === b.name.toLowerCase());
87
+ if (!filteredBuckets.length) {
88
+ return Promise.reject(`The specified bucket ${args.options.name} does not exist`);
89
+ }
90
+ if (filteredBuckets.length > 1) {
91
+ return Promise.reject(`Multiple buckets with name ${args.options.name} found: ${filteredBuckets.map(x => x.id)}`);
92
+ }
93
+ return Promise.resolve(filteredBuckets[0]);
94
+ });
95
+ }
96
+ getPlanId(args) {
97
+ const { planId, planName } = args.options;
98
+ if (planId) {
99
+ return Promise.resolve(planId);
100
+ }
101
+ return this
102
+ .getGroupId(args)
103
+ .then(groupId => {
104
+ const requestOptions = {
105
+ url: `${this.resource}/v1.0/planner/plans?$filter=owner eq '${groupId}'`,
106
+ headers: {
107
+ accept: 'application/json;odata.metadata=none'
108
+ },
109
+ responseType: 'json'
110
+ };
111
+ return request_1.default.get(requestOptions);
112
+ })
113
+ .then(plans => {
114
+ const filteredPlans = plans.value.filter(p => p.title.toLowerCase() === planName.toLowerCase());
115
+ if (!filteredPlans.length) {
116
+ return Promise.reject(`The specified plan ${planName} does not exist`);
117
+ }
118
+ if (filteredPlans.length > 1) {
119
+ return Promise.reject(`Multiple plans with name ${planName} found: ${filteredPlans.map(x => x.id)}`);
120
+ }
121
+ return Promise.resolve(filteredPlans[0].id);
122
+ });
123
+ }
124
+ getGroupId(args) {
125
+ const { ownerGroupId, ownerGroupName } = args.options;
126
+ if (ownerGroupId) {
127
+ return Promise.resolve(ownerGroupId);
128
+ }
129
+ const requestOptions = {
130
+ url: `${this.resource}/v1.0/groups?$filter=displayName eq '${encodeURIComponent(ownerGroupName)}'`,
131
+ headers: {
132
+ accept: 'application/json;odata.metadata=none'
133
+ },
134
+ responseType: 'json'
135
+ };
136
+ return request_1.default
137
+ .get(requestOptions)
138
+ .then(response => {
139
+ if (!response.value.length) {
140
+ return Promise.reject(`The specified owner group ${ownerGroupName} does not exist`);
141
+ }
142
+ if (response.value.length > 1) {
143
+ return Promise.reject(`Multiple owner groups with name ${ownerGroupName} found: ${response.value.map(x => x.id)}`);
144
+ }
145
+ return Promise.resolve(response.value[0].id);
146
+ });
147
+ }
148
+ options() {
149
+ const options = [
150
+ {
151
+ option: '--id [id]'
152
+ },
153
+ {
154
+ option: '--name [name]'
155
+ },
156
+ {
157
+ option: '--planId [planId]'
158
+ },
159
+ {
160
+ option: '--planName [planName]'
161
+ },
162
+ {
163
+ option: '--ownerGroupId [ownerGroupId]'
164
+ },
165
+ {
166
+ option: '--ownerGroupName [ownerGroupName]'
167
+ },
168
+ {
169
+ option: '--confirm'
170
+ }
171
+ ];
172
+ const parentOptions = super.options();
173
+ return options.concat(parentOptions);
174
+ }
175
+ optionSets() {
176
+ return [
177
+ ['id', 'name']
178
+ ];
179
+ }
180
+ validate(args) {
181
+ if (args.options.id) {
182
+ if (args.options.planId || args.options.planName || args.options.ownerGroupId || args.options.ownerGroupName) {
183
+ return 'Don\'t specify planId, planName, ownerGroupId or ownerGroupName when using id';
184
+ }
185
+ }
186
+ else {
187
+ if (!args.options.planId && !args.options.planName) {
188
+ return 'Specify either planId or planName when using name';
189
+ }
190
+ if (args.options.planId && args.options.planName) {
191
+ return 'Specify either planId or planName when using name but not both';
192
+ }
193
+ if (args.options.planName) {
194
+ if (!args.options.ownerGroupId && !args.options.ownerGroupName) {
195
+ return 'Specify either ownerGroupId or ownerGroupName when using planName';
196
+ }
197
+ if (args.options.ownerGroupId && args.options.ownerGroupName) {
198
+ return 'Specify either ownerGroupId or ownerGroupName when using planName but not both';
199
+ }
200
+ if (args.options.ownerGroupId && !utils_1.validation.isValidGuid(args.options.ownerGroupId)) {
201
+ return `${args.options.ownerGroupId} is not a valid GUID`;
202
+ }
203
+ }
204
+ else {
205
+ if (args.options.ownerGroupId || args.options.ownerGroupName) {
206
+ return 'Don\'t specify ownerGroupId or ownerGroupName when using planId';
207
+ }
208
+ }
209
+ }
210
+ return true;
211
+ }
212
+ }
213
+ module.exports = new PlannerBucketRemoveCommand();
214
+ //# sourceMappingURL=bucket-remove.js.map