@pnp/cli-microsoft365 6.1.0-beta.f818fbb → 6.1.0

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 (38) hide show
  1. package/dist/m365/aad/commands/group/group-get.js +79 -0
  2. package/dist/m365/aad/commands/user/user-set.js +84 -11
  3. package/dist/m365/aad/commands.js +1 -0
  4. package/dist/m365/base/ContextCommand.js +33 -0
  5. package/dist/m365/context/commands/context-init.js +28 -0
  6. package/dist/m365/context/commands/context-remove.js +103 -0
  7. package/dist/m365/context/commands.js +8 -0
  8. package/dist/m365/pp/commands/environment/environment-get.js +5 -13
  9. package/dist/m365/purview/commands/retentionlabel/retentionlabel-set.js +142 -0
  10. package/dist/m365/purview/commands.js +2 -1
  11. package/dist/m365/search/commands/externalconnection/externalconnection-schema-add.js +86 -0
  12. package/dist/m365/search/commands.js +2 -1
  13. package/dist/m365/spo/commands/group/group-member-add.js +68 -30
  14. package/dist/m365/spo/commands/group/group-member-remove.js +50 -7
  15. package/dist/m365/spo/commands/list/{list-retentionlabel-set.js → list-retentionlabel-ensure.js} +21 -15
  16. package/dist/m365/spo/commands/listitem/listitem-remove.js +1 -1
  17. package/dist/m365/spo/commands/listitem/listitem-retentionlabel-remove.js +143 -0
  18. package/dist/m365/spo/commands/page/page-add.js +60 -63
  19. package/dist/m365/spo/commands/page/page-set.js +59 -70
  20. package/dist/m365/spo/commands/site/site-appcatalog-list.js +43 -0
  21. package/dist/m365/spo/commands.js +3 -1
  22. package/dist/request.js +2 -1
  23. package/dist/utils/pid.js +31 -15
  24. package/docs/docs/cmd/aad/group/group-get.md +127 -0
  25. package/docs/docs/cmd/aad/user/user-set.md +31 -3
  26. package/docs/docs/cmd/context/context-init.md +25 -0
  27. package/docs/docs/cmd/context/context-remove.md +34 -0
  28. package/docs/docs/cmd/pp/environment/environment-get.md +9 -3
  29. package/docs/docs/cmd/purview/retentionlabel/retentionlabel-set.md +63 -0
  30. package/docs/docs/cmd/search/externalconnection/externalconnection-schema-add.md +31 -0
  31. package/docs/docs/cmd/spo/group/group-member-add.md +58 -6
  32. package/docs/docs/cmd/spo/group/group-member-remove.md +24 -8
  33. package/docs/docs/cmd/spo/list/list-retentionlabel-ensure.md +65 -0
  34. package/docs/docs/cmd/spo/listitem/listitem-remove.md +6 -6
  35. package/docs/docs/cmd/spo/listitem/listitem-retentionlabel-remove.md +55 -0
  36. package/docs/docs/cmd/spo/site/site-appcatalog-list.md +55 -0
  37. package/package.json +2 -2
  38. package/docs/docs/cmd/spo/list/list-retentionlabel-set.md +0 -65
