@pnp/cli-microsoft365 10.3.0-beta.cd20f0c → 10.3.0-beta.d1b978f

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 (27) hide show
  1. package/.eslintrc.cjs +1 -0
  2. package/README.md +11 -6
  3. package/allCommands.json +1 -1
  4. package/allCommandsFull.json +1 -1
  5. package/dist/m365/commands/login.js +6 -6
  6. package/dist/m365/entra/commands/approleassignment/approleassignment-remove.js +1 -1
  7. package/dist/m365/entra/commands/group/group-list.js +3 -2
  8. package/dist/m365/spo/commands/file/file-roleassignment-add.js +26 -2
  9. package/dist/m365/spo/commands/file/file-roleassignment-remove.js +26 -2
  10. package/dist/m365/spo/commands/folder/folder-roleassignment-add.js +28 -12
  11. package/dist/m365/spo/commands/folder/folder-roleassignment-remove.js +24 -7
  12. package/dist/m365/spo/commands/list/list-defaultvalue-list.js +140 -0
  13. package/dist/m365/spo/commands/listitem/listitem-roleassignment-add.js +25 -7
  14. package/dist/m365/spo/commands/listitem/listitem-roleassignment-remove.js +22 -5
  15. package/dist/m365/spo/commands/web/web-roleassignment-add.js +22 -5
  16. package/dist/m365/spo/commands/web/web-roleassignment-remove.js +22 -5
  17. package/dist/m365/spo/commands.js +1 -0
  18. package/docs/docs/cmd/spo/file/file-roleassignment-add.mdx +21 -4
  19. package/docs/docs/cmd/spo/file/file-roleassignment-remove.mdx +21 -3
  20. package/docs/docs/cmd/spo/folder/folder-roleassignment-add.mdx +15 -3
  21. package/docs/docs/cmd/spo/folder/folder-roleassignment-remove.mdx +15 -3
  22. package/docs/docs/cmd/spo/list/list-defaultvalue-list.mdx +110 -0
  23. package/docs/docs/cmd/spo/listitem/listitem-roleassignment-add.mdx +15 -3
  24. package/docs/docs/cmd/spo/listitem/listitem-roleassignment-remove.mdx +17 -5
  25. package/docs/docs/cmd/spo/web/web-roleassignment-add.mdx +15 -3
  26. package/docs/docs/cmd/spo/web/web-roleassignment-remove.mdx +15 -3
  27. package/package.json +1 -1
@@ -37,16 +37,16 @@ class LoginCommand extends Command {
37
37
  }
