@pnp/cli-microsoft365 8.0.0-beta.5dade25 → 8.0.0-beta.b0e3dab

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.
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  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");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _FlowListCommand_instances, _FlowListCommand_initTelemetry, _FlowListCommand_initOptions, _FlowListCommand_initValidators;
6
+ var _FlowListCommand_instances, _FlowListCommand_initTelemetry, _FlowListCommand_initOptions, _FlowListCommand_initValidators, _FlowListCommand_initTypes;
7
7
  import { formatting } from '../../../utils/formatting.js';
8
8
  import { odata } from '../../../utils/odata.js';
9
9
  import PowerAutomateCommand from '../../base/PowerAutomateCommand.js';
@@ -13,7 +13,7 @@ class FlowListCommand extends PowerAutomateCommand {
13
13
  return commands.LIST;
14
14
  }
15
15
  get description() {
16
- return 'Lists Microsoft Flows in the given environment';
16
+ return 'Lists Power Automate flows in the given environment';
17
17
  }
18
18
  defaultProperties() {
19
19
  return ['name', 'displayName'];
@@ -25,8 +25,12 @@ class FlowListCommand extends PowerAutomateCommand {
25
25
  __classPrivateFieldGet(this, _FlowListCommand_instances, "m", _FlowListCommand_initTelemetry).call(this);
26
26
  __classPrivateFieldGet(this, _FlowListCommand_instances, "m", _FlowListCommand_initOptions).call(this);
27
27
  __classPrivateFieldGet(this, _FlowListCommand_instances, "m", _FlowListCommand_initValidators).call(this);
28
+ __classPrivateFieldGet(this, _FlowListCommand_instances, "m", _FlowListCommand_initTypes).call(this);
28
29
  }
29
30
  async commandAction(logger, args) {
31
+ if (this.verbose) {
32
+ await logger.logToStderr(`Getting Power Automate flows${args.options.asAdmin && ' as admin'} in environment '${args.options.environmentName}'...`);
33
+ }
30
34
  try {
31
35
  const { environmentName, asAdmin, sharingStatus, includeSolutions } = args.options;
32
36
  let items = [];
@@ -50,34 +54,25 @@ class FlowListCommand extends PowerAutomateCommand {
50
54
  }
51
55
  // Remove duplicates
52
56
  items = items.filter((flow, index, self) => index === self.findIndex(f => f.id === flow.id));
53
- if (items.length > 0) {
54
- items.forEach(i => {
55
- i.displayName = i.properties.displayName;
57
+ if (args.options.output && args.options.output !== 'json') {
58
+ items.forEach(flow => {
59
+ flow.displayName = flow.properties.displayName;
56
60
  });
57
- await logger.log(items);
58
- }
59
- else {
60
- if (this.verbose) {
61
- await logger.logToStderr('No Flows found');
62
- }
63
61
  }
62
+ await logger.log(items);
64
63
  }
65
64
  catch (err) {
66
65
  this.handleRejectedODataJsonPromise(err);
67
66
  }
68
67
  }
69
68
  getApiUrl(environmentName, asAdmin, includeSolutionFlows, filter) {
70
- let url = `${this.resource}/providers/Microsoft.ProcessSimple${asAdmin ? '/scopes/admin' : ''}/environments/${formatting.encodeQueryParameter(environmentName)}/flows?api-version=2016-11-01`;
71
- if (filter === 'personal') {
72
- url += `&$filter=search('personal')`;
73
- }
74
- else if (filter === 'team') {
75
- url += `&$filter=search('team')`;
76
- }
77
- if (includeSolutionFlows) {
78
- url += '&include=includeSolutionCloudFlows';
79
- }
80
- return url;
69
+ const baseEndpoint = `${this.resource}/providers/Microsoft.ProcessSimple`;
70
+ const environmentSegment = `/environments/${formatting.encodeQueryParameter(environmentName)}`;
71
+ const adminSegment = `/scopes/admin${environmentSegment}/v2`;
72
+ const flowsEndpoint = '/flows?api-version=2016-11-01';
73
+ const filterQuery = filter === 'personal' || filter === 'team' ? `&$filter=search('${filter}')` : '';
74
+ const includeQuery = includeSolutionFlows ? '&include=includeSolutionCloudFlows' : '';
75
+ return `${baseEndpoint}${asAdmin ? adminSegment : environmentSegment}${flowsEndpoint}${filterQuery}${includeQuery}`;
81
76
  }
82
77
  }
83
78
  _FlowListCommand_instances = new WeakSet(), _FlowListCommand_initTelemetry = function _FlowListCommand_initTelemetry() {
@@ -105,10 +100,13 @@ _FlowListCommand_instances = new WeakSet(), _FlowListCommand_initTelemetry = fun
105
100
  return `The options asAdmin and sharingStatus cannot be specified together.`;
106
101
  }
107
102
  if (args.options.sharingStatus && !this.allowedSharingStatuses.some(status => status === args.options.sharingStatus)) {
108
- return `${args.options.sharingStatus} is not a valid sharing status. Allowed values are: ${this.allowedSharingStatuses.join(',')}`;
103
+ return `${args.options.sharingStatus} is not a valid sharing status. Allowed values are: ${this.allowedSharingStatuses.join(', ')}`;
109
104
  }
110
105
  return true;
111
106
  });
107
+ }, _FlowListCommand_initTypes = function _FlowListCommand_initTypes() {
108
+ this.types.string.push('environmentName', 'sharingStatus');
109
+ this.types.boolean.push('includeSolutions', 'asAdmin');
112
110
  };
