@pnp/cli-microsoft365 6.1.0-beta.4fefcde → 6.1.0-beta.6108255

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 (28) 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/purview/commands/retentionlabel/retentionlabel-set.js +142 -0
  9. package/dist/m365/purview/commands.js +2 -1
  10. package/dist/m365/spo/commands/group/group-member-add.js +68 -30
  11. package/dist/m365/spo/commands/group/group-member-remove.js +50 -7
  12. package/dist/m365/spo/commands/list/{list-retentionlabel-set.js → list-retentionlabel-ensure.js} +21 -15
  13. package/dist/m365/spo/commands/listitem/listitem-remove.js +1 -1
  14. package/dist/m365/spo/commands/listitem/listitem-retentionlabel-remove.js +143 -0
  15. package/dist/m365/spo/commands.js +2 -1
  16. package/dist/request.js +2 -1
  17. package/docs/docs/cmd/aad/group/group-get.md +127 -0
  18. package/docs/docs/cmd/aad/user/user-set.md +31 -3
  19. package/docs/docs/cmd/context/context-init.md +25 -0
  20. package/docs/docs/cmd/context/context-remove.md +34 -0
  21. package/docs/docs/cmd/purview/retentionlabel/retentionlabel-set.md +63 -0
  22. package/docs/docs/cmd/spo/group/group-member-add.md +58 -6
  23. package/docs/docs/cmd/spo/group/group-member-remove.md +24 -8
  24. package/docs/docs/cmd/spo/list/list-retentionlabel-ensure.md +65 -0
  25. package/docs/docs/cmd/spo/listitem/listitem-remove.md +6 -6
  26. package/docs/docs/cmd/spo/listitem/listitem-retentionlabel-remove.md +55 -0
  27. package/package.json +1 -1
  28. package/docs/docs/cmd/spo/list/list-retentionlabel-set.md +0 -65
@@ -20,6 +20,7 @@ const request_1 = require("../../../../request");
20
20
  const formatting_1 = require("../../../../utils/formatting");
21
21
  const validation_1 = require("../../../../utils/validation");
22
22
  const AadUserGetCommand = require("../../../aad/commands/user/user-get");
23
+ const SpoUserGetCommand = require("../user/user-get");
23
24
  const SpoCommand_1 = require("../../../base/SpoCommand");
24
25
  const commands_1 = require("../../commands");