@@ -0,0 +1,79 @@
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
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _AadGroupGetCommand_instances, _AadGroupGetCommand_initOptions, _AadGroupGetCommand_initValidators, _AadGroupGetCommand_initOptionSets, _AadGroupGetCommand_initTelemetry;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const validation_1 = require("../../../../utils/validation");
19
+ const aadGroup_1 = require("../../../../utils/aadGroup");
20
+ const GraphCommand_1 = require("../../../base/GraphCommand");
21
+ const commands_1 = require("../../commands");
22
+ class AadGroupGetCommand extends GraphCommand_1.default {
23
+ get name() {
24
+ return commands_1.default.GROUP_GET;
25
+ }
26
+ get description() {
27
+ return 'Gets information about the specified Azure AD Group';
28
+ }
29
+ constructor() {
30
+ super();
31
+ _AadGroupGetCommand_instances.add(this);
32
+ __classPrivateFieldGet(this, _AadGroupGetCommand_instances, "m", _AadGroupGetCommand_initOptions).call(this);
33
+ __classPrivateFieldGet(this, _AadGroupGetCommand_instances, "m", _AadGroupGetCommand_initValidators).call(this);
34
+ __classPrivateFieldGet(this, _AadGroupGetCommand_instances, "m", _AadGroupGetCommand_initOptionSets).call(this);
35
+ __classPrivateFieldGet(this, _AadGroupGetCommand_instances, "m", _AadGroupGetCommand_initTelemetry).call(this);
36
+ }
37
+ commandAction(logger, args) {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ let group;
40
+ try {
41
+ if (args.options.id) {
42
+ group = yield aadGroup_1.aadGroup.getGroupById(args.options.id);
43
+ }
44
+ else {
45
+ group = yield aadGroup_1.aadGroup.getGroupByDisplayName(args.options.title);
46
+ }
47
+ logger.log(group);
48
+ }
49
+ catch (err) {
50
+ this.handleRejectedODataJsonPromise(err);
51
+ }
52
+ });
53
+ }
54
+ }
55
+ _AadGroupGetCommand_instances = new WeakSet(), _AadGroupGetCommand_initOptions = function _AadGroupGetCommand_initOptions() {
56
+ this.options.unshift({
57
+ option: '-i, --id [id]'
58
+ }, {
59
+ option: '-t, --title [title]'
60
+ });
61
+ }, _AadGroupGetCommand_initValidators = function _AadGroupGetCommand_initValidators() {
62
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
63
+ if (args.options.id && !validation_1.validation.isValidGuid(args.options.id)) {
64
+ return `${args.options.id} is not a valid GUID`;
65
+ }
66
+ return true;
67
+ }));
68
+ }, _AadGroupGetCommand_initOptionSets = function _AadGroupGetCommand_initOptionSets() {
69
+ this.optionSets.push({ options: ['id', 'title'] });
70
+ }, _AadGroupGetCommand_initTelemetry = function _AadGroupGetCommand_initTelemetry() {
71
+ this.telemetry.push((args) => {
72
+ Object.assign(this.telemetryProperties, {
73
+ id: typeof args.options.id !== 'undefined',
74
+ title: typeof args.options.title !== 'undefined'
75
+ });
76
+ });
77
+ };
78
+ module.exports = new AadGroupGetCommand();
79
+ //# sourceMappingURL=group-get.js.map
@@ -15,7 +15,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
15
15
  };
16
16
  var _AadUserSetCommand_instances, _AadUserSetCommand_initTelemetry, _AadUserSetCommand_initOptions, _AadUserSetCommand_initTypes, _AadUserSetCommand_initValidators, _AadUserSetCommand_initOptionSets;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ const Auth_1 = require("../../../../Auth");
18
19
  const request_1 = require("../../../../request");
20
+ const accessToken_1 = require("../../../../utils/accessToken");
19
21
  const formatting_1 = require("../../../../utils/formatting");
20
22
  const validation_1 = require("../../../../utils/validation");
21
23
  const GraphCommand_1 = require("../../../base/GraphCommand");
