@pnp/cli-microsoft365 7.7.0-beta.d874bca → 7.8.0-beta.3152fc7

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.
package/dist/cli/cli.js CHANGED
@@ -17,6 +17,7 @@ import { md } from '../utils/md.js';
17
17
  import { validation } from '../utils/validation.js';
18
18
  import { prompt } from '../utils/prompt.js';
19
19
  import { timings } from './timings.js';
20
+ import chalk from 'chalk';
20
21
  const require = createRequire(import.meta.url);
21
22
  const __dirname = fileURLToPath(new URL('.', import.meta.url));
22
23
  let _config;
@@ -96,7 +97,7 @@ async function execute(rawArgs) {
96
97
  parsedArgs.h ||
97
98
  parsedArgs.help) {
98
99
  if (parsedArgs.output !== 'none') {
99
- printHelp(await getHelpMode(parsedArgs));
100
+ await printHelp(await getHelpMode(parsedArgs));
100
101
  }
101
102
  return;
102
103
  }
@@ -546,13 +547,16 @@ function getFirstNonUndefinedArrayItem(arr) {
546
547
  }
547
548
  return undefined;
548
549
  }
549
- function printHelp(helpMode, exitCode = 0) {
550
+ async function printHelp(helpMode, exitCode = 0) {
550
551
  const properties = {};
551
552
  if (cli.commandToExecute) {
552
553
  properties.command = cli.commandToExecute.name;
553
554
  printCommandHelp(helpMode);
554
555
  }
555
556
  else {
557
+ if (cli.currentCommandName && !cli.commands.some(command => command.name.startsWith(cli.currentCommandName))) {
558
+ await cli.error(chalk.red(`Command '${cli.currentCommandName}' was not found. Below you can find the commands and command groups you can use. For detailed information on a command group, use 'm365 [command group] --help'.`));
559
+ }
556
560
  cli.log();
557
561
  cli.log(`CLI for Microsoft 365 v${app.packageJson().version}`);
558
562
  cli.log(`${app.packageJson().description} `);
@@ -732,7 +736,7 @@ async function closeWithError(error, args, showHelpIfEnabled = false) {
732
736
  await cli.error(errorMessage);
733
737
  if (showHelpIfEnabled &&
734
738
  await cli.getSettingWithDefaultValue(settingsNames.showHelpOnFailure, showHelpIfEnabled)) {
735
- printHelp(await getHelpMode(args.options), exitCode);
739
+ await printHelp(await getHelpMode(args.options), exitCode);
736
740
  }
737
741
  else {
738
742
  process.exit(exitCode);
@@ -875,7 +879,8 @@ export const cli = {
875
879
  const spinnerOptions = {
876
880
  text: 'Running command...',
877
881
  /* c8 ignore next 1 */
878
- stream: cli.getSettingWithDefaultValue('errorOutput', 'stderr') === 'stderr' ? process.stderr : process.stdout
882
+ stream: cli.getSettingWithDefaultValue('errorOutput', 'stderr') === 'stderr' ? process.stderr : process.stdout,
883
+ discardStdin: false
879
884
  };
880
885
  cli.spinner = ora(spinnerOptions);
881
886
  //# sourceMappingURL=cli.js.map
@@ -73,13 +73,7 @@ class SetupCommand extends AnonymousCommand {
73
73
  };
74
74
  preferences.experience = await cli.promptForSelection(experienceConfig);
75
75
  const summaryConfig = {
76
- // invoked by inquirer
77
- /* c8 ignore next 6 */
78
- message: async () => {
79
- settings = this.getSettings(preferences);
80
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
81
- return this.getSummaryMessage(settings);
82
- }
76
+ message: this.getSummaryMessage(this.getSettings(preferences))
83
77
  };
84
78
  preferences.summary = await cli.promptForConfirmation(summaryConfig);
85
79
  if (preferences.summary) {
@@ -31,17 +31,22 @@ class EntraUserListCommand extends GraphCommand {
31
31
  async commandAction(logger, args) {
32
32
  await this.showDeprecationWarning(logger, aadCommands.USER_LIST, commands.USER_LIST);
33
33
  try {
34
+ const selectProperties = args.options.properties ? args.options.properties : 'id,displayName,mail,userPrincipalName';
35
+ const allSelectProperties = selectProperties.split(',');
36
+ const propertiesWithSlash = allSelectProperties.filter(item => item.includes('/'));
37
+ const fieldExpand = propertiesWithSlash
38
+ .map(p => `${p.split('/')[0]}($select=${p.split('/')[1]})`)
39
+ .join(',');
40
+ const expandParam = fieldExpand.length > 0 ? `&$expand=${fieldExpand}` : '';
41
+ const selectParam = allSelectProperties.filter(item => !item.includes('/'));
34
42
  let filter = '';
35
- const properties = args.options.properties ?
36
- args.options.properties.split(',').map(p => p.trim()) :
37
- ['userPrincipalName', 'displayName'];
38
43
  try {
39
44
  filter = this.getFilter(args.options);
40
45
  }
41
46
  catch (ex) {
42
47
  throw ex;
43
48
  }
44
- const url = `${this.resource}/v1.0/users?$select=${properties.join(',')}${(filter.length > 0 ? '&' + filter : '')}&$top=100`;
49
+ const url = `${this.resource}/v1.0/users?$select=${selectParam}${expandParam}${(filter.length > 0 ? '&' + filter : '')}&$top=100`;
45
50
  const users = await odata.getAllItems(url);
46
51
  await logger.log(users);
47
52
  }
@@ -52,6 +57,7 @@ class EntraUserListCommand extends GraphCommand {
52
57
  getFilter(options) {
53
58
  const filters = {};
54
59
  const excludeOptions = [
60
+ 'type',
55
61
  'properties',
56
62
  'p',
57
63
  'd',
@@ -72,7 +78,10 @@ class EntraUserListCommand extends GraphCommand {
72
78
  });
73
79
  let filter = Object.keys(filters).map(key => `startsWith(${key}, '${filters[key]}')`).join(' and ');
74
80
  if (filter.length > 0) {
75
- filter = '$filter=' + filter;
81
+ filter = `$filter=${filter}`;
82
+ }
83
+ if (options.type) {
84
+ filter += filter.length > 0 ? ` and userType eq '${options.type}'` : `$filter=userType eq '${options.type}'`;
76
85
  }
77
86
  return filter;
78
87
  }
@@ -80,11 +89,15 @@ class EntraUserListCommand extends GraphCommand {
80
89
  _EntraUserListCommand_instances = new WeakSet(), _EntraUserListCommand_initTelemetry = function _EntraUserListCommand_initTelemetry() {
81
90
  this.telemetry.push((args) => {
82
91
  Object.assign(this.telemetryProperties, {
83
- properties: args.options.properties
92
+ type: typeof args.options.type !== 'undefined',
93
+ properties: typeof args.options.properties !== 'undefined'
84
94
  });
85
95
  });
86
96
  }, _EntraUserListCommand_initOptions = function _EntraUserListCommand_initOptions() {
87
- this.options.unshift({ option: '-p, --properties [properties]' });
97
+ this.options.unshift({
98
+ option: "--type [type]",
99
+ autocomplete: ["Member", "Guest"]
100
+ }, { option: '-p, --properties [properties]' });
88
101
  };
89
102
  export default new EntraUserListCommand();
90
103
  //# sourceMappingURL=user-list.js.map
@@ -0,0 +1,115 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _SpeContainertypeAddCommand_instances, _SpeContainertypeAddCommand_initTelemetry, _SpeContainertypeAddCommand_initOptions, _SpeContainertypeAddCommand_initValidators;
7
+ import config from '../../../../config.js';
8
+ import request from '../../../../request.js';
9
+ import { spo } from '../../../../utils/spo.js';
10
+ import { validation } from '../../../../utils/validation.js';
11
+ import SpoCommand from '../../../base/SpoCommand.js';
12
+ import commands from '../../commands.js';
13
+ class SpeContainertypeAddCommand extends SpoCommand {
14
+ get name() {
15
+ return commands.CONTAINERTYPE_ADD;
16
+ }
17
+ get description() {
18
+ return 'Creates a new Container Type for your app';
19
+ }
20
+ constructor() {
21
+ super();
22
+ _SpeContainertypeAddCommand_instances.add(this);
23
+ __classPrivateFieldGet(this, _SpeContainertypeAddCommand_instances, "m", _SpeContainertypeAddCommand_initTelemetry).call(this);
24
+ __classPrivateFieldGet(this, _SpeContainertypeAddCommand_instances, "m", _SpeContainertypeAddCommand_initOptions).call(this);
25
+ __classPrivateFieldGet(this, _SpeContainertypeAddCommand_instances, "m", _SpeContainertypeAddCommand_initValidators).call(this);
26
+ }
27
+ async commandAction(logger, args) {
28
+ try {
29
+ if (this.verbose) {
30
+ await logger.logToStderr(`Creating a new Container Type for your app with name ${args.options.name}`);
31
+ }
32
+ const adminUrl = await spo.getSpoAdminUrl(logger, this.debug);
33
+ const requestBody = this.getRequestBody(args.options);
34
+ const formDigestInfo = await spo.ensureFormDigest(adminUrl, logger, undefined, this.debug);
35
+ const requestOptions = {
36
+ url: `${adminUrl}/_vti_bin/client.svc/ProcessQuery`,
37
+ headers: {
38
+ 'X-RequestDigest': formDigestInfo.FormDigestValue
39
+ },
40
+ data: requestBody
41
+ };
42
+ const res = await request.post(requestOptions);
43
+ const json = JSON.parse(res);
44
+ const response = json[0];
45
+ if (response.ErrorInfo) {
46
+ throw response.ErrorInfo.ErrorMessage;
47
+ }
48
+ const result = json.pop();
49
+ delete result._ObjectType_;
50
+ result.SPContainerTypeBillingClassification = args.options.trial ? 'Trial' : 'Standard';
51
+ result.AzureSubscriptionId = this.replaceString(result.AzureSubscriptionId);
52
+ result.OwningAppId = this.replaceString(result.OwningAppId);
53
+ result.OwningTenantId = this.replaceString(result.OwningTenantId);
54
+ result.ContainerTypeId = this.replaceString(result.ContainerTypeId);
55
+ await logger.log(result);
56
+ }
57
+ catch (err) {
58
+ this.handleRejectedPromise(err);
59
+ }
60
+ }
61
+ replaceString(s) {
62
+ return s.replace('/Guid(', '').replace(')/', '');
63
+ }
64
+ getRequestBody(options) {
65
+ if (options.trial) {
66
+ return `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="4" ObjectPathId="3" /><Method Name="NewSPOContainerType" Id="5" ObjectPathId="3"><Parameters><Parameter TypeId="{5466648e-c306-441b-9df4-c09deef25cb1}"><Property Name="AzureSubscriptionId" Type="Guid">{00000000-0000-0000-0000-000000000000}</Property><Property Name="ContainerTypeId" Type="Guid">{00000000-0000-0000-0000-000000000000}</Property><Property Name="CreationDate" Type="Null" /><Property Name="DisplayName" Type="String">${options.name}</Property><Property Name="ExpiryDate" Type="Null" /><Property Name="IsBillingProfileRequired" Type="Boolean">false</Property><Property Name="OwningAppId" Type="Guid">{${options.applicationId}}</Property><Property Name="OwningTenantId" Type="Guid">{00000000-0000-0000-0000-000000000000}</Property><Property Name="Region" Type="Null" /><Property Name="ResourceGroup" Type="Null" /><Property Name="SPContainerTypeBillingClassification" Type="Enum">1</Property></Parameter></Parameters></Method></Actions><ObjectPaths><Constructor Id="3" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>`;
67
+ }
68
+ return `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><Method Name="NewSPOContainerType" Id="4" ObjectPathId="1"><Parameters><Parameter TypeId="{5466648e-c306-441b-9df4-c09deef25cb1}"><Property Name="AzureSubscriptionId" Type="Guid">{${options.azureSubscriptionId}}</Property><Property Name="ContainerTypeId" Type="Guid">{00000000-0000-0000-0000-000000000000}</Property><Property Name="CreationDate" Type="Null" /><Property Name="DisplayName" Type="String">${options.name}</Property><Property Name="ExpiryDate" Type="Null" /><Property Name="IsBillingProfileRequired" Type="Boolean">false</Property><Property Name="OwningAppId" Type="Guid">{${options.applicationId}}</Property><Property Name="OwningTenantId" Type="Guid">{00000000-0000-0000-0000-000000000000}</Property><Property Name="Region" Type="String">${options.region}</Property><Property Name="ResourceGroup" Type="String">${options.resourceGroup}</Property><Property Name="SPContainerTypeBillingClassification" Type="Enum">0</Property></Parameter></Parameters></Method></Actions><ObjectPaths><Constructor Id="1" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /></ObjectPaths></Request>`;
69
+ }
70
+ }
71
+ _SpeContainertypeAddCommand_instances = new WeakSet(), _SpeContainertypeAddCommand_initTelemetry = function _SpeContainertypeAddCommand_initTelemetry() {
72
+ this.telemetry.push((args) => {
73
+ Object.assign(this.telemetryProperties, {
74
+ trial: !!args.options.trial,
75
+ azureSubscriptionId: typeof args.options.azureSubscriptionId !== 'undefined',
76
+ resourceGroup: typeof args.options.resourceGroup !== 'undefined',
77
+ region: typeof args.options.region !== 'undefined'
78
+ });
79
+ });
80
+ }, _SpeContainertypeAddCommand_initOptions = function _SpeContainertypeAddCommand_initOptions() {
81
+ this.options.unshift({
82
+ option: '-n, --name <name>'
83
+ }, {
84
+ option: '--applicationId <applicationId>'
85
+ }, {
86
+ option: '--trial'
87
+ }, {
88
+ option: '--azureSubscriptionId [azureSubscriptionId]'
89
+ }, {
90
+ option: '--resourceGroup [resourceGroup]'
91
+ }, {
92
+ option: '--region [region]'
93
+ });
94
+ }, _SpeContainertypeAddCommand_initValidators = function _SpeContainertypeAddCommand_initValidators() {
95
+ this.validators.push(async (args) => {
96
+ if (!validation.isValidGuid(args.options.applicationId)) {
97
+ return `${args.options.applicationId} is not a valid GUID for option applicationId.`;
98
+ }
99
+ if (args.options.trial === undefined && !args.options.azureSubscriptionId) {
100
+ return 'You must specify the azureSubscriptionId when creating a non-trial environment.';
101
+ }
102
+ if (args.options.trial === undefined && !args.options.resourceGroup) {
103
+ return 'You must specify the resourceGroup when creating a non-trial environment.';
104
+ }
105
+ if (args.options.trial === undefined && !args.options.region) {
106
+ return 'You must specify the region when creating a non-trial environment.';
107
+ }
108
+ if (args.options.azureSubscriptionId && !validation.isValidGuid(args.options.azureSubscriptionId)) {
109
+ return `${args.options.azureSubscriptionId} is not a valid GUID for option azureSubscriptionId.`;
110
+ }
111
+ return true;
112
+ });
113
+ };
114
+ export default new SpeContainertypeAddCommand();
115
+ //# sourceMappingURL=containertype-add.js.map
@@ -0,0 +1,5 @@
1
+ const prefix = 'spe';
2
+ export default {
3
+ CONTAINERTYPE_ADD: `${prefix} containertype add`
4
+ };
5
+ //# sourceMappingURL=commands.js.map