25
26
  class SpoGroupMemberAddCommand extends SpoCommand_1.default {
@@ -43,10 +44,10 @@ class SpoGroupMemberAddCommand extends SpoCommand_1.default {
43
44
  commandAction(logger, args) {
44
45
  return __awaiter(this, void 0, void 0, function* () {
45
46
  try {
46
- const groupId = yield this.getGroupId(args);
47
+ const groupId = yield this.getGroupId(args, logger);
47
48
  const resolvedUsernameList = yield this.getValidUsers(args, logger);
48
49
  if (this.verbose) {
49
- logger.logToStderr(`Start adding Active user/s to SharePoint Group ${args.options.groupId ? args.options.groupId : args.options.groupName}`);
50
+ logger.logToStderr(`Adding user(s) to SharePoint Group ${args.options.groupId ? args.options.groupId : args.options.groupName}`);
50
51
  }
51
52
  const data = {
52
53
  url: args.options.webUrl,
@@ -73,7 +74,10 @@ class SpoGroupMemberAddCommand extends SpoCommand_1.default {
73
74
  }
74
75
  });
75
76
  }
76
- getGroupId(args) {
77
+ getGroupId(args, logger) {
78
+ if (this.verbose) {
79
+ logger.logToStderr(`Getting group Id for SharePoint Group ${args.options.groupId ? args.options.groupId : args.options.groupName}`);
80
+ }
77
81
  const getGroupMethod = args.options.groupName ?
78
82
  `GetByName('${formatting_1.formatting.encodeQueryParameter(args.options.groupName)}')` :
79
83
  `GetById('${args.options.groupId}')`;
@@ -100,34 +104,23 @@ class SpoGroupMemberAddCommand extends SpoCommand_1.default {
100
104
  }
101
105
  const validUserNames = [];
102
106
  const invalidUserNames = [];
103
- const userInfo = args.options.userName ? args.options.userName : args.options.email;
107
+ const userIdentifiers = args.options.userName || args.options.email || args.options.userId.toString();
104
108
  return Promise
105
- .all(userInfo.split(',').map(singleUserName => {
106
- const options = {
107
- output: 'json',
108
- debug: args.options.debug,
109
- verbose: args.options.verbose
110
- };
111
- if (args.options.userName) {
112
- options.userName = singleUserName.trim();
113
- }
114
- else {
115
- options.email = singleUserName.trim();
116
- }
117
- return Cli_1.Cli
118
- .executeCommandWithOutput(AadUserGetCommand, { options: Object.assign(Object.assign({}, options), { _: [] }) })
119
- .then((getUserGetOutput) => {
120
- if (this.debug) {
121
- logger.logToStderr(getUserGetOutput.stderr);
109
+ .all(userIdentifiers.split(',').map((userIdentifier) => __awaiter(this, void 0, void 0, function* () {
110
+ try {
111
+ if (args.options.userId) {
112
+ yield this.spoUserGet(args.options, userIdentifier.trim(), logger, validUserNames);
122
113
  }
123
- validUserNames.push(JSON.parse(getUserGetOutput.stdout).userPrincipalName);
124
- }, (err) => {
125
- if (this.debug) {
126
- logger.logToStderr(err.stderr);
114
+ else {
115
+ yield this.aadUserGet(args.options, userIdentifier.trim(), logger, validUserNames);
127
116
  }
128
- invalidUserNames.push(singleUserName);
129
- });
130
- }))
117
+ }
118
+ catch (err) {
119
+ logger.logToStderr(err.stderr);
120
+ invalidUserNames.push(userIdentifier);
121
+ return err;
122
+ }
123
+ })))
131
124
  .then(() => {
132
125
  if (invalidUserNames.length > 0) {
133
126
  return Promise.reject(`Users not added to the group because the following users don't exist: ${invalidUserNames.join(', ')}`);
@@ -135,6 +128,38 @@ class SpoGroupMemberAddCommand extends SpoCommand_1.default {
135
128
  return Promise.resolve(validUserNames);
136
129
  });
137
130
  }
131
+ aadUserGet(options, userIdentifier, logger, validUserNames) {
132
+ return __awaiter(this, void 0, void 0, function* () {
133
+ if (this.verbose) {
134
+ logger.logToStderr(`Get UPN from Azure AD for user ${userIdentifier}`);
135
+ }
136
+ const aadUserGetCommandoptions = Object.assign(Object.assign(Object.assign({}, (options.userName && { userName: userIdentifier })), (options.email && { email: userIdentifier })), { output: 'json', debug: options.debug, verbose: options.verbose });
137
+ const aadUserGetOutput = yield Cli_1.Cli.executeCommandWithOutput(AadUserGetCommand, { options: Object.assign(Object.assign({}, aadUserGetCommandoptions), { _: [] }) });
138
+ if (this.debug) {
139
+ logger.logToStderr(aadUserGetOutput.stderr);
140
+ }
141
+ validUserNames.push(JSON.parse(aadUserGetOutput.stdout).userPrincipalName);
142
+ });
143
+ }
144
+ spoUserGet(options, userIdentifier, logger, validUserNames) {
145
+ return __awaiter(this, void 0, void 0, function* () {
146
+ if (this.verbose) {
147
+ logger.logToStderr(`Get UPN from SharePoint for user ${userIdentifier}`);
148
+ }
149
+ const spoUserGetCommandoptions = {
150
+ id: userIdentifier,
151
+ webUrl: options.webUrl,
152
+ output: 'json',
153
+ debug: options.debug,
154
+ verbose: options.verbose
155
+ };
156
+ const spoUserGetOutput = yield Cli_1.Cli.executeCommandWithOutput(SpoUserGetCommand, { options: Object.assign(Object.assign({}, spoUserGetCommandoptions), { _: [] }) });
157
+ if (this.debug) {
158
+ logger.logToStderr(spoUserGetOutput.stderr);
159
+ }
160
+ validUserNames.push(JSON.parse(spoUserGetOutput.stdout).UserPrincipalName);
161
+ });
162
+ }
138
163
  getFormattedUserList(activeUserList) {
139
164
  const generatedPeoplePicker = JSON.stringify(activeUserList.map(singleUsername => {
140
165
  return { Key: singleUsername.trim() };
@@ -148,7 +173,8 @@ _SpoGroupMemberAddCommand_instances = new WeakSet(), _SpoGroupMemberAddCommand_i
148
173
  groupId: typeof args.options.groupId !== 'undefined',
149
174
  groupName: typeof args.options.groupName !== 'undefined',
150
175
  userName: typeof args.options.userName !== 'undefined',
151
- email: typeof args.options.email !== 'undefined'
176
+ email: typeof args.options.email !== 'undefined',
177
+ userId: typeof args.options.userId !== 'undefined'
152
178
  });
153
179
  });
154
180
  }, _SpoGroupMemberAddCommand_initOptions = function _SpoGroupMemberAddCommand_initOptions() {
@@ -162,6 +188,8 @@ _SpoGroupMemberAddCommand_instances = new WeakSet(), _SpoGroupMemberAddCommand_i
162
188
  option: '--userName [userName]'
163
189
  }, {
164
190
  option: '--email [email]'
191
+ }, {
192
+ option: '--userId [userId]'
165
193
  });
166
194
  }, _SpoGroupMemberAddCommand_initValidators = function _SpoGroupMemberAddCommand_initValidators() {
167
195
  this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
@@ -172,10 +200,20 @@ _SpoGroupMemberAddCommand_instances = new WeakSet(), _SpoGroupMemberAddCommand_i
172
200
  if (args.options.groupId && isNaN(args.options.groupId)) {
173
201
  return `Specified groupId ${args.options.groupId} is not a number`;
174
202
  }
203
+ const userIdReg = new RegExp(/^[0-9,]*$/);
204
+ if (args.options.userId && !userIdReg.test(args.options.userId)) {
205
+ return `${args.options.userId} is not a number or a comma seperated value`;
206
+ }
207
+ if (args.options.userName && args.options.userName.split(',').some(e => !validation_1.validation.isValidUserPrincipalName(e))) {
208
+ return `${args.options.userName} contains one or more invalid usernames`;
209
+ }
210
+ if (args.options.email && args.options.email.split(',').some(e => !validation_1.validation.isValidUserPrincipalName(e))) {
211
+ return `${args.options.email} contains one or more invalid email addresses`;
212
+ }
175
213
  return true;
176
214
  }));
177
215
  }, _SpoGroupMemberAddCommand_initOptionSets = function _SpoGroupMemberAddCommand_initOptionSets() {
178
- this.optionSets.push({ options: ['groupId', 'groupName'] }, { options: ['userName', 'email'] });
216
+ this.optionSets.push({ options: ['groupId', 'groupName'] }, { options: ['userName', 'email', 'userId'] });
179
217
  };
180
218
  module.exports = new SpoGroupMemberAddCommand();
181
219
  //# sourceMappingURL=group-member-add.js.map
@@ -19,6 +19,7 @@ const Cli_1 = require("../../../../cli/Cli");
19
19
  const request_1 = require("../../../../request");
20
20
  const formatting_1 = require("../../../../utils/formatting");
21
21
  const validation_1 = require("../../../../utils/validation");
22
+ const AadUserGetCommand = require("../../../aad/commands/user/user-get");
22
23
  const SpoCommand_1 = require("../../../base/SpoCommand");
23
24
  const commands_1 = require("../../commands");
24
25
  class SpoGroupMemberRemoveCommand extends SpoCommand_1.default {
@@ -36,16 +37,42 @@ class SpoGroupMemberRemoveCommand extends SpoCommand_1.default {
36
37
  __classPrivateFieldGet(this, _SpoGroupMemberRemoveCommand_instances, "m", _SpoGroupMemberRemoveCommand_initValidators).call(this);
37
38
  __classPrivateFieldGet(this, _SpoGroupMemberRemoveCommand_instances, "m", _SpoGroupMemberRemoveCommand_initOptionSets).call(this);
38
39
  }
40
+ getUserName(logger, args) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ if (args.options.userName) {
43
+ return args.options.userName;
44
+ }
45
+ if (this.verbose) {
46
+ logger.logToStderr(`Retrieving information about the user ${args.options.email}`);
47
+ }
48
+ const options = {
49
+ email: args.options.email,
50
+ output: 'json',
51
+ debug: args.options.debug,
52
+ verbose: args.options.verbose
53
+ };
54
+ const userGetOutput = yield Cli_1.Cli.executeCommandWithOutput(AadUserGetCommand, { options: Object.assign(Object.assign({}, options), { _: [] }) });
55
+ const userOutput = JSON.parse(userGetOutput.stdout);
56
+ return userOutput.userPrincipalName;
57
+ });
58
+ }
39
59
  commandAction(logger, args) {
40
60
  return __awaiter(this, void 0, void 0, function* () {
41
61
  const removeUserfromSPGroup = () => __awaiter(this, void 0, void 0, function* () {
42
62
  if (this.verbose) {
43
- logger.logToStderr(`Removing User with Username ${args.options.userName} from Group: ${args.options.groupId ? args.options.groupId : args.options.groupName}`);
63
+ logger.logToStderr(`Removing User ${args.options.userName || args.options.email || args.options.userId} from Group: ${args.options.groupId ? args.options.groupId : args.options.groupName}`);
44
64
  }
45
- const loginName = `i:0#.f|membership|${args.options.userName}`;
46
- const requestUrl = `${args.options.webUrl}/_api/web/sitegroups/${args.options.groupId
65
+ let requestUrl = `${args.options.webUrl}/_api/web/sitegroups/${args.options.groupId
47
66
  ? `GetById('${args.options.groupId}')`
48
- : `GetByName('${formatting_1.formatting.encodeQueryParameter(args.options.groupName)}')`}/users/removeByLoginName(@LoginName)?@LoginName='${formatting_1.formatting.encodeQueryParameter(loginName)}'`;
67
+ : `GetByName('${formatting_1.formatting.encodeQueryParameter(args.options.groupName)}')`}`;
68
+ if (args.options.userId) {
69
+ requestUrl += `/users/removeById(${args.options.userId})`;
70
+ }
71
+ else {
72
+ const userName = yield this.getUserName(logger, args);
73
+ const loginName = `i:0#.f|membership|${userName}`;
74
+ requestUrl += `/users/removeByLoginName(@LoginName)?@LoginName='${formatting_1.formatting.encodeQueryParameter(loginName)}'`;
75
+ }
49
76
  const requestOptions = {
50
77
  url: requestUrl,
51
78
  headers: {
@@ -71,7 +98,7 @@ class SpoGroupMemberRemoveCommand extends SpoCommand_1.default {
71
98
  type: 'confirm',
72
99
  name: 'continue',
73
100
  default: false,
74
- message: `Are you sure you want to remove user User ${args.options.userName} from SharePoint group?`
101
+ message: `Are you sure you want to remove user ${args.options.userName || args.options.userId || args.options.email} from the SharePoint group?`
75
102
  });
76
103
  if (result.continue) {
77
104
  yield removeUserfromSPGroup();
@@ -85,6 +112,9 @@ _SpoGroupMemberRemoveCommand_instances = new WeakSet(), _SpoGroupMemberRemoveCom
85
112
  Object.assign(this.telemetryProperties, {
86
113
  groupId: (!(!args.options.groupId)).toString(),
87
114
  groupName: (!(!args.options.groupName)).toString(),
115
+ userName: (!(!args.options.userName)).toString(),
116
+ email: (!(!args.options.email)).toString(),
117
+ userId: (!(!args.options.userId)).toString(),
88
118
  confirm: (!(!args.options.confirm)).toString()
89
119
  });
90
120
  });
@@ -96,7 +126,11 @@ _SpoGroupMemberRemoveCommand_instances = new WeakSet(), _SpoGroupMemberRemoveCom
96
126
  }, {
97
127
  option: '--groupName [groupName]'
98
128
  }, {
99
- option: '--userName <userName>'
129
+ option: '--userName [userName]'
130
+ }, {
131
+ option: '--email [email]'
132
+ }, {
133
+ option: '--userId [userId]'
100
134
  }, {
101
135
  option: '--confirm'
102
136
  });
@@ -105,10 +139,19 @@ _SpoGroupMemberRemoveCommand_instances = new WeakSet(), _SpoGroupMemberRemoveCom
105
139
  if (args.options.groupId && isNaN(args.options.groupId)) {
106
140
  return `Specified "groupId" ${args.options.groupId} is not valid`;
107
141
  }
142
+ if (args.options.userId && isNaN(args.options.userId)) {
143
+ return `Specified "userId" ${args.options.userId} is not valid`;
144
+ }
145
+ if (args.options.userName && !validation_1.validation.isValidUserPrincipalName(args.options.userName)) {
146
+ return `${args.options.userName} is not a valid userName`;
147
+ }
148
+ if (args.options.email && !validation_1.validation.isValidUserPrincipalName(args.options.email)) {
149
+ return `${args.options.email} is not a valid email`;
150
+ }
108
151
  return validation_1.validation.isValidSharePointUrl(args.options.webUrl);
109
152
  }));
110
153
  }, _SpoGroupMemberRemoveCommand_initOptionSets = function _SpoGroupMemberRemoveCommand_initOptionSets() {
111
- this.optionSets.push({ options: ['groupName', 'groupId'] });
154
+ this.optionSets.push({ options: ['groupName', 'groupId'] }, { options: ['userName', 'email', 'userId'] });
112
155
  };