38
38
  getRefinedSchema(schema) {
39
39
  return schema
40
- .refine(options => typeof options.appId !== 'undefined' || cli.getClientId(), {
41
- message: `appId is required. TIP: use the "m365 setup" command to configure the default appId`,
40
+ .refine(options => typeof options.appId !== 'undefined' || cli.getClientId() || options.authType === 'identity', {
41
+ message: `appId is required. TIP: use the "m365 setup" command to configure the default appId.`,
42
42
  path: ['appId']
43
43
  })
44
44
  .refine(options => options.authType !== 'password' || options.userName, {
45
- message: 'Username is required when using password authentication',
45
+ message: 'Username is required when using password authentication.',
46
46
  path: ['userName']
47
47
  })
48
48
  .refine(options => options.authType !== 'password' || options.password, {
49
- message: 'Password is required when using password authentication',
49
+ message: 'Password is required when using password authentication.',
50
50
  path: ['password']
51
51
  })
52
52
  .refine(options => options.authType !== 'certificate' || !(options.certificateFile && options.certificateBase64Encoded), {
@@ -58,13 +58,13 @@ class LoginCommand extends Command {
58
58
  options.certificateBase64Encoded ||
59
59
  cli.getConfig().get(settingsNames.clientCertificateFile) ||
60
60
  cli.getConfig().get(settingsNames.clientCertificateBase64Encoded), {
61
- message: 'Specify either certificateFile or certificateBase64Encoded',
61
+ message: 'Specify either certificateFile or certificateBase64Encoded.',
62
62
  path: ['certificateFile']
63
63
  })
64
64
  .refine(options => options.authType !== 'secret' ||
65
65
  options.secret ||
66
66
  cli.getConfig().get(settingsNames.clientSecret), {
67
- message: 'Secret is required when using secret authentication',
67
+ message: 'Secret is required when using secret authentication.',
68
68
  path: ['secret']
69
69
  });
70
70
  }
@@ -111,7 +111,7 @@ class EntraAppRoleAssignmentRemoveCommand extends GraphCommand {
111
111
  await removeAppRoleAssignment();
112
112
  }
113
113
  else {
114
- const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove the appRoleAssignment with scope ${args.options.scope} for resource ${args.options.resource}?` });
114
+ const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove the appRoleAssignment with scope(s) ${args.options.scopes} for resource ${args.options.resource}?` });
115
115
  if (result) {
116
116
  await removeAppRoleAssignment();
117
117
  }
@@ -39,7 +39,8 @@ class EntraGroupListCommand extends GraphCommand {
39
39
  requestUrl += '?$filter=securityEnabled eq true and mailEnabled eq false';
40
40
  break;
41
41
  case 'distribution':
42
- requestUrl += '?$filter=securityEnabled eq false and mailEnabled eq true';
42
+ useConsistencyLevelHeader = true;
43
+ requestUrl += `?$filter=securityEnabled eq false and mailEnabled eq true and not(groupTypes/any(t:t eq 'Unified'))&$count=true`;
43
44
  break;
44
45
  case 'mailEnabledSecurity':
45
46
  useConsistencyLevelHeader = true;
@@ -77,7 +78,7 @@ class EntraGroupListCommand extends GraphCommand {
77
78
  }
78
79
  if (cli.shouldTrimOutput(args.options.output)) {
79
80
  groups.forEach((group) => {
80
- if (group.groupTypes && group.groupTypes.length > 0 && group.groupTypes[0] === 'Unified') {
81
+ if (group.groupTypes && group.groupTypes.length > 0 && group.groupTypes.includes('Unified')) {
81
82
  group.groupType = 'Microsoft 365';
82
83
  }
83
84
  else if (group.mailEnabled && group.securityEnabled) {
@@ -11,6 +11,7 @@ import { urlUtil } from '../../../../utils/urlUtil.js';
11
11
  import { validation } from '../../../../utils/validation.js';
12
12
  import SpoCommand from '../../../base/SpoCommand.js';
13
13
  import commands from '../../commands.js';
14
+ import { entraGroup } from '../../../../utils/entraGroup.js';
14
15
  class SpoFileRoleAssignmentAddCommand extends SpoCommand {
15
16
  get name() {
16
17
  return commands.FILE_ROLEASSIGNMENT_ADD;
@@ -42,6 +43,20 @@ class SpoFileRoleAssignmentAddCommand extends SpoCommand {
42
43
  const groupPrincipalId = await this.getGroupPrincipalId(args.options, logger);
43
44
  await this.addRoleAssignment(fileUrl, args.options.webUrl, groupPrincipalId, roleDefinitionId);
44
45
  }
46
+ else if (args.options.entraGroupId || args.options.entraGroupName) {
47
+ if (this.verbose) {
48
+ await logger.logToStderr('Retrieving group information...');
49
+ }
50
+ let group;
51
+ if (args.options.entraGroupId) {
52
+ group = await entraGroup.getGroupById(args.options.entraGroupId);
53
+ }
54
+ else {
55
+ group = await entraGroup.getGroupByDisplayName(args.options.entraGroupName);
56
+ }
57
+ const entraSiteUser = await spo.ensureEntraGroup(args.options.webUrl, group);
58
+ await this.addRoleAssignment(fileUrl, args.options.webUrl, entraSiteUser.Id, roleDefinitionId);
59
+ }
45
60
  else {
46
61
  await this.addRoleAssignment(fileUrl, args.options.webUrl, args.options.principalId, roleDefinitionId);
47
62
  }
@@ -93,6 +108,8 @@ _SpoFileRoleAssignmentAddCommand_instances = new WeakSet(), _SpoFileRoleAssignme
93
108
  principalId: typeof args.options.principalId !== 'undefined',
94
109
  upn: typeof args.options.upn !== 'undefined',
95
110
  groupName: typeof args.options.groupName !== 'undefined',
111
+ entraGroupId: typeof args.options.entraGroupId !== 'undefined',
112
+ entraGroupName: typeof args.options.entraGroupName !== 'undefined',
96
113
  roleDefinitionId: typeof args.options.roleDefinitionId !== 'undefined',
97
114
  roleDefinitionName: typeof args.options.roleDefinitionName !== 'undefined'
98
115
  });
@@ -110,6 +127,10 @@ _SpoFileRoleAssignmentAddCommand_instances = new WeakSet(), _SpoFileRoleAssignme
110
127
  option: '--upn [upn]'
111
128
  }, {
112
129
  option: '--groupName [groupName]'
130
+ }, {
131
+ option: '--entraGroupId [entraGroupId]'
132
+ }, {
133
+ option: '--entraGroupName [entraGroupName]'
113
134
  }, {
114
135
  option: '--roleDefinitionId [roleDefinitionId]'
115
136
  }, {
@@ -127,15 +148,18 @@ _SpoFileRoleAssignmentAddCommand_instances = new WeakSet(), _SpoFileRoleAssignme
127
148
  if (args.options.principalId && isNaN(args.options.principalId)) {
128
149
  return `Specified principalId ${args.options.principalId} is not a number`;
129
150
  }
151
+ if (args.options.entraGroupId && !validation.isValidGuid(args.options.entraGroupId)) {
152
+ return `'${args.options.entraGroupId}' is not a valid GUID for option entraGroupId`;
153
+ }
130
154
  if (args.options.roleDefinitionId && isNaN(args.options.roleDefinitionId)) {
131
155
  return `Specified roleDefinitionId ${args.options.roleDefinitionId} is not a number`;
132
156
  }
133
157
  return true;
134
158
  });
135
159
  }, _SpoFileRoleAssignmentAddCommand_initOptionSets = function _SpoFileRoleAssignmentAddCommand_initOptionSets() {
136
- this.optionSets.push({ options: ['fileId', 'fileUrl'] }, { options: ['principalId', 'upn', 'groupName'] }, { options: ['roleDefinitionId', 'roleDefinitionName'] });
160
+ this.optionSets.push({ options: ['fileId', 'fileUrl'] }, { options: ['principalId', 'upn', 'groupName', 'entraGroupId', 'entraGroupName'] }, { options: ['roleDefinitionId', 'roleDefinitionName'] });
137
161
  }, _SpoFileRoleAssignmentAddCommand_initTypes = function _SpoFileRoleAssignmentAddCommand_initTypes() {
138
- this.types.string.push('webUrl', 'fileUrl', 'fileId', 'upn', 'groupName', 'roleDefinitionName');
162
+ this.types.string.push('webUrl', 'fileUrl', 'fileId', 'upn', 'groupName', 'entraGroupId', 'entraGroupName', 'roleDefinitionName');
139
163
  };
140
164
  export default new SpoFileRoleAssignmentAddCommand();
141
165
  //# sourceMappingURL=file-roleassignment-add.js.map
@@ -12,6 +12,7 @@ import { urlUtil } from '../../../../utils/urlUtil.js';
12
12
  import { validation } from '../../../../utils/validation.js';
13
13
  import SpoCommand from '../../../base/SpoCommand.js';
14
14
  import commands from '../../commands.js';
15
+ import { entraGroup } from '../../../../utils/entraGroup.js';
15
16
  class SpoFileRoleAssignmentRemoveCommand extends SpoCommand {
16
17
  get name() {
17
18
  return commands.FILE_ROLEASSIGNMENT_REMOVE;
@@ -42,6 +43,20 @@ class SpoFileRoleAssignmentRemoveCommand extends SpoCommand {
42
43
  else if (args.options.upn) {
43
44
  principalId = await this.getUserPrincipalId(args.options, logger);
44
45
  }
46
+ else if (args.options.entraGroupId || args.options.entraGroupName) {
47
+ if (this.verbose) {
48
+ await logger.logToStderr('Retrieving group information...');
49
+ }
50
+ let group;
51
+ if (args.options.entraGroupId) {
52
+ group = await entraGroup.getGroupById(args.options.entraGroupId);
53
+ }
54
+ else {
55
+ group = await entraGroup.getGroupByDisplayName(args.options.entraGroupName);
56
+ }
57
+ const entraSiteUser = await spo.ensureEntraGroup(args.options.webUrl, group);
58
+ principalId = entraSiteUser.Id;
59
+ }
45
60
  else {
46
61
  principalId = args.options.principalId;
47
62
  }
@@ -93,6 +108,8 @@ _SpoFileRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoFileRoleAssig
93
108
  principalId: typeof args.options.principalId !== 'undefined',
94
109
  upn: typeof args.options.upn !== 'undefined',
95
110
  groupName: typeof args.options.groupName !== 'undefined',
111
+ entraGroupId: typeof args.options.entraGroupId !== 'undefined',
112
+ entraGroupName: typeof args.options.entraGroupName !== 'undefined',
96
113
  force: !!args.options.force
97
114
  });
98
115
  });
@@ -109,6 +126,10 @@ _SpoFileRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoFileRoleAssig
109
126
  option: '--upn [upn]'
110
127
  }, {
111
128
  option: '--groupName [groupName]'
129
+ }, {
130
+ option: '--entraGroupId [entraGroupId]'
131
+ }, {
132
+ option: '--entraGroupName [entraGroupName]'
112
133
  }, {
113
134
  option: '-f, --force'
114
135
  });
@@ -121,15 +142,18 @@ _SpoFileRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoFileRoleAssig
121
142
  if (args.options.principalId && isNaN(args.options.principalId)) {
122
143
  return `Specified principalId ${args.options.principalId} is not a number`;
123
144
  }
145
+ if (args.options.entraGroupId && !validation.isValidGuid(args.options.entraGroupId)) {
146
+ return `'${args.options.entraGroupId}' is not a valid GUID for option entraGroupId`;
147
+ }
124
148
  if (args.options.fileId && !validation.isValidGuid(args.options.fileId)) {
125
149
  return `${args.options.fileId} is not a valid GUID`;
126
150
  }
127
151
  return true;
128
152
  });
129
153
  }, _SpoFileRoleAssignmentRemoveCommand_initOptionSets = function _SpoFileRoleAssignmentRemoveCommand_initOptionSets() {
130
- this.optionSets.push({ options: ['fileUrl', 'fileId'] }, { options: ['upn', 'groupName', 'principalId'] });
154
+ this.optionSets.push({ options: ['fileUrl', 'fileId'] }, { options: ['upn', 'groupName', 'principalId', 'entraGroupId', 'entraGroupName'] });
131
155
  }, _SpoFileRoleAssignmentRemoveCommand_initTypes = function _SpoFileRoleAssignmentRemoveCommand_initTypes() {
132
- this.types.string.push('webUrl', 'fileUrl', 'fileId', 'upn', 'groupName');
156
+ this.types.string.push('webUrl', 'fileUrl', 'fileId', 'upn', 'groupName', 'entraGroupId', 'entraGroupName');
133
157
  this.types.boolean.push('force');
134
158
  };