@@ -42,16 +44,36 @@ class AadUserSetCommand extends GraphCommand_1.default {
42
44
  commandAction(logger, args) {
43
45
  return __awaiter(this, void 0, void 0, function* () {
44
46
  try {
47
+ if (this.verbose) {
48
+ logger.logToStderr(`Updating user ${args.options.userPrincipalName || args.options.objectId}`);
49
+ }
50
+ if (args.options.currentPassword) {
51
+ if (args.options.objectId && args.options.objectId !== accessToken_1.accessToken.getUserIdFromAccessToken(Auth_1.default.service.accessTokens[Auth_1.default.defaultResource].accessToken)) {
52
+ throw `You can only change your own password. Please use --objectId @meId to reference to your own userId`;
53
+ }
54
+ else if (args.options.userPrincipalName && args.options.userPrincipalName.toLowerCase() !== accessToken_1.accessToken.getUserNameFromAccessToken(Auth_1.default.service.accessTokens[Auth_1.default.defaultResource].accessToken).toLowerCase()) {
55
+ throw 'You can only change your own password. Please use --userPrincipalName @meUserName to reference to your own user principal name';
56
+ }
57
+ }
58
+ const requestUrl = `${this.resource}/v1.0/users/${formatting_1.formatting.encodeQueryParameter(args.options.objectId ? args.options.objectId : args.options.userPrincipalName)}`;
45
59
  const manifest = this.mapRequestBody(args.options);
46
- const requestOptions = {
47
- url: `${this.resource}/v1.0/users/${formatting_1.formatting.encodeQueryParameter(args.options.objectId ? args.options.objectId : args.options.userPrincipalName)}`,
48
- headers: {
49
- accept: 'application/json'
50
- },
51
- responseType: 'json',
52
- data: manifest
53
- };
54
- yield request_1.default.patch(requestOptions);
60
+ if (Object.keys(manifest).length > 0) {
61
+ if (this.verbose) {
62
+ logger.logToStderr(`Setting the updated properties for the user ${args.options.userPrincipalName || args.options.objectId}`);
63
+ }
64
+ const requestOptions = {
65
+ url: requestUrl,
66
+ headers: {
67
+ accept: 'application/json'
68
+ },
69
+ responseType: 'json',
70
+ data: manifest
71
+ };
72
+ yield request_1.default.patch(requestOptions);
73
+ }
74
+ if (args.options.currentPassword) {
75
+ yield this.changePassword(requestUrl, args.options, logger);
76
+ }
55
77
  }
56
78
  catch (err) {
57
79
  this.handleRejectedODataJsonPromise(err);
@@ -68,7 +90,11 @@ class AadUserSetCommand extends GraphCommand_1.default {
68
90
  'i',
69
91
  'userPrincipalName',
70
92
  'n',
71
- 'accountEnabled'
93
+ 'resetPassword',
94
+ 'accountEnabled',
95
+ 'currentPassword',
96
+ 'newPassword',
97
+ 'forceChangePasswordNextSignIn'
72
98
  ];
73
99
  if (options.accountEnabled !== undefined) {
74
100
  requestBody['AccountEnabled'] = options.accountEnabled;
@@ -78,15 +104,45 @@ class AadUserSetCommand extends GraphCommand_1.default {
78
104
  requestBody[key] = `${options[key]}`;
79
105
  }
80
106
  });
107
+ if (options.resetPassword) {
108
+ requestBody.passwordProfile = {
109
+ forceChangePasswordNextSignIn: options.forceChangePasswordNextSignIn || false,
110
+ password: options.newPassword
111
+ };
112
+ }
81
113
  return requestBody;
82
114
  }
115
+ changePassword(requestUrl, options, logger) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ if (this.verbose) {
118
+ logger.logToStderr(`Changing password for user ${options.userPrincipalName || options.objectId}`);
119
+ }
120
+ const requestBody = {
121
+ currentPassword: options.currentPassword,
122
+ newPassword: options.newPassword
123
+ };
124
+ const requestOptions = {
125
+ url: `${requestUrl}/changePassword`,
126
+ headers: {
127
+ accept: 'application/json;odata.metadata=none'
128
+ },
129
+ responseType: 'json',
130
+ data: requestBody
131
+ };
132
+ yield request_1.default.post(requestOptions);
133
+ });
134
+ }
83
135
  }