113
156
  module.exports = new SpoGroupMemberRemoveCommand();
114
157
  //# sourceMappingURL=group-member-remove.js.map
@@ -13,7 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
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
14
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
15
  };
16
- var _SpoListRetentionLabelSetCommand_instances, _SpoListRetentionLabelSetCommand_initTelemetry, _SpoListRetentionLabelSetCommand_initOptions, _SpoListRetentionLabelSetCommand_initValidators, _SpoListRetentionLabelSetCommand_initOptionSets;
16
+ var _SpoListRetentionLabelEnsureCommand_instances, _SpoListRetentionLabelEnsureCommand_initTelemetry, _SpoListRetentionLabelEnsureCommand_initOptions, _SpoListRetentionLabelEnsureCommand_initValidators, _SpoListRetentionLabelEnsureCommand_initOptionSets;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  const request_1 = require("../../../../request");
19
19
  const formatting_1 = require("../../../../utils/formatting");
@@ -21,9 +21,9 @@ const urlUtil_1 = require("../../../../utils/urlUtil");
21
21
  const validation_1 = require("../../../../utils/validation");
22
22
  const SpoCommand_1 = require("../../../base/SpoCommand");
23
23
  const commands_1 = require("../../commands");
24
- class SpoListRetentionLabelSetCommand extends SpoCommand_1.default {
24
+ class SpoListRetentionLabelEnsureCommand extends SpoCommand_1.default {
25
25
  get name() {
26
- return commands_1.default.LIST_RETENTIONLABEL_SET;
26
+ return commands_1.default.LIST_RETENTIONLABEL_ENSURE;
27
27
  }
28
28
  alias() {
29
29
  return [commands_1.default.LIST_LABEL_SET];
@@ -33,15 +33,21 @@ class SpoListRetentionLabelSetCommand extends SpoCommand_1.default {
33
33
  }
34
34
  constructor() {
35
35
  super();
36
- _SpoListRetentionLabelSetCommand_instances.add(this);
37
- __classPrivateFieldGet(this, _SpoListRetentionLabelSetCommand_instances, "m", _SpoListRetentionLabelSetCommand_initTelemetry).call(this);
38
- __classPrivateFieldGet(this, _SpoListRetentionLabelSetCommand_instances, "m", _SpoListRetentionLabelSetCommand_initOptions).call(this);
39
- __classPrivateFieldGet(this, _SpoListRetentionLabelSetCommand_instances, "m", _SpoListRetentionLabelSetCommand_initValidators).call(this);
40
- __classPrivateFieldGet(this, _SpoListRetentionLabelSetCommand_instances, "m", _SpoListRetentionLabelSetCommand_initOptionSets).call(this);
36
+ _SpoListRetentionLabelEnsureCommand_instances.add(this);
37
+ __classPrivateFieldGet(this, _SpoListRetentionLabelEnsureCommand_instances, "m", _SpoListRetentionLabelEnsureCommand_initTelemetry).call(this);
38
+ __classPrivateFieldGet(this, _SpoListRetentionLabelEnsureCommand_instances, "m", _SpoListRetentionLabelEnsureCommand_initOptions).call(this);
39
+ __classPrivateFieldGet(this, _SpoListRetentionLabelEnsureCommand_instances, "m", _SpoListRetentionLabelEnsureCommand_initValidators).call(this);
40
+ __classPrivateFieldGet(this, _SpoListRetentionLabelEnsureCommand_instances, "m", _SpoListRetentionLabelEnsureCommand_initOptionSets).call(this);
41
41
  }
42
42
  commandAction(logger, args) {
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
- this.showDeprecationWarning(logger, commands_1.default.LIST_LABEL_SET, commands_1.default.LIST_RETENTIONLABEL_SET);
44
+ this.showDeprecationWarning(logger, commands_1.default.LIST_LABEL_SET, commands_1.default.LIST_RETENTIONLABEL_ENSURE);
45
+ if (args.options.blockDelete) {
46
+ this.warn(logger, `Option 'blockDelete' is deprecated.`);
47
+ }
48
+ if (args.options.blockEdit) {
49
+ this.warn(logger, `Option 'blockEdit' is deprecated.`);
50
+ }
45
51
  try {
46
52
  let listRestUrl = '';
47
53
  let listServerRelativeUrl = '';
@@ -90,7 +96,7 @@ class SpoListRetentionLabelSetCommand extends SpoCommand_1.default {
90
96
  });
91
97
  }
92
98
  }
93
- _SpoListRetentionLabelSetCommand_instances = new WeakSet(), _SpoListRetentionLabelSetCommand_initTelemetry = function _SpoListRetentionLabelSetCommand_initTelemetry() {
99
+ _SpoListRetentionLabelEnsureCommand_instances = new WeakSet(), _SpoListRetentionLabelEnsureCommand_initTelemetry = function _SpoListRetentionLabelEnsureCommand_initTelemetry() {
94
100
  this.telemetry.push((args) => {
95
101
  Object.assign(this.telemetryProperties, {
96
102
  listId: (!(!args.options.listId)).toString(),
@@ -101,7 +107,7 @@ _SpoListRetentionLabelSetCommand_instances = new WeakSet(), _SpoListRetentionLab
101
107
  blockEdit: args.options.blockEdit || false
102
108
  });
103
109
  });
104
- }, _SpoListRetentionLabelSetCommand_initOptions = function _SpoListRetentionLabelSetCommand_initOptions() {
110
+ }, _SpoListRetentionLabelEnsureCommand_initOptions = function _SpoListRetentionLabelEnsureCommand_initOptions() {
105
111
  this.options.unshift({
106
112
  option: '-u, --webUrl <webUrl>'
107
113
  }, {
@@ -119,15 +125,15 @@ _SpoListRetentionLabelSetCommand_instances = new WeakSet(), _SpoListRetentionLab
119
125
  }, {
120
126
  option: '--blockEdit'
121
127
  });
122
- }, _SpoListRetentionLabelSetCommand_initValidators = function _SpoListRetentionLabelSetCommand_initValidators() {
128
+ }, _SpoListRetentionLabelEnsureCommand_initValidators = function _SpoListRetentionLabelEnsureCommand_initValidators() {
123
129
  this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
124
130
  if (args.options.listId && !validation_1.validation.isValidGuid(args.options.listId)) {
125
131
  return `${args.options.listId} is not a valid GUID`;
126
132
  }
127
133
  return validation_1.validation.isValidSharePointUrl(args.options.webUrl);
128
134
  }));
129
- }, _SpoListRetentionLabelSetCommand_initOptionSets = function _SpoListRetentionLabelSetCommand_initOptionSets() {
135
+ }, _SpoListRetentionLabelEnsureCommand_initOptionSets = function _SpoListRetentionLabelEnsureCommand_initOptionSets() {
130
136
  this.optionSets.push({ options: ['listId', 'listTitle', 'listUrl'] });
131
137
  };