135
159
  export default new SpoFileRoleAssignmentRemoveCommand();
@@ -14,6 +14,8 @@ import commands from '../../commands.js';
14
14
  import spoGroupGetCommand from '../group/group-get.js';
15
15
  import spoRoleDefinitionFolderCommand from '../roledefinition/roledefinition-list.js';
16
16
  import spoUserGetCommand from '../user/user-get.js';
17
+ import { entraGroup } from '../../../../utils/entraGroup.js';
18
+ import { spo } from '../../../../utils/spo.js';
17
19
  class SpoFolderRoleAssignmentAddCommand extends SpoCommand {
18
20
  get name() {
19
21
  return commands.FOLDER_ROLEASSIGNMENT_ADD;
@@ -45,20 +47,25 @@ class SpoFolderRoleAssignmentAddCommand extends SpoCommand {
45
47
  requestUrl += `GetFolderByServerRelativePath(DecodedUrl='${formatting.encodeQueryParameter(serverRelativeUrl)}')/ListItemAllFields`;
46
48
  }
47
49
  const roleDefinitionId = await this.getRoleDefinitionId(args.options);
50
+ let principalId = args.options.principalId;
48
51
  if (args.options.upn) {
49
- const upnPrincipalId = await this.getUserPrincipalId(args.options);
50
- await this.breakRoleAssignment(requestUrl);
51
- await this.addRoleAssignment(requestUrl, upnPrincipalId, roleDefinitionId);
52
+ principalId = await this.getUserPrincipalId(args.options);
52
53
  }
53
54
  else if (args.options.groupName) {
54
- const groupPrincipalId = await this.getGroupPrincipalId(args.options);
55
- await this.breakRoleAssignment(requestUrl);
56
- await this.addRoleAssignment(requestUrl, groupPrincipalId, roleDefinitionId);
55
+ principalId = await this.getGroupPrincipalId(args.options);
57
56
  }
58
- else {
59
- await this.breakRoleAssignment(requestUrl);
60
- await this.addRoleAssignment(requestUrl, args.options.principalId, roleDefinitionId);
57
+ else if (args.options.entraGroupId || args.options.entraGroupName) {
58
+ if (this.verbose) {
59
+ await logger.logToStderr('Retrieving group information...');
60
+ }
61
+ const group = args.options.entraGroupId
62
+ ? await entraGroup.getGroupById(args.options.entraGroupId)
63
+ : await entraGroup.getGroupByDisplayName(args.options.entraGroupName);
64
+ const siteUser = await spo.ensureEntraGroup(args.options.webUrl, group);
65
+ principalId = siteUser.Id;
61
66
  }
67
+ await this.breakRoleAssignment(requestUrl);
68
+ await this.addRoleAssignment(requestUrl, principalId, roleDefinitionId);
62
69
  }
63
70
  catch (err) {
64
71
  this.handleRejectedODataJsonPromise(err);
@@ -140,6 +147,8 @@ _SpoFolderRoleAssignmentAddCommand_instances = new WeakSet(), _SpoFolderRoleAssi
140
147
  principalId: typeof args.options.principalId !== 'undefined',
141
148
  upn: typeof args.options.upn !== 'undefined',
142
149
  groupName: typeof args.options.groupName !== 'undefined',
150
+ entraGroupId: typeof args.options.entraGroupId !== 'undefined',
151
+ entraGroupName: typeof args.options.entraGroupName !== 'undefined',
143
152
  roleDefinitionId: typeof args.options.roleDefinitionId !== 'undefined',
144
153
  roleDefinitionName: typeof args.options.roleDefinitionName !== 'undefined'
145
154
  });
@@ -155,6 +164,10 @@ _SpoFolderRoleAssignmentAddCommand_instances = new WeakSet(), _SpoFolderRoleAssi
155
164
  option: '--upn [upn]'
156
165
  }, {
157
166
  option: '--groupName [groupName]'
167
+ }, {
168
+ option: '--entraGroupId [entraGroupId]'
169
+ }, {
170
+ option: '--entraGroupName [entraGroupName]'
158
171
  }, {
159
172
  option: '--roleDefinitionId [roleDefinitionId]'
160
173
  }, {
@@ -169,15 +182,18 @@ _SpoFolderRoleAssignmentAddCommand_instances = new WeakSet(), _SpoFolderRoleAssi
169
182
  if (args.options.principalId && isNaN(args.options.principalId)) {
170
183
  return `Specified principalId ${args.options.principalId} is not a number`;
171
184
  }
185
+ if (args.options.entraGroupId && !validation.isValidGuid(args.options.entraGroupId)) {
186
+ return `'${args.options.entraGroupId}' is not a valid GUID for option entraGroupId.`;
187
+ }
172
188
  if (args.options.roleDefinitionId && isNaN(args.options.roleDefinitionId)) {
173
189
  return `Specified roleDefinitionId ${args.options.roleDefinitionId} is not a number`;
174
190
  }
175
- const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName];
191
+ const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName, args.options.entraGroupId, args.options.entraGroupName];
176
192
  if (!principalOptions.some(item => item !== undefined)) {
177
- return `Specify either principalId, upn or groupName`;
193
+ return `Specify either principalId, upn, groupName, entraGroupId or entraGroupName`;
178
194
  }