113
111
  export default new FlowListCommand();
114
112
  //# sourceMappingURL=flow-list.js.map
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  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");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _SpoCdnGetCommand_instances, _SpoCdnGetCommand_initTelemetry, _SpoCdnGetCommand_initOptions, _SpoCdnGetCommand_initValidators;
6
+ var _SpoCdnGetCommand_instances, _SpoCdnGetCommand_initTelemetry, _SpoCdnGetCommand_initOptions, _SpoCdnGetCommand_initValidators, _SpoCdnGetCommand_initTypes;
7
7
  import config from '../../../../config.js';
8
8
  import request from '../../../../request.js';
9
9
  import { spo } from '../../../../utils/spo.js';
@@ -19,9 +19,11 @@ class SpoCdnGetCommand extends SpoCommand {
19
19
  constructor() {
20
20
  super();
21
21
  _SpoCdnGetCommand_instances.add(this);
22
+ this.validTypes = ['Public', 'Private'];
22
23
  __classPrivateFieldGet(this, _SpoCdnGetCommand_instances, "m", _SpoCdnGetCommand_initTelemetry).call(this);
23
24
  __classPrivateFieldGet(this, _SpoCdnGetCommand_instances, "m", _SpoCdnGetCommand_initOptions).call(this);
24
25
  __classPrivateFieldGet(this, _SpoCdnGetCommand_instances, "m", _SpoCdnGetCommand_initValidators).call(this);
26
+ __classPrivateFieldGet(this, _SpoCdnGetCommand_instances, "m", _SpoCdnGetCommand_initTypes).call(this);
25
27
  }
26
28
  async commandAction(logger, args) {
27
29
  const cdnTypeString = args.options.type || 'Public';
@@ -48,15 +50,11 @@ class SpoCdnGetCommand extends SpoCommand {
48
50
  if (response.ErrorInfo) {
49
51
  throw response.ErrorInfo.ErrorMessage;
50
52
  }
51
- else {
52
- const result = json[json.length - 1];
53
- if (this.verbose) {
54
- await logger.logToStderr(`${(cdnType === 0 ? 'Public' : 'Private')} CDN at ${spoAdminUrl} is ${(result === true ? 'enabled' : 'disabled')}`);
55
- }
56
- else {
57
- await logger.logToStderr(result);
58
- }
53
+ const result = json[json.length - 1];
54
+ if (this.verbose) {
55
+ await logger.logToStderr(`${cdnType === 0 ? 'Public' : 'Private'} CDN at ${spoAdminUrl} is ${result === true ? 'enabled' : 'disabled'}`);
59
56
  }
57
+ await logger.log(result);
60
58
  }
61
59
  catch (err) {
62
60
  this.handleRejectedPromise(err);
@@ -72,18 +70,17 @@ _SpoCdnGetCommand_instances = new WeakSet(), _SpoCdnGetCommand_initTelemetry = f
72
70
  }, _SpoCdnGetCommand_initOptions = function _SpoCdnGetCommand_initOptions() {
73
71
  this.options.unshift({
74
72
  option: '-t, --type [type]',
75
- autocomplete: ['Public', 'Private']
73
+ autocomplete: this.validTypes
76
74
  });
77
75
  }, _SpoCdnGetCommand_initValidators = function _SpoCdnGetCommand_initValidators() {
78
76
  this.validators.push(async (args) => {
79
- if (args.options.type) {
80
- if (args.options.type !== 'Public' &&
81
- args.options.type !== 'Private') {
82
- return `${args.options.type} is not a valid CDN type. Allowed values are Public|Private`;
83
- }
77
+ if (args.options.type && !this.validTypes.includes(args.options.type)) {
78
+ return `'${args.options.type}' is not a valid CDN type. Allowed values are: ${this.validTypes.join(', ')}.`;
84
79
  }
85
80
  return true;
86
81
  });
82
+ }, _SpoCdnGetCommand_initTypes = function _SpoCdnGetCommand_initTypes() {
83
+ this.types.string.push('type');
87
84
  };
88
85
  export default new SpoCdnGetCommand();
89
86
  //# sourceMappingURL=cdn-get.js.map
@@ -19,6 +19,7 @@ class SpoCdnSetCommand extends SpoCommand {
19
19
  constructor() {
20
20
  super();
21
21
  _SpoCdnSetCommand_instances.add(this);
22
+ this.validTypes = ['Public', 'Private', 'Both'];
22
23
  __classPrivateFieldGet(this, _SpoCdnSetCommand_instances, "m", _SpoCdnSetCommand_initTelemetry).call(this);
23
24
  __classPrivateFieldGet(this, _SpoCdnSetCommand_instances, "m", _SpoCdnSetCommand_initOptions).call(this);
24
25
  __classPrivateFieldGet(this, _SpoCdnSetCommand_instances, "m", _SpoCdnSetCommand_initTypes).call(this);
@@ -104,7 +105,7 @@ _SpoCdnSetCommand_instances = new WeakSet(), _SpoCdnSetCommand_initTelemetry = f
104
105
  Object.assign(this.telemetryProperties, {
105
106
  cdnType: args.options.type || 'Public',
106
107
  enabled: args.options.enabled,
107
- noDefaultOrigins: (!(!args.options.noDefaultOrigins)).toString()
108
+ noDefaultOrigins: !!args.options.noDefaultOrigins
108
109
  });
109
110
  });
110
111
  }, _SpoCdnSetCommand_initOptions = function _SpoCdnSetCommand_initOptions() {
@@ -113,18 +114,19 @@ _SpoCdnSetCommand_instances = new WeakSet(), _SpoCdnSetCommand_initTelemetry = f
113
114
  autocomplete: ['true', 'false']
114
115
  }, {
115
116
  option: '-t, --type [type]',
116
- autocomplete: ['Public', 'Private', 'Both']
117
+ autocomplete: this.validTypes
117
118
  }, {
118
119
  option: '--noDefaultOrigins'
119
120
  });
120
121
  }, _SpoCdnSetCommand_initTypes = function _SpoCdnSetCommand_initTypes() {
121
- this.types.boolean.push('enabled');
122
+ this.types.boolean.push('enabled', 'noDefaultOrigins');
123
+ this.types.string.push('type');
122
124
  }, _SpoCdnSetCommand_initValidators = function _SpoCdnSetCommand_initValidators() {
123
125
  this.validators.push(async (args) => {
124
126
  if (args.options.type) {
125
127
  if (args.options.type !== 'Public' && args.options.type !== 'Both' &&
126
128
  args.options.type !== 'Private') {
127
- return `${args.options.type} is not a valid CDN type. Allowed values are Public|Private|Both`;
129
+ return `${args.options.type} is not a valid CDN type. Allowed values are ${this.validTypes.join(', ')}.`;
128
130
  }
129
131
  }
130
132
  return true;
@@ -3,12 +3,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
3
  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");
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _SpoGroupMemberAddCommand_instances, _SpoGroupMemberAddCommand_initTelemetry, _SpoGroupMemberAddCommand_initOptions, _SpoGroupMemberAddCommand_initValidators, _SpoGroupMemberAddCommand_initOptionSets;
6
+ var _SpoGroupMemberAddCommand_instances, _SpoGroupMemberAddCommand_initTelemetry, _SpoGroupMemberAddCommand_initOptions, _SpoGroupMemberAddCommand_initValidators, _SpoGroupMemberAddCommand_initOptionSets, _SpoGroupMemberAddCommand_initTypes;
7
7
  import request from '../../../../request.js';
8
8
  import { entraGroup } from '../../../../utils/entraGroup.js';
9
- import { entraUser } from '../../../../utils/entraUser.js';
10
9
  import { formatting } from '../../../../utils/formatting.js';
11
- import { spo } from '../../../../utils/spo.js';
12
10
  import { validation } from '../../../../utils/validation.js';
13
11
  import SpoCommand from '../../../base/SpoCommand.js';
14
12
  import commands from '../../commands.js';
@@ -20,7 +18,7 @@ class SpoGroupMemberAddCommand extends SpoCommand {
20
18
  return 'Add members to a SharePoint Group';
21
19
  }
22
20
  defaultProperties() {
23
- return ['DisplayName', 'Email'];
21
+ return ['Title', 'UserPrincipalName'];
24
22
  }
25
23
  constructor() {
26
24
  super();
@@ -29,110 +27,100 @@ class SpoGroupMemberAddCommand extends SpoCommand {
29
27
  __classPrivateFieldGet(this, _SpoGroupMemberAddCommand_instances, "m", _SpoGroupMemberAddCommand_initOptions).call(this);
30
28
  __classPrivateFieldGet(this, _SpoGroupMemberAddCommand_instances, "m", _SpoGroupMemberAddCommand_initValidators).call(this);
31
29
  __classPrivateFieldGet(this, _SpoGroupMemberAddCommand_instances, "m", _SpoGroupMemberAddCommand_initOptionSets).call(this);
30
+ __classPrivateFieldGet(this, _SpoGroupMemberAddCommand_instances, "m", _SpoGroupMemberAddCommand_initTypes).call(this);
32
31
  }
33
32
  async commandAction(logger, args) {
34
33
  try {
35
34
  if (args.options.aadGroupIds) {
36
35
  args.options.entraGroupIds = args.options.aadGroupIds;
37
- await this.warn(logger, `Option 'aadGroupIds' is deprecated. Please use 'entraGroupIds' instead`);
36
+ await this.warn(logger, `Option 'aadGroupIds' is deprecated. Please use 'entraGroupIds' instead.`);
38
37
  }
39
38
  if (args.options.aadGroupNames) {
40
39
  args.options.entraGroupNames = args.options.aadGroupNames;
41
- await this.warn(logger, `Option 'aadGroupNames' is deprecated. Please use 'entraGroupNames' instead`);
40
+ await this.warn(logger, `Option 'aadGroupNames' is deprecated. Please use 'entraGroupNames' instead.`);
42
41
  }
43
- const groupId = await this.getGroupId(args, logger);
44
- const resolvedUsernameList = await this.getValidUsers(args, logger);
42
+ const loginNames = await this.getLoginNames(logger, args.options);
43
+ let apiUrl = `${args.options.webUrl}/_api/web/SiteGroups`;
44
+ if (args.options.groupId) {
45
+ apiUrl += `/GetById(${args.options.groupId})`;
46
+ }
47
+ else {
48
+ apiUrl += `/GetByName('${formatting.encodeQueryParameter(args.options.groupName)}')`;
49
+ }
50
+ apiUrl += '/users';
45
51
  if (this.verbose) {
46
- await logger.logToStderr(`Adding resource(s) to SharePoint Group ${args.options.groupId || args.options.groupName}`);
47
- }
48
- const requestOptions = {
49
- url: `${args.options.webUrl}/_api/SP.Web.ShareObject`,
50
- headers: {
51
- accept: 'application/json;odata=nometadata',
52
- 'content-type': 'application/json;odata=nometadata'
53
- },
54
- responseType: 'json',
55
- data: {
56
- url: args.options.webUrl,
57
- peoplePickerInput: this.getFormattedUserList(resolvedUsernameList),
58
- roleValue: `group:${groupId}`
59
- }
60
- };
61
- const sharingResult = await request.post(requestOptions);
62
- if (sharingResult.ErrorMessage !== null) {
63
- throw sharingResult.ErrorMessage;
52
+ await logger.logToStderr('Adding members to group...');
53
+ }
54
+ const result = [];
55
+ for (const loginName of loginNames) {
56
+ const requestOptions = {
57
+ url: apiUrl,
58
+ headers: {
59
+ accept: 'application/json;odata=nometadata'
60
+ },
61
+ responseType: 'json',
62
+ data: {
63
+ LoginName: loginName
64
+ }
65
+ };
66
+ const response = await request.post(requestOptions);
67
+ result.push(response);
64
68
  }
65
- await logger.log(sharingResult.UsersAddedToGroup);
69
+ await logger.log(result);
66
70
  }
67
71
  catch (err) {
68
72
  this.handleRejectedODataJsonPromise(err);
69
73
  }
70
74
  }
71
- async getGroupId(args, logger) {
72
- if (this.verbose) {
73
- await logger.logToStderr(`Getting group Id for SharePoint Group ${args.options.groupId ? args.options.groupId : args.options.groupName}`);
74
- }
75
- const getGroupMethod = args.options.groupName ?
76
- `GetByName('${formatting.encodeQueryParameter(args.options.groupName)}')` :
77
- `GetById('${args.options.groupId}')`;
78
- const requestOptions = {
79
- url: `${args.options.webUrl}/_api/web/sitegroups/${getGroupMethod}?$select=Id`,
80
- headers: {
81
- 'accept': 'application/json;odata=nometadata'
82
- },
83
- responseType: 'json'
84
- };
85
- const response = await request.get(requestOptions);
86
- return response.Id;
87
- }
88
- async getValidUsers(args, logger) {
89
- if (this.verbose) {
90
- await logger.logToStderr('Checking if the specified users and groups exist');
75
+ async getLoginNames(logger, options) {
76
+ const loginNames = [];
77
+ if (options.userNames || options.emails) {
78
+ loginNames.push(...formatting.splitAndTrim(options.userNames || options.emails).map(u => `i:0#.f|membership|${u}`));
91
79
  }
92
- const validUserNames = [];
93
- const identifiers = args.options.userNames ?? args.options.emails ?? args.options.entraGroupIds ?? args.options.entraGroupNames ?? args.options.userIds.toString();
94
- await Promise.all(identifiers.split(',').map(async (identifier) => {
95
- const trimmedIdentifier = identifier.trim();
96
- try {
97
- if (args.options.userIds) {
98
- if (this.verbose) {
99
- await logger.logToStderr(`Getting AAD ID of user with ID ${trimmedIdentifier}`);
100
- }
101
- const spoUserAzureId = await spo.getUserAzureIdBySpoId(args.options.webUrl, trimmedIdentifier);
102
- validUserNames.push(spoUserAzureId);
103
- }
104
- else if (args.options.userNames) {
105
- validUserNames.push(trimmedIdentifier);
106
- }
107
- else if (args.options.entraGroupIds) {
108
- validUserNames.push(trimmedIdentifier);
109
- }
110
- else if (args.options.entraGroupNames) {
111
- if (this.verbose) {
112
- await logger.logToStderr(`Getting ID of Microsoft Entra group ${trimmedIdentifier}`);
113
- }
114
- const groupId = await entraGroup.getGroupIdByDisplayName(trimmedIdentifier);
115
- validUserNames.push(groupId);
80
+ else if (options.entraGroupIds || options.entraGroupNames) {
81
+ if (this.verbose) {
82
+ await logger.logToStderr(`Resolving ${(options.entraGroupIds || options.entraGroupNames).length} group(s)...`);
83
+ }
84
+ const groups = [];
85
+ if (options.entraGroupIds) {
86
+ const groupIds = formatting.splitAndTrim(options.entraGroupIds);
87
+ for (const groupId of groupIds) {
88
+ const group = await entraGroup.getGroupById(groupId);
89
+ groups.push(group);
116
90
  }
117
- else {
118
- if (this.verbose) {
119
- await logger.logToStderr(`Getting Microsoft Entra ID for user ${trimmedIdentifier}`);
120
- }
121
- const upn = await entraUser.getUserIdByEmail(trimmedIdentifier);
122
- validUserNames.push(upn);
91
+ }
92
+ else {
93
+ const groupNames = formatting.splitAndTrim(options.entraGroupNames);
94
+ for (const groupName of groupNames) {
95
+ const group = await entraGroup.getGroupByDisplayName(groupName);
96
+ groups.push(group);
123
97
  }
124
98
  }
125
- catch (err) {
126
- throw `Resource '${trimmedIdentifier}' does not exist.`;
99
+ // Check if group is M365 group or security group
100
+ loginNames.push(...groups.map(g => g.mailEnabled ? `c:0o.c|federateddirectoryclaimprovider|${g.id}` : `c:0t.c|tenant|${g.id}`));
101
+ }
102
+ else if (options.userIds) {
103
+ const userIds = formatting.splitAndTrim(options.userIds);
104
+ if (this.verbose) {
105
+ await logger.logToStderr(`Resolving ${userIds.length} user(s)...`);
127
106
  }
128
- }));
129
- return validUserNames;
107
+ for (const userId of userIds) {
108
+ const loginName = await this.getUserLoginNameById(options.webUrl, parseInt(userId));
109
+ loginNames.push(loginName);
110
+ }
111
+ }
112
+ return loginNames;
130
113
  }
131
- getFormattedUserList(activeUserList) {
132
- const generatedPeoplePicker = JSON.stringify(activeUserList.map(singleUsername => {
133
- return { Key: singleUsername.trim() };
134
- }));
135
- return generatedPeoplePicker;
114
+ async getUserLoginNameById(webUrl, userId) {
115
+ const requestOptions = {
116
+ url: `${webUrl}/_api/web/SiteUsers/GetById(${userId})?$select=LoginName`,
117
+ headers: {
118
+ accept: 'application/json;odata=nometadata'
119
+ },
120
+ responseType: 'json'
121
+ };
122
+ const user = await request.get(requestOptions);
123
+ return user.LoginName;
136
124
  }
137
125
  }
138
126
  _SpoGroupMemberAddCommand_instances = new WeakSet(), _SpoGroupMemberAddCommand_initTelemetry = function _SpoGroupMemberAddCommand_initTelemetry() {
@@ -177,29 +165,45 @@ _SpoGroupMemberAddCommand_instances = new WeakSet(), _SpoGroupMemberAddCommand_i
177
165
  if (isValidSharePointUrl !== true) {
178
166
  return isValidSharePointUrl;
179
167
  }
180
- if (args.options.groupId && isNaN(args.options.groupId)) {
181
- return `Specified groupId ${args.options.groupId} is not a number`;
168
+ if (args.options.groupId && !validation.isValidPositiveInteger(args.options.groupId)) {
169
+ return `Specified groupId ${args.options.groupId} is not a positive number.`;
182
170
  }
183
- const userIdReg = new RegExp(/^[0-9,]*$/);
184
- if (args.options.userIds && !userIdReg.test(args.options.userIds)) {
185
- return `${args.options.userIds} is not a number or a comma separated value`;
171
+ if (args.options.userIds) {
172
+ const isValidArray = validation.isValidPositiveIntegerArray(args.options.userIds);
173
+ if (isValidArray !== true) {
174
+ return `Option 'userIds' contains one or more invalid numbers: ${isValidArray}.`;
175
+ }
186
176
  }
187
- if (args.options.userNames && args.options.userNames.split(',').some(e => !validation.isValidUserPrincipalName(e))) {
188
- return `${args.options.userNames} contains one or more invalid usernames`;
177
+ if (args.options.userNames) {
178
+ const isValidArray = validation.isValidUserPrincipalNameArray(args.options.userNames);
179
+ if (isValidArray !== true) {
180
+ return `Option 'userNames' contains one or more invalid UPNs: ${isValidArray}.`;
181
+ }
189
182
  }
190
- if (args.options.emails && args.options.emails.split(',').some(e => !validation.isValidUserPrincipalName(e))) {
191
- return `${args.options.emails} contains one or more invalid email addresses`;
183
+ if (args.options.emails) {
184
+ const isValidArray = validation.isValidUserPrincipalNameArray(args.options.emails);
185
+ if (isValidArray !== true) {
186
+ return `Option 'emails' contains one or more invalid UPNs: ${isValidArray}.`;
187
+ }
192
188
  }
193
- if (args.options.entraGroupIds && args.options.entraGroupIds.split(',').some(e => !validation.isValidGuid(e))) {
194
- return `${args.options.entraGroupIds} contains one or more invalid GUIDs`;
189
+ if (args.options.entraGroupIds) {
190
+ const isValidArray = validation.isValidGuidArray(args.options.entraGroupIds);
191
+ if (isValidArray !== true) {
192
+ return `Option 'entraGroupIds' contains one or more invalid GUIDs: ${isValidArray}.`;
193
+ }
195
194
  }
196
- if (args.options.aadGroupIds && args.options.aadGroupIds.split(',').some(e => !validation.isValidGuid(e))) {
197
- return `${args.options.aadGroupIds} contains one or more invalid GUIDs`;
195
+ if (args.options.aadGroupIds) {
196
+ const isValidArray = validation.isValidGuidArray(args.options.aadGroupIds);
197
+ if (isValidArray !== true) {
198
+ return `Option 'aadGroupIds' contains one or more invalid GUIDs: ${isValidArray}.`;
199
+ }
198
200
  }
199
201
  return true;
200
202
  });
201
203
  }, _SpoGroupMemberAddCommand_initOptionSets = function _SpoGroupMemberAddCommand_initOptionSets() {
202
204
  this.optionSets.push({ options: ['groupId', 'groupName'] }, { options: ['userNames', 'emails', 'userIds', 'entraGroupIds', 'aadGroupIds', 'entraGroupNames', 'aadGroupNames'] });
205
+ }, _SpoGroupMemberAddCommand_initTypes = function _SpoGroupMemberAddCommand_initTypes() {
206
+ this.types.string.push('webUrl', 'groupName', 'userNames', 'emails', 'userIds', 'entraGroupIds', 'aadGroupIds', 'entraGroupNames', 'aadGroupNames');
203
207
  };
204
208
  export default new SpoGroupMemberAddCommand();
205
209
  //# sourceMappingURL=group-member-add.js.map
@@ -1,3 +1,4 @@
1
+ import { formatting } from "./formatting.js";
1
2
  export const validation = {
2
3
  isValidGuidArray(guidsString) {
3
4
  const guids = guidsString.split(',').map(guid => guid.trim());
@@ -33,6 +34,24 @@ export const validation = {
33
34
  // verify if the upn is a valid upn. @meusername will be replaced in a later stage with the actual username of the logged in user
34
35
  return upnRegEx.test(upn) || upn.toLowerCase().trim() === '@meusername';
35
36
  },
37
+ /**
38
+ * Validates if the provided number is a valid positive integer (1 or higher).
39
+ * @param integer Integer value.
40
+ * @returns True if integer, false otherwise.
41
+ */
42
+ isValidPositiveInteger(integer) {
43
+ return !isNaN(Number(integer)) && Number.isInteger(+integer) && +integer > 0;
44
+ },
45
+ /**
46
+ * Validates an array of integers. The integers must be positive (1 or higher).
47
+ * @param integerString Comma-separated string of integers.
48
+ * @returns True if the integers are valid, an error message with the invalid integers otherwise.
49
+ */
50
+ isValidPositiveIntegerArray(integerString) {
51
+ const integers = formatting.splitAndTrim(integerString);
52
+ const invalidIntegers = integers.filter(integer => !this.isValidPositiveInteger(integer));
53
+ return invalidIntegers.length > 0 ? invalidIntegers.join(', ') : true;
54
+ },
36
55
  isDateInRange(date, monthOffset) {
37
56
  const d = new Date(date);
38
57
  const cutoffDate = new Date();