132
- module.exports = new SpoListRetentionLabelSetCommand();
133
- //# sourceMappingURL=list-retentionlabel-set.js.map
138
+ module.exports = new SpoListRetentionLabelEnsureCommand();
139
+ //# sourceMappingURL=list-retentionlabel-ensure.js.map
@@ -41,7 +41,7 @@ class SpoListItemRemoveCommand extends SpoCommand_1.default {
41
41
  return __awaiter(this, void 0, void 0, function* () {
42
42
  const removeListItem = () => __awaiter(this, void 0, void 0, function* () {
43
43
  if (this.verbose) {
44
- logger.logToStderr(`Removing list from list ${args.options.listId || args.options.listTitle || args.options.listUrl} item in site at ${args.options.webUrl}...`);
44
+ logger.logToStderr(`Removing list item ${args.options.id} from list ${args.options.listId || args.options.listTitle || args.options.listUrl} in site at ${args.options.webUrl}...`);
45
45
  }
46
46
  let requestUrl = `${args.options.webUrl}/_api/web`;
47
47
  if (args.options.listId) {
@@ -0,0 +1,143 @@
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 _SpoListItemRetentionLabelRemoveCommand_instances, _SpoListItemRetentionLabelRemoveCommand_initTelemetry, _SpoListItemRetentionLabelRemoveCommand_initOptions, _SpoListItemRetentionLabelRemoveCommand_initValidators, _SpoListItemRetentionLabelRemoveCommand_initOptionSets;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const Cli_1 = require("../../../../cli/Cli");
19
+ const request_1 = require("../../../../request");
20
+ const formatting_1 = require("../../../../utils/formatting");
21
+ const urlUtil_1 = require("../../../../utils/urlUtil");
22
+ const validation_1 = require("../../../../utils/validation");
23
+ const SpoCommand_1 = require("../../../base/SpoCommand");
24
+ const commands_1 = require("../../commands");
25
+ class SpoListItemRetentionLabelRemoveCommand extends SpoCommand_1.default {
26
+ get name() {
27
+ return commands_1.default.LISTITEM_RETENTIONLABEL_REMOVE;
28
+ }
29
+ get description() {
30
+ return 'Clear the retention label from a list item';
31
+ }
32
+ constructor() {
33
+ super();
34
+ _SpoListItemRetentionLabelRemoveCommand_instances.add(this);
35
+ __classPrivateFieldGet(this, _SpoListItemRetentionLabelRemoveCommand_instances, "m", _SpoListItemRetentionLabelRemoveCommand_initTelemetry).call(this);
36
+ __classPrivateFieldGet(this, _SpoListItemRetentionLabelRemoveCommand_instances, "m", _SpoListItemRetentionLabelRemoveCommand_initOptions).call(this);
37
+ __classPrivateFieldGet(this, _SpoListItemRetentionLabelRemoveCommand_instances, "m", _SpoListItemRetentionLabelRemoveCommand_initValidators).call(this);
38
+ __classPrivateFieldGet(this, _SpoListItemRetentionLabelRemoveCommand_instances, "m", _SpoListItemRetentionLabelRemoveCommand_initOptionSets).call(this);
39
+ }
40
+ commandAction(logger, args) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ if (args.options.confirm) {
43
+ yield this.removeListItemRetentionLabel(logger, args);
44
+ }
45
+ else {
46
+ const result = yield Cli_1.Cli.prompt({
47
+ type: 'confirm',
48
+ name: 'continue',
49
+ default: false,
50
+ message: `Are you sure you want to remove the retentionlabel from list item ${args.options.listItemId} from list ${args.options.listId || args.options.listTitle || args.options.listUrl} located in site ${args.options.webUrl}?`
51
+ });
52
+ if (result.continue) {
53
+ yield this.removeListItemRetentionLabel(logger, args);
54
+ }
55
+ }
56
+ });
57
+ }
58
+ removeListItemRetentionLabel(logger, args) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ if (this.verbose) {
61
+ logger.logToStderr(`Removing retention label from list ${args.options.listId || args.options.listTitle || args.options.listUrl} in site at ${args.options.webUrl}...`);
62
+ }
63
+ try {
64
+ let url = `${args.options.webUrl}/_api/web`;
65
+ if (args.options.listId) {
66
+ url += `/lists(guid'${formatting_1.formatting.encodeQueryParameter(args.options.listId)}')/items(${args.options.listItemId})/SetComplianceTag()`;
67
+ }
68
+ else if (args.options.listTitle) {
69
+ url += `/lists/getByTitle('${formatting_1.formatting.encodeQueryParameter(args.options.listTitle)}')/items(${args.options.listItemId})/SetComplianceTag()`;
70
+ }
71
+ else {
72
+ const listServerRelativeUrl = urlUtil_1.urlUtil.getServerRelativePath(args.options.webUrl, args.options.listUrl);
73
+ url += `/GetList(@a1)/items(@a2)/SetComplianceTag()?@a1='${formatting_1.formatting.encodeQueryParameter(listServerRelativeUrl)}'&@a2='${args.options.listItemId}'`;
74
+ }
75
+ const requestBody = {
76
+ "complianceTag": "",
77
+ "isTagPolicyHold": false,
78
+ "isTagPolicyRecord": false,
79
+ "isEventBasedTag": false,
80
+ "isTagSuperLock": false,
81
+ "isUnlockedAsDefault": false
82
+ };
83
+ const requestOptions = {
84
+ url: url,
85
+ method: 'POST',
86
+ headers: {
87
+ 'accept': 'application/json;odata=nometadata'
88
+ },
89
+ data: requestBody,
90
+ responseType: 'json'
91
+ };
92
+ yield request_1.default.post(requestOptions);
93
+ }
94
+ catch (err) {
95
+ this.handleRejectedODataJsonPromise(err);
96
+ }
97
+ });
98
+ }
99
+ }
100
+ _SpoListItemRetentionLabelRemoveCommand_instances = new WeakSet(), _SpoListItemRetentionLabelRemoveCommand_initTelemetry = function _SpoListItemRetentionLabelRemoveCommand_initTelemetry() {
101
+ this.telemetry.push((args) => {
102
+ Object.assign(this.telemetryProperties, {
103
+ listId: typeof args.options.listId !== 'undefined',
104
+ listTitle: typeof args.options.listTitle !== 'undefined',
105
+ listUrl: typeof args.options.listUrl !== 'undefined',
106
+ confirm: !!args.options.confirm
107
+ });
108
+ });
109
+ }, _SpoListItemRetentionLabelRemoveCommand_initOptions = function _SpoListItemRetentionLabelRemoveCommand_initOptions() {
110
+ this.options.unshift({
111
+ option: '-u, --webUrl <webUrl>'
112
+ }, {
113
+ option: '-i, --listItemId <listItemId>'
114
+ }, {
115
+ option: '-l, --listId [listId]'
116
+ }, {
117
+ option: '-t, --listTitle [listTitle]'
118
+ }, {
119
+ option: '--listUrl [listUrl]'
120
+ }, {
121
+ option: '--confirm'
122
+ });
123
+ }, _SpoListItemRetentionLabelRemoveCommand_initValidators = function _SpoListItemRetentionLabelRemoveCommand_initValidators() {
124
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
125
+ const id = parseInt(args.options.listItemId);
126
+ if (isNaN(id)) {
127
+ return `${args.options.listItemId} is not a valid list item ID`;
128
+ }
129
+ const isValidSharePointUrl = validation_1.validation.isValidSharePointUrl(args.options.webUrl);
130
+ if (isValidSharePointUrl !== true) {
131
+ return isValidSharePointUrl;
132
+ }
133
+ if (args.options.listId &&
134
+ !validation_1.validation.isValidGuid(args.options.listId)) {
135
+ return `${args.options.listId} is not a valid GUID`;
136
+ }
137
+ return true;
138
+ }));
139
+ }, _SpoListItemRetentionLabelRemoveCommand_initOptionSets = function _SpoListItemRetentionLabelRemoveCommand_initOptionSets() {
140
+ this.optionSets.push({ options: ['listId', 'listTitle', 'listUrl'] });
141
+ };
142
+ module.exports = new SpoListItemRetentionLabelRemoveCommand();
143
+ //# sourceMappingURL=listitem-retentionlabel-remove.js.map
@@ -115,8 +115,8 @@ exports.default = {
115
115
  LIST_LABEL_SET: `${prefix} list label set`,
116
116
  LIST_LIST: `${prefix} list list`,
117
117
  LIST_REMOVE: `${prefix} list remove`,
118
+ LIST_RETENTIONLABEL_ENSURE: `${prefix} list retentionlabel ensure`,
118
119
  LIST_RETENTIONLABEL_GET: `${prefix} list retentionlabel get`,
119
- LIST_RETENTIONLABEL_SET: `${prefix} list retentionlabel set`,
120
120
  LIST_ROLEASSIGNMENT_REMOVE: `${prefix} list roleassignment remove`,
121
121
  LIST_ROLEASSIGNMENT_ADD: `${prefix} list roleassignment add`,
122
122
  LIST_ROLEINHERITANCE_BREAK: `${prefix} list roleinheritance break`,
@@ -145,6 +145,7 @@ exports.default = {
145
145
  LISTITEM_RECORD_DECLARE: `${prefix} listitem record declare`,
146
146
  LISTITEM_RECORD_UNDECLARE: `${prefix} listitem record undeclare`,
147
147
  LISTITEM_REMOVE: `${prefix} listitem remove`,
148
+ LISTITEM_RETENTIONLABEL_REMOVE: `${prefix} listitem retentionlabel remove`,
148
149
  LISTITEM_ROLEASSIGNMENT_ADD: `${prefix} listitem roleassignment add`,
149
150
  LISTITEM_ROLEASSIGNMENT_REMOVE: `${prefix} listitem roleassignment remove`,
150
151
  LISTITEM_ROLEINHERITANCE_BREAK: `${prefix} listitem roleinheritance break`,
package/dist/request.js CHANGED
@@ -61,7 +61,8 @@ class Request {
61
61
  this.req = axios_1.default.create({
62
62
  headers: {
63
63
  'user-agent': `NONISV|SharePointPnP|CLIMicrosoft365/${packageJSON.version}`,
64
- 'accept-encoding': 'gzip, deflate'
64
+ 'accept-encoding': 'gzip, deflate',
65
+ 'X-ClientService-ClientTag': `M365CLI:${packageJSON.version}`
65
66
  },
66
67
  decompress: true,
67
68
  responseType: 'text',