179
195
  if (principalOptions.filter(item => item !== undefined).length > 1) {
180
- return `Specify either principalId, upn or groupName but not multiple`;
196
+ return `Specify either principalId, upn, groupName, entraGroupId or entraGroupName but not multiple`;
181
197
  }
182
198
  const roleDefinitionOptions = [args.options.roleDefinitionId, args.options.roleDefinitionName];
183
199
  if (!roleDefinitionOptions.some(item => item !== undefined)) {
@@ -13,6 +13,8 @@ import SpoCommand from '../../../base/SpoCommand.js';
13
13
  import commands from '../../commands.js';
14
14
  import spoGroupGetCommand from '../group/group-get.js';
15
15
  import spoUserGetCommand from '../user/user-get.js';
16
+ import { entraGroup } from '../../../../utils/entraGroup.js';
17
+ import { spo } from '../../../../utils/spo.js';
16
18
  class SpoFolderRoleAssignmentRemoveCommand extends SpoCommand {
17
19
  get name() {
18
20
  return commands.FOLDER_ROLEASSIGNMENT_REMOVE;
@@ -38,15 +40,21 @@ class SpoFolderRoleAssignmentRemoveCommand extends SpoCommand {
38
40
  try {
39
41
  if (args.options.upn) {
40
42
  args.options.principalId = await this.getUserPrincipalId(args.options);
41
- await this.removeRoleAssignment(requestUrl, logger, args.options);
42
43
  }
43
44
  else if (args.options.groupName) {
44
45
  args.options.principalId = await this.getGroupPrincipalId(args.options);
45
- await this.removeRoleAssignment(requestUrl, logger, args.options);
46
46
  }
47
- else {
48
- await this.removeRoleAssignment(requestUrl, logger, args.options);
47
+ else if (args.options.entraGroupId || args.options.entraGroupName) {
48
+ if (this.verbose) {
49
+ await logger.logToStderr('Retrieving group information...');
50
+ }
51
+ const group = args.options.entraGroupId
52
+ ? await entraGroup.getGroupById(args.options.entraGroupId)
53
+ : await entraGroup.getGroupByDisplayName(args.options.entraGroupName);
54
+ const siteUser = await spo.ensureEntraGroup(args.options.webUrl, group);
55
+ args.options.principalId = siteUser.Id;
49
56
  }
57
+ await this.removeRoleAssignment(requestUrl, logger, args.options);
50
58
  }
51
59
  catch (err) {
52
60
  this.handleRejectedODataJsonPromise(err);
@@ -106,6 +114,8 @@ _SpoFolderRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoFolderRoleA
106
114
  principalId: typeof args.options.principalId !== 'undefined',
107
115
  upn: typeof args.options.upn !== 'undefined',
108
116
  groupName: typeof args.options.groupName !== 'undefined',
117
+ entraGroupId: typeof args.options.entraGroupId !== 'undefined',
118
+ entraGroupName: typeof args.options.entraGroupName !== 'undefined',
109
119
  force: !!args.options.force
110
120
  });
111
121
  });
@@ -120,6 +130,10 @@ _SpoFolderRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoFolderRoleA
120
130
  option: '--upn [upn]'
121
131
  }, {
122
132
  option: '--groupName [groupName]'
133
+ }, {
134
+ option: '--entraGroupId [entraGroupId]'
135
+ }, {
136
+ option: '--entraGroupName [entraGroupName]'
123
137
  }, {
124
138
  option: '-f, --force'
125
139
  });