84
136
  _AadUserSetCommand_instances = new WeakSet(), _AadUserSetCommand_initTelemetry = function _AadUserSetCommand_initTelemetry() {
85
137
  this.telemetry.push((args) => {
86
138
  Object.assign(this.telemetryProperties, {
87
139
  objectId: typeof args.options.objectId !== 'undefined',
88
140
  userPrincipalName: typeof args.options.userPrincipalName !== 'undefined',
89
- accountEnabled: args.options.accountEnabled
141
+ accountEnabled: !!args.options.accountEnabled,
142
+ resetPassword: !!args.options.resetPassword,
143
+ forceChangePasswordNextSignIn: !!args.options.forceChangePasswordNextSignIn,
144
+ currentPassword: typeof args.options.currentPassword !== 'undefined',
145
+ newPassword: typeof args.options.newPassword !== 'undefined'
90
146
  });
91
147
  });
92
148
  }, _AadUserSetCommand_initOptions = function _AadUserSetCommand_initOptions() {
@@ -97,6 +153,14 @@ _AadUserSetCommand_instances = new WeakSet(), _AadUserSetCommand_initTelemetry =
97
153
  }, {
98
154
  option: '--accountEnabled [accountEnabled]',
99
155
  autocomplete: ['true', 'false']
156
+ }, {
157
+ option: '--resetPassword'
158
+ }, {
159
+ option: '--forceChangePasswordNextSignIn'
160
+ }, {
161
+ option: '--currentPassword [currentPassword]'
162
+ }, {
163
+ option: '--newPassword [newPassword]'
100
164
  });
101
165
  }, _AadUserSetCommand_initTypes = function _AadUserSetCommand_initTypes() {
102
166
  this.types.boolean.push('accountEnabled');
@@ -106,6 +170,15 @@ _AadUserSetCommand_instances = new WeakSet(), _AadUserSetCommand_initTelemetry =
106
170
  !validation_1.validation.isValidGuid(args.options.objectId)) {
107
171
  return `${args.options.objectId} is not a valid GUID`;
108
172
  }
173
+ if (!args.options.resetPassword && ((args.options.currentPassword && !args.options.newPassword) || (args.options.newPassword && !args.options.currentPassword))) {
174
+ return `Specify both currentPassword and newPassword when you want to change your password`;
175
+ }
176
+ if (args.options.resetPassword && args.options.currentPassword) {
177
+ return `When resetting a user's password, don't specify the current password`;
178
+ }
179
+ if (args.options.resetPassword && !args.options.newPassword) {
180
+ return `When resetting a user's password, specify the new password to set for the user, using the newPassword option`;
181
+ }
109
182
  return true;
110
183
  }));