@@ -132,12 +146,15 @@ _SpoFolderRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoFolderRoleA
132
146
  if (args.options.principalId && isNaN(args.options.principalId)) {
133
147
  return `Specified principalId ${args.options.principalId} is not a number`;
134
148
  }
135
- const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName];
149
+ if (args.options.entraGroupId && !validation.isValidGuid(args.options.entraGroupId)) {
150
+ return `'${args.options.entraGroupId}' is not a valid GUID for option entraGroupId.`;
151
+ }
152
+ const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName, args.options.entraGroupId, args.options.entraGroupName];
136
153
  if (principalOptions.some(item => item !== undefined) && principalOptions.filter(item => item !== undefined).length > 1) {
137
- return `Specify either principalId id, upn or groupName`;
154
+ return `Specify either principalId id, upn, groupName, entraGroupId or entraGroupName`;
138
155
  }
139
156
  if (principalOptions.filter(item => item !== undefined).length === 0) {
140
- return `Specify at least principalId id, upn or groupName`;
157
+ return `Specify at least principalId id, upn, groupName, entraGroupId or entraGroupName`;
141
158
  }
142
159
  return true;
143
160
  });
@@ -0,0 +1,140 @@
1
+ import SpoCommand from '../../../base/SpoCommand.js';
2
+ import { globalOptionsZod } from '../../../../Command.js';
3
+ import { z } from 'zod';
4
+ import { zod } from '../../../../utils/zod.js';
5
+ import commands from '../../commands.js';
6
+ import { DOMParser } from '@xmldom/xmldom';
7
+ import { validation } from '../../../../utils/validation.js';
8
+ import { urlUtil } from '../../../../utils/urlUtil.js';
9
+ import request from '../../../../request.js';
10
+ import { formatting } from '../../../../utils/formatting.js';
11
+ const options = globalOptionsZod
12
+ .extend({
13
+ webUrl: zod.alias('u', z.string()
14
+ .refine(url => validation.isValidSharePointUrl(url) === true, url => ({
15
+ message: `'${url}' is not a valid SharePoint Online site URL.`
16
+ }))),
17
+ listId: zod.alias('i', z.string().optional()
18
+ .refine(id => id === undefined || validation.isValidGuid(id), id => ({
19
+ message: `'${id}' is not a valid GUID.`
20
+ }))),
21
+ listTitle: zod.alias('t', z.string().optional()),
22
+ listUrl: z.string().optional(),
23
+ folderUrl: z.string().optional()
24
+ })
25
+ .strict();
26
+ class SpoListDefaultValueListCommand extends SpoCommand {
27
+ get name() {
28
+ return commands.LIST_DEFAULTVALUE_LIST;
29
+ }
30
+ get description() {
31
+ return 'Retrieves default column values for a specific document library';
32
+ }
33
+ get schema() {
34
+ return options;
35
+ }
36
+ getRefinedSchema(schema) {
37
+ return schema
38
+ .refine(options => [options.listId, options.listTitle, options.listUrl].filter(o => o !== undefined).length === 1, {
39
+ message: 'Use one of the following options: listId, listTitle, listUrl.'
40
+ });
41
+ }
42
+ async commandAction(logger, args) {
43
+ try {
44
+ if (this.verbose) {
45
+ await logger.logToStderr(`Retrieving default column values for list '${args.options.listId || args.options.listTitle || args.options.listUrl}'...`);
46
+ await logger.logToStderr('Retrieving list information...');
47
+ }
48
+ const listServerRelUrl = await this.getServerRelativeListUrl(args.options);
49
+ if (this.verbose) {
50
+ await logger.logToStderr('Retrieving default column values...');
51
+ }
52
+ let defaultValues;
53
+ try {
54
+ const defaultValuesXml = await this.getDefaultColumnValuesXml(args.options.webUrl, listServerRelUrl);
55
+ defaultValues = this.convertXmlToJson(defaultValuesXml);
56
+ }
57
+ catch (err) {
58
+ if (err.status !== 404) {
59
+ throw err;
60
+ }
61
+ // For lists that have never had default column values set, the client_LocationBasedDefaults.html file does not exist.
62
+ defaultValues = [];
63
+ }
64
+ if (args.options.folderUrl) {
65
+ const serverRelFolderUrl = urlUtil.removeTrailingSlashes(urlUtil.getServerRelativePath(args.options.webUrl, args.options.folderUrl));
66
+ defaultValues = defaultValues.filter(d => d.folderUrl.toLowerCase() === serverRelFolderUrl.toLowerCase());
67
+ }
68
+ await logger.log(defaultValues);
69
+ }
70
+ catch (err) {
71
+ this.handleRejectedODataJsonPromise(err);
72
+ }
73
+ }
74
+ async getServerRelativeListUrl(options) {
75
+ const requestOptions = {
76
+ url: `${options.webUrl}/_api/Web`,
77
+ headers: {
78
+ accept: 'application/json;odata=nometadata'
79
+ },
80
+ responseType: 'json'
81
+ };
82
+ if (options.listUrl) {
83
+ const serverRelativeUrl = urlUtil.getServerRelativePath(options.webUrl, options.listUrl);
84
+ requestOptions.url += `/GetList('${serverRelativeUrl}')`;
85
+ }
86
+ else if (options.listId) {
87
+ requestOptions.url += `/Lists('${options.listId}')`;
88
+ }
89
+ else if (options.listTitle) {
90
+ requestOptions.url += `/Lists/GetByTitle('${formatting.encodeQueryParameter(options.listTitle)}')`;
91
+ }
92
+ requestOptions.url += '?$expand=RootFolder&$select=RootFolder/ServerRelativeUrl,BaseTemplate';
93
+ try {
94
+ const response = await request.get(requestOptions);
95
+ if (response.BaseTemplate !== 101) {
96
+ throw `List '${options.listId || options.listTitle || options.listUrl}' is not a document library.`;
97
+ }
98
+ return response.RootFolder.ServerRelativeUrl;
99
+ }
100
+ catch (error) {
101
+ if (error.status === 404) {
102
+ throw `List '${options.listId || options.listTitle || options.listUrl}' was not found.`;
103
+ }
104
+ throw error;
105
+ }
106
+ }
107
+ async getDefaultColumnValuesXml(webUrl, listServerRelUrl) {
108
+ const requestOptions = {
109
+ url: `${webUrl}/_api/Web/GetFileByServerRelativePath(decodedUrl='${formatting.encodeQueryParameter(listServerRelUrl + '/Forms/client_LocationBasedDefaults.html')}')/$value`,
110
+ headers: {
111
+ accept: 'application/json;odata=nometadata'
112
+ },
113
+ responseType: 'json'
114
+ };
115
+ const defaultValuesXml = await request.get(requestOptions);
116
+ return defaultValuesXml;
117
+ }
118
+ convertXmlToJson(xml) {
119
+ const results = [];
120
+ const parser = new DOMParser();
121
+ const doc = parser.parseFromString(xml, 'application/xml');
122
+ const folderLinks = doc.getElementsByTagName('a');
123
+ for (let i = 0; i < folderLinks.length; i++) {
124
+ const folderUrl = folderLinks[i].getAttribute('href');
125
+ const defaultValues = folderLinks[i].getElementsByTagName('DefaultValue');
126
+ for (let j = 0; j < defaultValues.length; j++) {
127
+ const fieldName = defaultValues[j].getAttribute('FieldName');
128
+ const fieldValue = defaultValues[j].textContent;
129
+ results.push({
130
+ fieldName: fieldName,
131
+ fieldValue: fieldValue,
132
+ folderUrl: decodeURIComponent(folderUrl)
133
+ });
134
+ }
135
+ }
136
+ return results;
137
+ }
138
+ }
139
+ export default new SpoListDefaultValueListCommand();
140
+ //# sourceMappingURL=list-defaultvalue-list.js.map
@@ -6,6 +6,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
6
6
  var _SpoListItemRoleAssignmentAddCommand_instances, _SpoListItemRoleAssignmentAddCommand_initTelemetry, _SpoListItemRoleAssignmentAddCommand_initOptions, _SpoListItemRoleAssignmentAddCommand_initValidators;