111
184
  }, _AadUserSetCommand_initOptionSets = function _AadUserSetCommand_initOptionSets() {
@@ -13,6 +13,7 @@ exports.default = {
13
13
  APPROLEASSIGNMENT_ADD: `${prefix} approleassignment add`,
14
14
  APPROLEASSIGNMENT_LIST: `${prefix} approleassignment list`,
15
15
  APPROLEASSIGNMENT_REMOVE: `${prefix} approleassignment remove`,
16
+ GROUP_GET: `${prefix} group get`,
16
17
  GROUP_LIST: `${prefix} group list`,
17
18
  GROUPSETTING_ADD: `${prefix} groupsetting add`,
18
19
  GROUPSETTING_GET: `${prefix} groupsetting get`,
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const Command_1 = require("../../Command");
5
+ const AnonymousCommand_1 = require("./AnonymousCommand");
6
+ class ContextCommand extends AnonymousCommand_1.default {
7
+ saveContextInfo(context) {
8
+ const filePath = '.m365rc.json';
9
+ let m365rc = {};
10
+ if (fs.existsSync(filePath)) {
11
+ try {
12
+ const fileContents = fs.readFileSync(filePath, 'utf8');
13
+ if (fileContents) {
14
+ m365rc = JSON.parse(fileContents);
15
+ }
16
+ }
17
+ catch (e) {
18
+ throw new Command_1.CommandError(`Error reading ${filePath}: ${e}. Please add context info to ${filePath} manually.`);
19
+ }
20
+ }
21
+ if (!m365rc.context) {
22
+ m365rc.context = context;
23
+ try {
24
+ fs.writeFileSync(filePath, JSON.stringify(m365rc, null, 2));
25
+ }
26
+ catch (e) {
27
+ throw new Command_1.CommandError(`Error writing ${filePath}: ${e}. Please add context info to ${filePath} manually.`);
28
+ }
29
+ }
30
+ }
31
+ }
32
+ exports.default = ContextCommand;
33
+ //# sourceMappingURL=ContextCommand.js.map
@@ -0,0 +1,28 @@
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 ContextCommand_1 = require("../../base/ContextCommand");
13
+ const commands_1 = require("../commands");
14
+ class ContextInitCommand extends ContextCommand_1.default {
15
+ get name() {
16
+ return commands_1.default.INIT;
17
+ }
18
+ get description() {
19
+ return 'Initiates CLI for Microsoft 365 context in the current working folder';
20
+ }
21
+ commandAction() {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ yield this.saveContextInfo({});
24
+ });
25
+ }
26
+ }
27
+ module.exports = new ContextInitCommand();
28
+ //# sourceMappingURL=context-init.js.map
@@ -0,0 +1,103 @@
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
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _ContextRemoveCommand_instances, _ContextRemoveCommand_initTelemetry, _ContextRemoveCommand_initOptions;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const fs = require("fs");
19
+ const Cli_1 = require("../../../cli/Cli");
20
+ const Command_1 = require("../../../Command");
21
+ const AnonymousCommand_1 = require("../../base/AnonymousCommand");
22
+ const commands_1 = require("../commands");
23
+ class ContextRemoveCommand extends AnonymousCommand_1.default {
24
+ get name() {
25
+ return commands_1.default.REMOVE;
26
+ }
27
+ get description() {
28
+ return 'Removes the CLI for Microsoft 365 context in the current working folder';
29
+ }
30
+ constructor() {
31
+ super();
32
+ _ContextRemoveCommand_instances.add(this);
33
+ __classPrivateFieldGet(this, _ContextRemoveCommand_instances, "m", _ContextRemoveCommand_initTelemetry).call(this);
34
+ __classPrivateFieldGet(this, _ContextRemoveCommand_instances, "m", _ContextRemoveCommand_initOptions).call(this);
35
+ }
36
+ commandAction(logger, args) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ if (args.options.confirm) {
39
+ yield this.removeContext();
40
+ }
41
+ else {
42
+ const result = yield Cli_1.Cli.prompt({
43
+ type: 'confirm',
44
+ name: 'continue',
45
+ default: false,
46
+ message: `Are you sure you want to remove the context?`
47
+ });
48
+ if (result.continue) {
49
+ yield this.removeContext();
50
+ }
51
+ }
52
+ });
53
+ }
54
+ removeContext() {
55
+ const filePath = '.m365rc.json';
56
+ let m365rc = {};
57
+ if (fs.existsSync(filePath)) {
58
+ try {
59
+ const fileContents = fs.readFileSync(filePath, 'utf8');
60
+ if (fileContents) {
61
+ m365rc = JSON.parse(fileContents);
62
+ }
63
+ }
64
+ catch (e) {
65
+ throw new Command_1.CommandError(`Error reading ${filePath}: ${e}. Please remove context info from ${filePath} manually.`);
66
+ }
67
+ }
68
+ if (!m365rc.context) {
69
+ return;
70
+ }
71
+ const keys = Object.keys(m365rc);
72
+ if (keys.length === 1 && keys.indexOf('context') > -1) {
73
+ try {
74
+ fs.unlinkSync(filePath);
75
+ }
76
+ catch (e) {
77
+ throw new Command_1.CommandError(`Error removing ${filePath}: ${e}. Please remove ${filePath} manually.`);
78
+ }
79
+ }
80
+ else {
81
+ try {
82
+ delete m365rc.context;
83
+ fs.writeFileSync(filePath, JSON.stringify(m365rc, null, 2));
84
+ }
85
+ catch (e) {
86
+ throw new Command_1.CommandError(`Error writing ${filePath}: ${e}. Please remove context info from ${filePath} manually.`);
87
+ }
88
+ }
89
+ }
90
+ }
91
+ _ContextRemoveCommand_instances = new WeakSet(), _ContextRemoveCommand_initTelemetry = function _ContextRemoveCommand_initTelemetry() {
92
+ this.telemetry.push((args) => {
93
+ Object.assign(this.telemetryProperties, {
94
+ confirm: !!args.options.confirm
95
+ });
96
+ });
97
+ }, _ContextRemoveCommand_initOptions = function _ContextRemoveCommand_initOptions() {
98
+ this.options.unshift({
99
+ option: '--confirm'
100
+ });
101
+ };
102
+ module.exports = new ContextRemoveCommand();
103
+ //# sourceMappingURL=context-remove.js.map
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const prefix = 'context';
4
+ exports.default = {
5
+ INIT: `${prefix} init`,
6
+ REMOVE: `${prefix} remove`
7
+ };
8
+ //# sourceMappingURL=commands.js.map
@@ -15,7 +15,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
15
15
  };