7
7
  import { cli } from '../../../../cli/cli.js';
8
8
  import request from '../../../../request.js';
9
+ import { entraGroup } from '../../../../utils/entraGroup.js';
9
10
  import { formatting } from '../../../../utils/formatting.js';
10
11
  import { urlUtil } from '../../../../utils/urlUtil.js';
11
12
  import { validation } from '../../../../utils/validation.js';
@@ -14,6 +15,7 @@ import commands from '../../commands.js';
14
15
  import spoGroupGetCommand from '../group/group-get.js';
15
16
  import spoRoleDefinitionListCommand from '../roledefinition/roledefinition-list.js';
16
17
  import spoUserGetCommand from '../user/user-get.js';
18
+ import { spo } from '../../../../utils/spo.js';
17
19
  class SpoListItemRoleAssignmentAddCommand extends SpoCommand {
18
20
  get name() {
19
21
  return commands.LISTITEM_ROLEASSIGNMENT_ADD;
@@ -46,7 +48,7 @@ class SpoListItemRoleAssignmentAddCommand extends SpoCommand {
46
48
  }
47
49
  requestUrl += `items(${args.options.listItemId})/`;
48
50
  const roleDefinitionId = await this.getRoleDefinitionId(args.options);
49
- let principalId = 0;
51
+ let principalId = args.options.principalId;
50
52
  if (args.options.upn) {
51
53
  principalId = await this.getUserPrincipalId(args.options);
52
54
  await this.addRoleAssignment(requestUrl, roleDefinitionId, principalId);
@@ -55,10 +57,17 @@ class SpoListItemRoleAssignmentAddCommand extends SpoCommand {
55
57
  principalId = await this.getGroupPrincipalId(args.options);
56
58
  await this.addRoleAssignment(requestUrl, roleDefinitionId, principalId);
57
59
  }
58
- else {
59
- principalId = args.options.principalId;
60
- await this.addRoleAssignment(requestUrl, roleDefinitionId, principalId);
60
+ else if (args.options.entraGroupId || args.options.entraGroupName) {
61
+ if (this.verbose) {
62
+ await logger.logToStderr('Retrieving group information...');
63
+ }
64
+ const group = args.options.entraGroupId
65
+ ? await entraGroup.getGroupById(args.options.entraGroupId)
66
+ : await entraGroup.getGroupByDisplayName(args.options.entraGroupName);
67
+ const siteUser = await spo.ensureEntraGroup(args.options.webUrl, group);
68
+ principalId = siteUser.Id;
61
69
  }
70
+ await this.addRoleAssignment(requestUrl, roleDefinitionId, principalId);
62
71
  }
63
72
  catch (err) {
64
73
  this.handleRejectedODataJsonPromise(err);
@@ -126,6 +135,8 @@ _SpoListItemRoleAssignmentAddCommand_instances = new WeakSet(), _SpoListItemRole
126
135
  principalId: typeof args.options.principalId !== 'undefined',
127
136
  upn: typeof args.options.upn !== 'undefined',
128
137
  groupName: typeof args.options.groupName !== 'undefined',
138
+ entraGroupId: typeof args.options.entraGroupId !== 'undefined',
139
+ entraGroupName: typeof args.options.entraGroupName !== 'undefined',
129
140
  roleDefinitionId: typeof args.options.roleDefinitionId !== 'undefined',
130
141
  roleDefinitionName: typeof args.options.roleDefinitionName !== 'undefined'
131
142
  });
@@ -147,6 +158,10 @@ _SpoListItemRoleAssignmentAddCommand_instances = new WeakSet(), _SpoListItemRole
147
158
  option: '--upn [upn]'
148
159
  }, {
149
160
  option: '--groupName [groupName]'
161
+ }, {
162
+ option: '--entraGroupId [entraGroupId]'
163
+ }, {
164
+ option: '--entraGroupName [entraGroupName]'
150
165
  }, {
151
166
  option: '--roleDefinitionId [roleDefinitionId]'
152
167
  }, {
@@ -177,12 +192,15 @@ _SpoListItemRoleAssignmentAddCommand_instances = new WeakSet(), _SpoListItemRole
177
192
  if (listOptions.filter(item => item !== undefined).length === 0) {
178
193
  return `Specify at least list id or title or list url`;
179
194
  }
180
- const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName];
195
+ const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName, args.options.entraGroupId, args.options.entraGroupName];
181
196
  if (!principalOptions.some(item => item !== undefined)) {
182
- return `Specify either principalId, upn or groupName`;
197
+ return `Specify either principalId, upn, groupName, entraGroupId or entraGroupName`;
183
198
  }
184
199
  if (principalOptions.filter(item => item !== undefined).length > 1) {
185
- return `Specify either principalId, upn or groupName but not multiple`;
200
+ return `Specify either principalId, upn, groupName, entraGroupId or entraGroupName but not multiple`;
201
+ }
202
+ if (args.options.entraGroupId && !validation.isValidGuid(args.options.entraGroupId)) {
203
+ return `'${args.options.entraGroupId}' is not a valid GUID for option entraGroupId.`;
186
204
  }
187
205
  const roleDefinitionOptions = [args.options.roleDefinitionId, args.options.roleDefinitionName];
188
206
  if (!roleDefinitionOptions.some(item => item !== undefined)) {