16
16
  var _PpEnvironmentGetCommand_instances, _PpEnvironmentGetCommand_initTelemetry, _PpEnvironmentGetCommand_initOptions;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- const request_1 = require("../../../../request");
18
+ const odata_1 = require("../../../../utils/odata");
19
19
  const PowerPlatformCommand_1 = require("../../../base/PowerPlatformCommand");
20
20
  const commands_1 = require("../../commands");
21
21
  class PpEnvironmentGetCommand extends PowerPlatformCommand_1.default {
@@ -40,17 +40,8 @@ class PpEnvironmentGetCommand extends PowerPlatformCommand_1.default {
40
40
  if (args.options.asAdmin) {
41
41
  url = `${this.resource}/providers/Microsoft.BusinessAppPlatform/scopes/admin/environments`;
42
42
  }
43
- const requestOptions = {
44
- url: `${url}?api-version=2020-10-01`,
45
- headers: {
46
- accept: 'application/json'
47
- },
48
- responseType: 'json'
49
- };
50
- const res = yield request_1.default.get(requestOptions);
51
- const environmentItem = res.value.filter((env) => {
52
- return env.name === args.options.name;
53
- })[0];
43
+ const res = yield odata_1.odata.getAllItems(`${url}?api-version=2020-10-01`);
44
+ const environmentItem = res.filter((env) => args.options.name ? env.name === args.options.name : env.properties.isDefault === true)[0];
54
45
  if (!environmentItem) {
55
46
  throw `The specified Power Platform environment does not exist`;
56
47
  }
@@ -61,12 +52,13 @@ class PpEnvironmentGetCommand extends PowerPlatformCommand_1.default {
61
52
  _PpEnvironmentGetCommand_instances = new WeakSet(), _PpEnvironmentGetCommand_initTelemetry = function _PpEnvironmentGetCommand_initTelemetry() {
62
53
  this.telemetry.push((args) => {
63
54
  Object.assign(this.telemetryProperties, {
55
+ name: typeof args.options.name !== 'undefined',
64
56
  asAdmin: !!args.options.asAdmin
65
57
  });
66
58
  });
67
59
  }, _PpEnvironmentGetCommand_initOptions = function _PpEnvironmentGetCommand_initOptions() {
68
60
  this.options.unshift({
69
- option: '-n, --name <name>'
61
+ option: '-n, --name [name]'
70
62
  }, {
71
63
  option: '--asAdmin'
72
64
  });
@@ -0,0 +1,142 @@
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
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _PurviewRetentionLabelSetCommand_instances, _PurviewRetentionLabelSetCommand_initTelemetry, _PurviewRetentionLabelSetCommand_initOptions, _PurviewRetentionLabelSetCommand_initValidators;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const validation_1 = require("../../../../utils/validation");
19
+ const request_1 = require("../../../../request");
20
+ const GraphCommand_1 = require("../../../base/GraphCommand");
21
+ const commands_1 = require("../../commands");
22
+ class PurviewRetentionLabelSetCommand extends GraphCommand_1.default {
23
+ get name() {
24
+ return commands_1.default.RETENTIONLABEL_SET;
25
+ }
26
+ get description() {
27
+ return 'Update a retention label';
28
+ }
29
+ constructor() {
30
+ super();
31
+ _PurviewRetentionLabelSetCommand_instances.add(this);
32
+ this.allowedBehaviorDuringRetentionPeriodValues = ['doNotRetain', 'retain', 'retainAsRecord', 'retainAsRegulatoryRecord'];
33
+ this.allowedActionAfterRetentionPeriodValues = ['none', 'delete', 'startDispositionReview'];
34
+ this.allowedRetentionTriggerValues = ['dateLabeled', 'dateCreated', 'dateModified', 'dateOfEvent'];
35
+ this.allowedDefaultRecordBehaviorValues = ['startLocked', 'startUnlocked'];
36
+ __classPrivateFieldGet(this, _PurviewRetentionLabelSetCommand_instances, "m", _PurviewRetentionLabelSetCommand_initTelemetry).call(this);
37
+ __classPrivateFieldGet(this, _PurviewRetentionLabelSetCommand_instances, "m", _PurviewRetentionLabelSetCommand_initOptions).call(this);
38
+ __classPrivateFieldGet(this, _PurviewRetentionLabelSetCommand_instances, "m", _PurviewRetentionLabelSetCommand_initValidators).call(this);
39
+ }
40
+ commandAction(logger, args) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ if (this.verbose) {
43
+ logger.log(`Starting to update retention label with id ${args.options.id}`);
44
+ }
45
+ const requestBody = this.mapRequestBody(args.options);
46
+ const requestOptions = {
47
+ url: `${this.resource}/beta/security/labels/retentionLabels/${args.options.id}`,
48
+ headers: {
49
+ accept: 'application/json'
50
+ },
51
+ responseType: 'json',
52
+ data: requestBody
53
+ };
54
+ yield request_1.default.patch(requestOptions);
55
+ });
56
+ }
57
+ mapRequestBody(options) {
58
+ const requestBody = {};
59
+ const excludeOptions = [
60
+ 'debug',
61
+ 'verbose',
62
+ 'output',
63
+ 'id',
64
+ 'retentionDuration'
65
+ ];
66
+ Object.keys(options).forEach(key => {
67
+ if (excludeOptions.indexOf(key) === -1) {
68
+ requestBody[key] = `${options[key]}`;
69
+ }
70
+ });
71
+ if (options.retentionDuration) {
72
+ requestBody['retentionDuration'] = {
73
+ '@odata.type': 'microsoft.graph.security.retentionDurationInDays',
74
+ 'days': options.retentionDuration
75
+ };
76
+ }
77
+ return requestBody;
78
+ }
79
+ }
80
+ _PurviewRetentionLabelSetCommand_instances = new WeakSet(), _PurviewRetentionLabelSetCommand_initTelemetry = function _PurviewRetentionLabelSetCommand_initTelemetry() {
81
+ this.telemetry.push((args) => {
82
+ Object.assign(this.telemetryProperties, {
83
+ behaviorDuringRetentionPeriod: typeof args.options.behaviorDuringRetentionPeriod !== 'undefined',
84
+ actionAfterRetentionPeriod: typeof args.options.actionAfterRetentionPeriod !== 'undefined',
85
+ retentionDuration: typeof args.options.retentionDuration !== 'undefined',
86
+ retentionTrigger: typeof args.options.retentionTrigger !== 'undefined',
87
+ defaultRecordBehavior: typeof args.options.defaultRecordBehavior !== 'undefined',
88
+ descriptionForUsers: typeof args.options.descriptionForUsers !== 'undefined',
89
+ descriptionForAdmins: typeof args.options.descriptionForAdmins !== 'undefined',
90
+ labelToBeApplied: typeof args.options.labelToBeApplied !== 'undefined'
91
+ });
92
+ });
93
+ }, _PurviewRetentionLabelSetCommand_initOptions = function _PurviewRetentionLabelSetCommand_initOptions() {
94
+ this.options.unshift({
95
+ option: '-i, --id <id>'
96
+ }, {
97
+ option: '--behaviorDuringRetentionPeriod [behaviorDuringRetentionPeriod]',
98
+ autocomplete: this.allowedBehaviorDuringRetentionPeriodValues
99
+ }, {
100
+ option: '--actionAfterRetentionPeriod [actionAfterRetentionPeriod]',
101
+ autocomplete: this.allowedActionAfterRetentionPeriodValues
102
+ }, {
103
+ option: '--retentionDuration [retentionDuration]'
104
+ }, {
105
+ option: '-t, --retentionTrigger [retentionTrigger]',
106
+ autocomplete: this.allowedRetentionTriggerValues
107
+ }, {
108
+ option: '--defaultRecordBehavior [defaultRecordBehavior]',
109
+ autocomplete: this.allowedDefaultRecordBehaviorValues
110
+ }, {
111
+ option: '--descriptionForUsers [descriptionForUsers]'
112
+ }, {
113
+ option: '--descriptionForAdmins [descriptionForAdmins]'
114
+ }, {
115
+ option: '--labelToBeApplied [labelToBeApplied]'
116
+ });
117
+ }, _PurviewRetentionLabelSetCommand_initValidators = function _PurviewRetentionLabelSetCommand_initValidators() {
118
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
119
+ if (!validation_1.validation.isValidGuid(args.options.id)) {
120
+ return `'${args.options.id}' is not a valid GUID.`;
121
+ }
122
+ const { actionAfterRetentionPeriod, behaviorDuringRetentionPeriod, defaultRecordBehavior, descriptionForAdmins, descriptionForUsers, labelToBeApplied, retentionDuration, retentionTrigger } = args.options;
123
+ if ([actionAfterRetentionPeriod, behaviorDuringRetentionPeriod, defaultRecordBehavior, descriptionForAdmins, descriptionForUsers, labelToBeApplied, retentionDuration, retentionTrigger].every(i => typeof i === 'undefined')) {
124
+ return `Specify at least one property to update.`;
125
+ }
126
+ if (behaviorDuringRetentionPeriod && this.allowedBehaviorDuringRetentionPeriodValues.indexOf(behaviorDuringRetentionPeriod) === -1) {
127
+ return `'${behaviorDuringRetentionPeriod}' is not a valid value for the behaviorDuringRetentionPeriod option. Allowed values are ${this.allowedBehaviorDuringRetentionPeriodValues.join('|')}`;
128
+ }
129
+ if (actionAfterRetentionPeriod && this.allowedActionAfterRetentionPeriodValues.indexOf(actionAfterRetentionPeriod) === -1) {
130
+ return `'${actionAfterRetentionPeriod}' is not a valid value for the actionAfterRetentionPeriod option. Allowed values are ${this.allowedActionAfterRetentionPeriodValues.join('|')}`;
131
+ }
132
+ if (retentionTrigger && this.allowedRetentionTriggerValues.indexOf(retentionTrigger) === -1) {
133
+ return `'${retentionTrigger}' is not a valid value for the retentionTrigger option. Allowed values are ${this.allowedRetentionTriggerValues.join('|')}`;
134
+ }
135
+ if (defaultRecordBehavior && this.allowedDefaultRecordBehaviorValues.indexOf(defaultRecordBehavior) === -1) {
136
+ return `'${defaultRecordBehavior}' is not a valid value for the defaultRecordBehavior option. Allowed values are ${this.allowedDefaultRecordBehaviorValues.join('|')}`;
137
+ }
138
+ return true;
139
+ }));
140
+ };
141
+ module.exports = new PurviewRetentionLabelSetCommand();
142
+ //# sourceMappingURL=retentionlabel-set.js.map
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const prefix = 'purview';
4
4
  exports.default = {
5
5
  RETENTIONLABEL_LIST: `${prefix} retentionlabel list`,
6
- RETENTIONLABEL_REMOVE: `${prefix} retentionlabel remove`
6
+ RETENTIONLABEL_REMOVE: `${prefix} retentionlabel remove`,
7
+ RETENTIONLABEL_SET: `${prefix} retentionlabel set`
7
8
  };
8
9
  //# sourceMappingURL=commands.js.map